Skip to content

Commit ab73258

Browse files
authored
feat:added the primaryColor and accentColor attribute for DefaultHeader (#35)
Signed-off-by: tyBrave <tianyong21@h-partners.com>
1 parent 915a0c7 commit ab73258

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

harmony/smart_refresh_layout/src/main/cpp/RNCDefaultHeaderComponentInstance.cpp

+17-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "RNOH/arkui/NativeNodeApi.h"
99
#include "react/renderer/imagemanager/primitives.h"
1010
#include "SmartRefreshState.h"
11+
#include "SmartUtils.h"
1112

1213
namespace rnoh {
1314

@@ -57,18 +58,26 @@ namespace rnoh {
5758

5859
void RNCDefaultHeaderComponentInstance::onPropsChanged(SharedConcreteProps const &props) {
5960
if (props != nullptr) {
60-
facebook::react::SharedColor headerColor = props->primaryColor;
61-
if (props->accentColor) {
62-
textNode.setFontColor(props->accentColor);
63-
imageNode.setTintColor(props->accentColor);
61+
primaryColor = props->primaryColor;
62+
if (props->accentColor != "") {
63+
textNode.setFontColor(SmartUtils::parseColor(props->accentColor));
64+
imageNode.setTintColor(SmartUtils::parseColor(props->accentColor));
65+
progressNode.setLoadingProgressNodeColor(SmartUtils::parseColor(props->accentColor));
6466
}
6567
}
6668
}
67-
69+
facebook::react::SharedColor RNCDefaultHeaderComponentInstance::GetPrimaryColor() {
70+
return SmartUtils::parseColor(primaryColor);
71+
}
6872
void RNCDefaultHeaderComponentInstance::finalizeUpdates() {
69-
ArkUI_NumberValue heightNumberValue[] = {60};
70-
ArkUI_AttributeItem heightItem = {heightNumberValue, 1};
71-
NativeNodeApi::getInstance()->setAttribute(m_stackNode.getArkUINodeHandle(), NODE_HEIGHT, &heightItem);
73+
auto rnInstancePtr = this->m_deps->rnInstance.lock();
74+
if (rnInstancePtr != nullptr) {
75+
auto turboModule = rnInstancePtr->getTurboModule("RNCSmartRefreshContext");
76+
auto arkTsTurboModule = std::dynamic_pointer_cast<rnoh::ArkTSTurboModule>(turboModule);
77+
folly::dynamic result = arkTsTurboModule->callSync("cvp2px", {getLayoutMetrics().frame.size.width});
78+
folly::dynamic result1 = arkTsTurboModule->callSync("cvp2px", {60});
79+
m_stackNode.setLayoutRect({0, 0}, {result["values"].asDouble(), result1["values"].asDouble()}, 1.0);
80+
}
7281
m_stackNode.setAlignment(ARKUI_ALIGNMENT_BOTTOM);
7382
}
7483

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace rnoh {
2424
SmartProgressNode progressNode;
2525
ArkUI_NodeHandle mColumnHandle;
2626
std::string primaryColor{""};
27+
std::string accentColor{""};
2728

2829
public:
2930
RNCDefaultHeaderComponentInstance(Context context);
@@ -34,7 +35,7 @@ namespace rnoh {
3435
void finalizeUpdates() override;
3536
SmartStackNode &getLocalRootArkUINode() override;
3637
void onRefreshStatusChange(int32_t status) override;
37-
std::string getDefaultHeaderBackGroundColor() { return primaryColor; }
3838
void setImageRotate(float angle);
39+
facebook::react::SharedColor GetPrimaryColor() override;
3940
};
4041
} // namespace rnoh

0 commit comments

Comments
 (0)