1
+ //
2
+ // Created on 2024/3/30.
3
+ //
4
+ // Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
5
+ // please include "napi/native_api.h".
6
+
7
+ #include " RNCClassicsHeaderComponentInstance.h"
8
+ #include " RNOH/arkui/NativeNodeApi.h"
9
+ #include " react/renderer/imagemanager/primitives.h"
10
+ #include " SmartRefreshState.h"
11
+
12
+ namespace rnoh {
13
+
14
+ RNCClassicsHeaderComponentInstance::RNCClassicsHeaderComponentInstance (Context context)
15
+ : CppComponentInstance(std::move(context)) {
16
+ LOG (INFO) << " [tyBrave] <RNCClassicsHeaderComponentInstance {}" ;
17
+
18
+ mColumnHandle = NativeNodeApi::getInstance ()->createNode (ARKUI_NODE_ROW);
19
+
20
+ facebook::react::ImageSources imageSources;
21
+ imageSources.push_back ({.uri = " resource://BASE/media/icon_up.png" });
22
+ imageNode.setSources (imageSources);
23
+ imageNode.setSize ({30 , 20 });
24
+ imageNode.setResizeMode (facebook::react::ImageResizeMode::Contain);
25
+
26
+ facebook::react::ImageSources imageUpdateSources;
27
+ imageUpdateSources.push_back ({.uri = " resource://BASE/media/icon_load.png" });
28
+ updateImageNode.setSources (imageUpdateSources);
29
+ updateImageNode.setSize ({25 , 25 });
30
+ updateImageNode.setResizeMode (facebook::react::ImageResizeMode::Contain);
31
+
32
+
33
+ auto textColumn = NativeNodeApi::getInstance ()->createNode (ARKUI_NODE_COLUMN);
34
+
35
+ ArkUI_NumberValue margin_self[] = {{.f32 = 0 }, {.f32 = 0 }, {.f32 = 0 }, {.f32 = 12 }};
36
+ ArkUI_AttributeItem margin[] = {margin_self, 4 };
37
+ NativeNodeApi::getInstance ()->setAttribute (textColumn, NODE_MARGIN, margin);
38
+
39
+ textNode.setTextContent (" 下拉刷新" );
40
+ textNode.setFontSize (15 );
41
+ textNode.setFontColor (0xff666666 );
42
+
43
+ timeTextNode.setTextContent (" 更新于 早上10:10" );
44
+ timeTextNode.setFontSize (12 );
45
+ timeTextNode.setFontColor (0xff7c7c7c );
46
+
47
+
48
+ NativeNodeApi::getInstance ()->insertChildAt (textColumn, textNode.getArkUINodeHandle (), 0 );
49
+ NativeNodeApi::getInstance ()->insertChildAt (textColumn, timeTextNode.getArkUINodeHandle (), 1 );
50
+
51
+ std::time_t now_seconds = std::chrono::system_clock::to_time_t (std::chrono::system_clock::now ());
52
+ std::tm *now_tm = std::localtime (&now_seconds);
53
+
54
+ LOG (INFO) << " [tyBrave] <RNCClassicsHeaderComponentInstance {}"
55
+ << " 当前时间: " << (now_tm->tm_year + 1900 ) << ' -' << (now_tm->tm_mon + 1 ) << ' -' << now_tm->tm_mday
56
+ << ' ' << now_tm->tm_hour << ' :' << now_tm->tm_min << ' :' << now_tm->tm_sec ;
57
+
58
+
59
+ mColumnHandle = NativeNodeApi::getInstance ()->createNode (ARKUI_NODE_ROW);
60
+
61
+ ArkUI_NumberValue heightNumberValue[] = {50 };
62
+ ArkUI_AttributeItem heightItem = {heightNumberValue, 1 };
63
+ NativeNodeApi::getInstance ()->setAttribute (mColumnHandle , NODE_HEIGHT, &heightItem);
64
+
65
+ NativeNodeApi::getInstance ()->insertChildAt (mColumnHandle , imageNode.getArkUINodeHandle (), 0 );
66
+ NativeNodeApi::getInstance ()->insertChildAt (mColumnHandle , updateImageNode.getArkUINodeHandle (), 1 );
67
+ NativeNodeApi::getInstance ()->insertChildAt (mColumnHandle , textColumn, 2 );
68
+ NativeNodeApi::getInstance ()->insertChildAt (m_stackNode.getArkUINodeHandle (), mColumnHandle , 0 );
69
+
70
+ // ArkUI_NumberValue positionArray[] = {{.f32 = -50}, {.f32 = 20}};
71
+ // ArkUI_AttributeItem positionValue[] = {positionArray, 2};
72
+ // NativeNodeApi::getInstance()->setAttribute(timeTextNode.getArkUINodeHandle(), NODE_POSITION,
73
+ // positionValue);
74
+ }
75
+ void RNCClassicsHeaderComponentInstance::onChildInserted (ComponentInstance::Shared const &childComponentInstance,
76
+ std::size_t index) {
77
+ CppComponentInstance::onChildInserted (childComponentInstance, index);
78
+ m_stackNode.insertChild (childComponentInstance->getLocalRootArkUINode (), index);
79
+ }
80
+
81
+ void RNCClassicsHeaderComponentInstance::onChildRemoved (ComponentInstance::Shared const &childComponentInstance) {
82
+ CppComponentInstance::onChildRemoved (childComponentInstance);
83
+ m_stackNode.removeChild (childComponentInstance->getLocalRootArkUINode ());
84
+ };
85
+
86
+ StackNode &RNCClassicsHeaderComponentInstance::getLocalRootArkUINode () { return m_stackNode; }
87
+
88
+ void RNCClassicsHeaderComponentInstance::onPropsChanged (SharedConcreteProps const &props) {
89
+ if (props != nullptr ) {
90
+ // facebook::react::SharedColor headerColor = props->primaryColor;
91
+ // LOG(INFO) << "[tyBrave] <SmartRefreshLayoutComponentInstance ---------------" <<
92
+ // props->accentColor
93
+ // << ";sss:" << props->primaryColor;
94
+ // if (props->accentColor) {
95
+ // textNode.setFontColor(props->accentColor);
96
+ // imageNode.setTintColor(props->accentColor);
97
+ // }
98
+ }
99
+ }
100
+
101
+ void RNCClassicsHeaderComponentInstance::finalizeUpdates () {
102
+ ArkUI_NumberValue heightNumberValue[] = {60 };
103
+ ArkUI_AttributeItem heightItem = {heightNumberValue, 1 };
104
+ NativeNodeApi::getInstance ()->setAttribute (m_stackNode.getArkUINodeHandle (), NODE_HEIGHT, &heightItem);
105
+ m_stackNode.setAlignment (ARKUI_ALIGNMENT_BOTTOM);
106
+ }
107
+
108
+ void RNCClassicsHeaderComponentInstance::setImageRotate (float angle) {
109
+ ArkUI_NumberValue opacityValue[] = {{.f32 = 0 }, {.f32 = 0 }, {.f32 = 1 }, {.f32 = angle}, {.f32 = 0 }};
110
+ ArkUI_AttributeItem opacityItem = {opacityValue, sizeof (opacityValue) / sizeof (ArkUI_NumberValue)};
111
+ NativeNodeApi::getInstance ()->setAttribute (imageNode.getArkUINodeHandle (), NODE_ROTATE, &opacityItem);
112
+ }
113
+
114
+ void RNCClassicsHeaderComponentInstance::onRefreshStatusChange (int32_t status) {
115
+
116
+ ArkUI_NumberValue imageNodeVisiblyAbleValue[] = {{.u32 = ARKUI_VISIBILITY_VISIBLE}};
117
+ ArkUI_AttributeItem imageNodeVisiblyAbleItem = {imageNodeVisiblyAbleValue, 1 };
118
+ NativeNodeApi::getInstance ()->setAttribute (imageNode.getArkUINodeHandle (), NODE_VISIBILITY,
119
+ &imageNodeVisiblyAbleItem);
120
+ switch (status) {
121
+ case IS_FREE:
122
+ case IS_PULL_DOWN_1: {
123
+ textNode.setTextContent (" 下拉刷新" );
124
+ setImageRotate (180.0 );
125
+ ArkUI_NumberValue visiblyAbleValue[] = {{.u32 = ARKUI_VISIBILITY_NONE}};
126
+ ArkUI_AttributeItem visiblyAbleItem = {visiblyAbleValue, 1 };
127
+ NativeNodeApi::getInstance ()->setAttribute (updateImageNode.getArkUINodeHandle (), NODE_VISIBILITY,
128
+ &visiblyAbleItem);
129
+ } break ;
130
+ case IS_REFRESHING: {
131
+ textNode.setTextContent (" 正在更新" );
132
+ ArkUI_NumberValue imageNodeVisiblyAbleValue[] = {{.u32 = ARKUI_VISIBILITY_NONE}};
133
+ ArkUI_AttributeItem imageNodeVisiblyAbleItem = {imageNodeVisiblyAbleValue, 1 };
134
+ NativeNodeApi::getInstance ()->setAttribute (imageNode.getArkUINodeHandle (), NODE_VISIBILITY,
135
+ &imageNodeVisiblyAbleItem);
136
+
137
+ ArkUI_NumberValue visiblyAbleValue[] = {{.u32 = ARKUI_VISIBILITY_VISIBLE}};
138
+ ArkUI_AttributeItem visiblyAbleItem = {visiblyAbleValue, 1 };
139
+ NativeNodeApi::getInstance ()->setAttribute (updateImageNode.getArkUINodeHandle (), NODE_VISIBILITY,
140
+ &visiblyAbleItem);
141
+ }
142
+
143
+ break ;
144
+ case IS_PULL_DOWN_2: {
145
+ textNode.setTextContent (" 释放刷新" );
146
+ setImageRotate (0.0 );
147
+ ArkUI_NumberValue visiblyAbleValue[] = {{.u32 = ARKUI_VISIBILITY_NONE}};
148
+ ArkUI_AttributeItem visiblyAbleItem = {visiblyAbleValue, 1 };
149
+ NativeNodeApi::getInstance ()->setAttribute (updateImageNode.getArkUINodeHandle (), NODE_VISIBILITY,
150
+ &visiblyAbleItem);
151
+ } break ;
152
+ case IS_REFRESHED: {
153
+ textNode.setTextContent (" 刷新完毕" );
154
+ ArkUI_NumberValue visiblyAbleValue[] = {{.u32 = ARKUI_VISIBILITY_NONE}};
155
+ ArkUI_AttributeItem visiblyAbleItem = {visiblyAbleValue, 1 };
156
+ NativeNodeApi::getInstance ()->setAttribute (updateImageNode.getArkUINodeHandle (), NODE_VISIBILITY,
157
+ &visiblyAbleItem);
158
+ } break ;
159
+ }
160
+ }
161
+ } // namespace rnoh
0 commit comments