Skip to content

Commit 2c74adb

Browse files
authored
fix:fix materialHeader The header icon is not centered (#37)
Signed-off-by: tyBrave <tianyong21@h-partners.com>
1 parent ab73258 commit 2c74adb

File tree

3 files changed

+53
-38
lines changed

3 files changed

+53
-38
lines changed

harmony/smart_refresh_layout/src/main/cpp/RNCMaterialHeaderComponentInstance.cpp

+41-29
Original file line numberDiff line numberDiff line change
@@ -24,48 +24,45 @@ namespace rnoh {
2424

2525
ArkUI_NumberValue heightArray[] = {{.f32 = 45}};
2626
ArkUI_AttributeItem heightValue[] = {heightArray, 1};
27-
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_HEIGHT, heightValue);
27+
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_HEIGHT, heightValue);
2828
ArkUI_NumberValue widthArray[] = {{.f32 = 45}};
2929
ArkUI_AttributeItem widthValue[] = {widthArray, 1};
30-
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_WIDTH, widthValue);
31-
32-
ArkUI_NumberValue borderStyArray[] = {1};
30+
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_WIDTH, widthValue);
31+
32+
ArkUI_NumberValue borderStyArray[] = {0.2};
3333
ArkUI_AttributeItem borderStyValue[] = {borderStyArray, 1};
34-
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_BORDER_WIDTH, borderStyValue);
34+
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_BORDER_WIDTH, borderStyValue);
3535

3636
ArkUI_NumberValue radiusArray[] = {{.f32 = 45}};
3737
ArkUI_AttributeItem radiusValue[] = {radiusArray, 1};
38-
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_BORDER_RADIUS, radiusValue);
39-
38+
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_BORDER_RADIUS, radiusValue);
39+
imageStack.setBackgroundColor(0xFFfafafa);
4040
ArkUI_NumberValue borderColorArray[] = {
4141
{.u32 = 0xFFaaaaaa}, {.u32 = 0xFFaaaaaa}, {.u32 = 0xFFaaaaaa}, {.u32 = 0xFFaaaaaa}, {.u32 = 0xFFaaaaaa}};
4242
ArkUI_AttributeItem borderColorValue[] = {borderColorArray, 4};
43-
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_BORDER_COLOR, borderColorValue);
43+
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_BORDER_COLOR,
44+
borderColorValue);
4445

4546
uint32_t shadowColorValue = 0xffaaaaaa;
46-
uint32_t alpha = static_cast<uint32_t>((float)(shadowColorValue >> 24 & (0xff))*1.0);
47+
uint32_t alpha = static_cast<uint32_t>((float)(shadowColorValue >> 24 & (0xff)) * 1.0);
4748
shadowColorValue = (alpha << 24) + (shadowColorValue & 0xffffff);
48-
ArkUI_NumberValue shadowValue[] = {
49-
{.f32 = 2},
50-
{.i32 = 0},
51-
{.f32 = 1},
52-
{.f32 = 1},
53-
{.i32 = 0},
54-
{.u32 = shadowColorValue},
55-
{.u32 = 0}
56-
};
57-
ArkUI_AttributeItem shadowItem = {.value = shadowValue,.size = sizeof(shadowValue)/sizeof(ArkUI_NumberValue)};
58-
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_CUSTOM_SHADOW, &shadowItem);
59-
49+
ArkUI_NumberValue shadowValue[] = {
50+
{.f32 = 2}, {.i32 = 0}, {.f32 = 1}, {.f32 = 1}, {.i32 = 0}, {.u32 = shadowColorValue}, {.u32 = 0}};
51+
ArkUI_AttributeItem shadowItem = {.value = shadowValue,
52+
.size = sizeof(shadowValue) / sizeof(ArkUI_NumberValue)};
53+
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_CUSTOM_SHADOW, &shadowItem);
54+
6055
ArkUI_NumberValue z_indexArray[] = {{.f32 = 1000}};
6156
ArkUI_AttributeItem z_indexValue[] = {z_indexArray, 1};
62-
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_Z_INDEX, z_indexValue);
57+
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_Z_INDEX, z_indexValue);
6358

64-
NativeNodeApi::getInstance()->insertChildAt(imageStack, progressNode.getArkUINodeHandle(), 0);
65-
NativeNodeApi::getInstance()->insertChildAt(arkUI_Node->getArkUINodeHandle(), imageStack, index);
59+
NativeNodeApi::getInstance()->insertChildAt(imageStack.getArkUINodeHandle(), progressNode.getArkUINodeHandle(),
60+
0);
61+
NativeNodeApi::getInstance()->insertChildAt(arkUI_Node->getArkUINodeHandle(), imageStack.getArkUINodeHandle(),
62+
index);
6663
ArkUI_NumberValue positionArray[] = {{.f32 = static_cast<float>((screenWidth - 46) / 2.0)}, {.f32 = -46}};
6764
ArkUI_AttributeItem positionValue[] = {positionArray, 2};
68-
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_POSITION, positionValue);
65+
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_POSITION, positionValue);
6966
}
7067

7168
void RNCMaterialHeaderComponentInstance::onHeaderMove(float dur) {
@@ -74,7 +71,7 @@ namespace rnoh {
7471
}
7572
ArkUI_NumberValue positionArray[] = {{.f32 = static_cast<float>((mWindowWidth - 46) / 2.0)}, {.f32 = dur - 46}};
7673
ArkUI_AttributeItem positionValue[] = {positionArray, 2};
77-
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_POSITION, positionValue);
74+
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_POSITION, positionValue);
7875
}
7976
void RNCMaterialHeaderComponentInstance::setScaleAnimate(int32_t dur) {
8077

@@ -83,15 +80,30 @@ namespace rnoh {
8380
float value = 1.0 - static_cast<float>(v);
8481
ArkUI_NumberValue scaleArray[] = {{.f32 = value}, {.f32 = value}};
8582
ArkUI_AttributeItem scaleValue[] = {scaleArray, 2};
86-
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_SCALE, scaleValue);
83+
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_SCALE, scaleValue);
8784
if (std::abs(value - 0.01) < 1e-6) {
8885
ArkUI_NumberValue scaleArray[] = {{.f32 = 1.0}, {.f32 = 1.0}};
8986
ArkUI_AttributeItem scaleValue[] = {scaleArray, 2};
90-
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_SCALE, scaleValue);
87+
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_SCALE, scaleValue);
9188
}
9289
});
9390
task->execute();
9491
}
92+
93+
void RNCMaterialHeaderComponentInstance::finalizeUpdates() {
94+
auto rnInstancePtr = this->m_deps->rnInstance.lock();
95+
if (rnInstancePtr != nullptr) {
96+
auto turboModule = rnInstancePtr->getTurboModule("RNCSmartRefreshContext");
97+
auto arkTsTurboModule = std::dynamic_pointer_cast<rnoh::ArkTSTurboModule>(turboModule);
98+
folly::dynamic result = arkTsTurboModule->callSync("cvp2px", {getLayoutMetrics().frame.size.width});
99+
folly::dynamic result1 = arkTsTurboModule->callSync("cvp2px", {60});
100+
m_stackNode.setLayoutRect({0, 0}, {result["values"].asDouble(), result1["values"].asDouble()}, 1.0);
101+
}
102+
m_stackNode.setAlignment(ARKUI_ALIGNMENT_BOTTOM);
103+
}
104+
105+
facebook::react::SharedColor RNCMaterialHeaderComponentInstance::GetPrimaryColor() { return -1; }
106+
95107
void RNCMaterialHeaderComponentInstance::onChildInserted(ComponentInstance::Shared const &childComponentInstance,
96108
std::size_t index) {
97109
CppComponentInstance::onChildInserted(childComponentInstance, index);
@@ -115,7 +127,7 @@ namespace rnoh {
115127
float y = -46.0;
116128
ArkUI_NumberValue positionArray[] = {{.f32 = x}, {.f32 = y}};
117129
ArkUI_AttributeItem positionValue[] = {positionArray, 2};
118-
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_POSITION, positionValue);
130+
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_POSITION, positionValue);
119131
}
120132
case IS_PULL_DOWN_1:
121133
case IS_PULL_DOWN_2: {

harmony/smart_refresh_layout/src/main/cpp/RNCMaterialHeaderComponentInstance.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace rnoh {
1717

1818
private:
1919
SmartStackNode m_stackNode;
20-
ArkUI_NodeHandle imageStack{m_stackNode.getArkUINodeHandle()};
20+
SmartStackNode imageStack;
2121
SmartProgressNode progressNode;
2222
float mWindowWidth{0.0};
2323
bool isRefreshed{false};
@@ -32,5 +32,7 @@ namespace rnoh {
3232
void addHeader(int32_t screenWidth, int32_t index, ArkUINode *arkUI_Node) override;
3333
void onHeaderMove(float dur) override;
3434
void setScaleAnimate(int32_t dur);
35+
facebook::react::SharedColor GetPrimaryColor() override;
36+
void finalizeUpdates() override;
3537
};
3638
} // namespace rnoh

harmony/smart_refresh_layout/src/main/cpp/SmartProgressNode.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ void SmartProgressNode::setLoadingProgressNodeColor(facebook::react::SharedColor
2020
}
2121

2222
void SmartProgressNode::setLoadingProgressNodeAnimating(const bool &enable) {
23-
uint32_t typeValue = 1;
24-
if (!enable) {
25-
typeValue = 0;
26-
}
27-
ArkUI_NumberValue preparedTypeValue[] = {{.u32 = typeValue}};
28-
ArkUI_AttributeItem typeItem = {preparedTypeValue, sizeof(preparedTypeValue) / sizeof(ArkUI_NumberValue)};
29-
maybeThrow(
30-
NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_LOADING_PROGRESS_ENABLE_LOADING, &typeItem));
23+
uint32_t enableLoadingProgressNodeAnimation = enable ? 1 : 0;
24+
std::array<ArkUI_NumberValue, 1> enableLoadingProgressNodeAnimationValue = {
25+
{{.u32 = enableLoadingProgressNodeAnimation}}};
26+
27+
ArkUI_AttributeItem enableLoadingProgressNodeAnimationItem = {enableLoadingProgressNodeAnimationValue.data(),
28+
enableLoadingProgressNodeAnimationValue.size()};
29+
30+
maybeThrow(NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_LOADING_PROGRESS_ENABLE_LOADING,
31+
&enableLoadingProgressNodeAnimationItem));
3132
}
3233

3334
} // namespace rnoh

0 commit comments

Comments
 (0)