Skip to content

fix:fix materialHeader The header icon is not centered #37

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,45 @@ namespace rnoh {

ArkUI_NumberValue heightArray[] = {{.f32 = 45}};
ArkUI_AttributeItem heightValue[] = {heightArray, 1};
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_HEIGHT, heightValue);
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_HEIGHT, heightValue);
ArkUI_NumberValue widthArray[] = {{.f32 = 45}};
ArkUI_AttributeItem widthValue[] = {widthArray, 1};
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_WIDTH, widthValue);
ArkUI_NumberValue borderStyArray[] = {1};
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_WIDTH, widthValue);

ArkUI_NumberValue borderStyArray[] = {0.2};
ArkUI_AttributeItem borderStyValue[] = {borderStyArray, 1};
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_BORDER_WIDTH, borderStyValue);
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_BORDER_WIDTH, borderStyValue);

ArkUI_NumberValue radiusArray[] = {{.f32 = 45}};
ArkUI_AttributeItem radiusValue[] = {radiusArray, 1};
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_BORDER_RADIUS, radiusValue);

NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_BORDER_RADIUS, radiusValue);
imageStack.setBackgroundColor(0xFFfafafa);
ArkUI_NumberValue borderColorArray[] = {
{.u32 = 0xFFaaaaaa}, {.u32 = 0xFFaaaaaa}, {.u32 = 0xFFaaaaaa}, {.u32 = 0xFFaaaaaa}, {.u32 = 0xFFaaaaaa}};
ArkUI_AttributeItem borderColorValue[] = {borderColorArray, 4};
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_BORDER_COLOR, borderColorValue);
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_BORDER_COLOR,
borderColorValue);

uint32_t shadowColorValue = 0xffaaaaaa;
uint32_t alpha = static_cast<uint32_t>((float)(shadowColorValue >> 24 & (0xff))*1.0);
uint32_t alpha = static_cast<uint32_t>((float)(shadowColorValue >> 24 & (0xff)) * 1.0);
shadowColorValue = (alpha << 24) + (shadowColorValue & 0xffffff);
ArkUI_NumberValue shadowValue[] = {
{.f32 = 2},
{.i32 = 0},
{.f32 = 1},
{.f32 = 1},
{.i32 = 0},
{.u32 = shadowColorValue},
{.u32 = 0}
};
ArkUI_AttributeItem shadowItem = {.value = shadowValue,.size = sizeof(shadowValue)/sizeof(ArkUI_NumberValue)};
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_CUSTOM_SHADOW, &shadowItem);

ArkUI_NumberValue shadowValue[] = {
{.f32 = 2}, {.i32 = 0}, {.f32 = 1}, {.f32 = 1}, {.i32 = 0}, {.u32 = shadowColorValue}, {.u32 = 0}};
ArkUI_AttributeItem shadowItem = {.value = shadowValue,
.size = sizeof(shadowValue) / sizeof(ArkUI_NumberValue)};
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_CUSTOM_SHADOW, &shadowItem);

ArkUI_NumberValue z_indexArray[] = {{.f32 = 1000}};
ArkUI_AttributeItem z_indexValue[] = {z_indexArray, 1};
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_Z_INDEX, z_indexValue);
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_Z_INDEX, z_indexValue);

NativeNodeApi::getInstance()->insertChildAt(imageStack, progressNode.getArkUINodeHandle(), 0);
NativeNodeApi::getInstance()->insertChildAt(arkUI_Node->getArkUINodeHandle(), imageStack, index);
NativeNodeApi::getInstance()->insertChildAt(imageStack.getArkUINodeHandle(), progressNode.getArkUINodeHandle(),
0);
NativeNodeApi::getInstance()->insertChildAt(arkUI_Node->getArkUINodeHandle(), imageStack.getArkUINodeHandle(),
index);
ArkUI_NumberValue positionArray[] = {{.f32 = static_cast<float>((screenWidth - 46) / 2.0)}, {.f32 = -46}};
ArkUI_AttributeItem positionValue[] = {positionArray, 2};
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_POSITION, positionValue);
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_POSITION, positionValue);
}

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

Expand All @@ -83,15 +80,30 @@ namespace rnoh {
float value = 1.0 - static_cast<float>(v);
ArkUI_NumberValue scaleArray[] = {{.f32 = value}, {.f32 = value}};
ArkUI_AttributeItem scaleValue[] = {scaleArray, 2};
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_SCALE, scaleValue);
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_SCALE, scaleValue);
if (std::abs(value - 0.01) < 1e-6) {
ArkUI_NumberValue scaleArray[] = {{.f32 = 1.0}, {.f32 = 1.0}};
ArkUI_AttributeItem scaleValue[] = {scaleArray, 2};
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_SCALE, scaleValue);
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_SCALE, scaleValue);
}
});
task->execute();
}

void RNCMaterialHeaderComponentInstance::finalizeUpdates() {
auto rnInstancePtr = this->m_deps->rnInstance.lock();
if (rnInstancePtr != nullptr) {
auto turboModule = rnInstancePtr->getTurboModule("RNCSmartRefreshContext");
auto arkTsTurboModule = std::dynamic_pointer_cast<rnoh::ArkTSTurboModule>(turboModule);
folly::dynamic result = arkTsTurboModule->callSync("cvp2px", {getLayoutMetrics().frame.size.width});
folly::dynamic result1 = arkTsTurboModule->callSync("cvp2px", {60});
m_stackNode.setLayoutRect({0, 0}, {result["values"].asDouble(), result1["values"].asDouble()}, 1.0);
}
m_stackNode.setAlignment(ARKUI_ALIGNMENT_BOTTOM);
}

facebook::react::SharedColor RNCMaterialHeaderComponentInstance::GetPrimaryColor() { return -1; }

void RNCMaterialHeaderComponentInstance::onChildInserted(ComponentInstance::Shared const &childComponentInstance,
std::size_t index) {
CppComponentInstance::onChildInserted(childComponentInstance, index);
Expand All @@ -115,7 +127,7 @@ namespace rnoh {
float y = -46.0;
ArkUI_NumberValue positionArray[] = {{.f32 = x}, {.f32 = y}};
ArkUI_AttributeItem positionValue[] = {positionArray, 2};
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_POSITION, positionValue);
NativeNodeApi::getInstance()->setAttribute(imageStack.getArkUINodeHandle(), NODE_POSITION, positionValue);
}
case IS_PULL_DOWN_1:
case IS_PULL_DOWN_2: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace rnoh {

private:
SmartStackNode m_stackNode;
ArkUI_NodeHandle imageStack{m_stackNode.getArkUINodeHandle()};
SmartStackNode imageStack;
SmartProgressNode progressNode;
float mWindowWidth{0.0};
bool isRefreshed{false};
Expand All @@ -32,5 +32,7 @@ namespace rnoh {
void addHeader(int32_t screenWidth, int32_t index, ArkUINode *arkUI_Node) override;
void onHeaderMove(float dur) override;
void setScaleAnimate(int32_t dur);
facebook::react::SharedColor GetPrimaryColor() override;
void finalizeUpdates() override;
};
} // namespace rnoh
17 changes: 9 additions & 8 deletions harmony/smart_refresh_layout/src/main/cpp/SmartProgressNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ void SmartProgressNode::setLoadingProgressNodeColor(facebook::react::SharedColor
}

void SmartProgressNode::setLoadingProgressNodeAnimating(const bool &enable) {
uint32_t typeValue = 1;
if (!enable) {
typeValue = 0;
}
ArkUI_NumberValue preparedTypeValue[] = {{.u32 = typeValue}};
ArkUI_AttributeItem typeItem = {preparedTypeValue, sizeof(preparedTypeValue) / sizeof(ArkUI_NumberValue)};
maybeThrow(
NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_LOADING_PROGRESS_ENABLE_LOADING, &typeItem));
uint32_t enableLoadingProgressNodeAnimation = enable ? 1 : 0;
std::array<ArkUI_NumberValue, 1> enableLoadingProgressNodeAnimationValue = {
{{.u32 = enableLoadingProgressNodeAnimation}}};

ArkUI_AttributeItem enableLoadingProgressNodeAnimationItem = {enableLoadingProgressNodeAnimationValue.data(),
enableLoadingProgressNodeAnimationValue.size()};

maybeThrow(NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_LOADING_PROGRESS_ENABLE_LOADING,
&enableLoadingProgressNodeAnimationItem));
}

} // namespace rnoh