Skip to content

Commit c25658c

Browse files
committed
add material header
1 parent 94f0026 commit c25658c

11 files changed

+153
-63
lines changed

harmony/smart_refresh_layout.har

778 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default class BuildProfile {
2-
static readonly HAR_VERSION = '0.6.7-0.3.1';
2+
static readonly HAR_VERSION = '0.6.7-0.3.2';
33
static readonly BUILD_MODE_NAME = 'debug';
44
static readonly DEBUG = true;
55
}

harmony/smart_refresh_layout/oh-package.json5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"name": "@react-native-oh-tpl/react-native-smartrefreshlayout",
77
"description": "Please describe the basic information.",
88
"main": "index.ets",
9-
"version": "0.6.7-0.3.1",
9+
"version": "0.6.7-0.3.2",
1010
"dependencies": {
1111
"rnoh": "file:../rnoh"
1212
},

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
// please include "napi/native_api.h".
66
#pragma once
77

8+
#include "RNOH/arkui/ArkUINode.h"
89
#include "boost/cstdint.hpp"
10+
#include <arkui/native_type.h>
11+
#include <bits/alltypes.h>
912
namespace rnoh {
1013
class HeaderNodeDelegate {
1114
public:
1215
virtual ~HeaderNodeDelegate() = default;
1316
virtual void onRefreshStatusChange(int32_t status){};
17+
virtual void addHeader(int32_t screenWidth, int32_t index, ArkUINode *arkUI_Node){};
18+
virtual void onHeaderMove(float dur){};
1419
};
15-
}
20+
} // namespace rnoh

harmony/smart_refresh_layout/src/main/cpp/RNCAnyHeaderComponentInstance.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#include "RNCAnyHeaderComponentInstance.h"
2+
#include "RNOH/arkui/NativeNodeApi.h"
23

34
namespace rnoh {
45

56
RNCAnyHeaderComponentInstance::RNCAnyHeaderComponentInstance(Context context)
6-
: CppComponentInstance(std::move(context)) {}
7+
: CppComponentInstance(std::move(context)) {
8+
ArkUI_NumberValue clipValue[] = {{.u32 = 1}};
9+
ArkUI_AttributeItem clipItem = {clipValue, sizeof(clipValue) / sizeof(ArkUI_NumberValue)};
10+
NativeNodeApi::getInstance()->setAttribute(m_stackNode.getArkUINodeHandle(), NODE_CLIP, &clipItem);
11+
}
712

813
void RNCAnyHeaderComponentInstance::onChildInserted(ComponentInstance::Shared const &childComponentInstance,
914
std::size_t index) {

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

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@
66

77
#include "RNCMaterialHeaderComponentInstance.h"
88
#include "RNOH/arkui/NativeNodeApi.h"
9+
#include "TaskCommonThread.h"
910
#include "react/renderer/imagemanager/primitives.h"
1011
#include "SmartRefreshState.h"
12+
#include <bits/alltypes.h>
1113

1214
namespace rnoh {
1315

1416
RNCMaterialHeaderComponentInstance::RNCMaterialHeaderComponentInstance(Context context)
15-
: CppComponentInstance(std::move(context)) {
16-
LOG(INFO) << "[tyBrave] <RNCMaterialHeaderComponentInstance {}";
17+
: CppComponentInstance(std::move(context)) {}
1718

18-
facebook::react::ImageSources imageSources;
19-
imageSources.push_back({.uri = "resource://BASE/media/icon_up.png"});
20-
imageNode.setSources(imageSources);
21-
imageNode.setSize({30, 20});
22-
imageNode.setResizeMode(facebook::react::ImageResizeMode::Contain);
19+
void RNCMaterialHeaderComponentInstance::addHeader(int32_t screenWidth, int32_t index, ArkUINode *arkUI_Node) {
20+
mWindowWidth = screenWidth;
21+
progressNode.setLoadingProgressNodeColor(0x53658461);
22+
progressNode.setLoadingProgressNodeAnimating(true);
23+
progressNode.setSize({45, 45});
2324

24-
auto imageStack = NativeNodeApi::getInstance()->createNode(ARKUI_NODE_STACK);
25+
imageStack = NativeNodeApi::getInstance()->createNode(ARKUI_NODE_STACK);
2526

2627
ArkUI_NumberValue heightArray[] = {{.f32 = 45}};
2728
ArkUI_AttributeItem heightValue[] = {heightArray, 1};
@@ -51,24 +52,36 @@ namespace rnoh {
5152
ArkUI_AttributeItem z_indexValue[] = {z_indexArray, 1};
5253
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_Z_INDEX, z_indexValue);
5354

54-
// ArkUI_NumberValue borderStyArray[] = {ArkUI_BorderStyle::ARKUI_BORDER_STYLE_SOLID};
55-
// ArkUI_AttributeItem borderStyValue[] = {borderStyArray, 1};
56-
// NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_BORDER_STYLE, borderStyValue);
57-
58-
// uint32_t colorValue =0xFFFFFF00; // facebook::react::isColorMeaningful(color) ? *color :
59-
// *facebook::react::clearColor(); ArkUI_NumberValue preparedColorValue[] = {{.u32 = colorValue}};
60-
// ArkUI_AttributeItem colorItem = {preparedColorValue, sizeof(preparedColorValue) /
61-
// sizeof(ArkUI_NumberValue)}; NativeNodeApi::getInstance()->setAttribute(imageStack,
62-
// NODE_BACKGROUND_COLOR, &colorItem);
63-
64-
65-
NativeNodeApi::getInstance()->insertChildAt(imageStack, imageNode.getArkUINodeHandle(), 0);
66-
67-
ArkUI_NumberValue positionArray[] = {{.f32 = 80}, {.f32 = 90}};
55+
NativeNodeApi::getInstance()->insertChildAt(imageStack, progressNode.getArkUINodeHandle(), 0);
56+
NativeNodeApi::getInstance()->insertChildAt(arkUI_Node->getArkUINodeHandle(), imageStack, index);
57+
ArkUI_NumberValue positionArray[] = {{.f32 = static_cast<float>((screenWidth - 45) / 2.0)}, {.f32 = -45}};
6858
ArkUI_AttributeItem positionValue[] = {positionArray, 2};
6959
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_POSITION, positionValue);
60+
}
7061

71-
NativeNodeApi::getInstance()->insertChildAt(m_stackNode.getArkUINodeHandle(), imageStack, 0);
62+
void RNCMaterialHeaderComponentInstance::onHeaderMove(float dur) {
63+
if (isRefreshed) {
64+
return;
65+
}
66+
ArkUI_NumberValue positionArray[] = {{.f32 = static_cast<float>((mWindowWidth - 45) / 2.0)}, {.f32 = dur - 45}};
67+
ArkUI_AttributeItem positionValue[] = {positionArray, 2};
68+
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_POSITION, positionValue);
69+
}
70+
void RNCMaterialHeaderComponentInstance::setScaleAnimate(int32_t dur) {
71+
72+
TaskCommonThread *task = new TaskCommonThread();
73+
task->setTaskParams(static_cast<std::chrono::milliseconds>(dur), [this](double v) {
74+
float value = 1.0 - static_cast<float>(v);
75+
ArkUI_NumberValue scaleArray[] = {{.f32 = value}, {.f32 = value}};
76+
ArkUI_AttributeItem scaleValue[] = {scaleArray, 2};
77+
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_SCALE, scaleValue);
78+
if (std::abs(value - 0.01) < 1e-6) {
79+
ArkUI_NumberValue scaleArray[] = {{.f32 = 1.0}, {.f32 = 1.0}};
80+
ArkUI_AttributeItem scaleValue[] = {scaleArray, 2};
81+
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_SCALE, scaleValue);
82+
}
83+
});
84+
task->execute();
7285
}
7386
void RNCMaterialHeaderComponentInstance::onChildInserted(ComponentInstance::Shared const &childComponentInstance,
7487
std::size_t index) {
@@ -84,36 +97,31 @@ namespace rnoh {
8497

8598
StackNode &RNCMaterialHeaderComponentInstance::getLocalRootArkUINode() { return m_stackNode; }
8699

87-
void RNCMaterialHeaderComponentInstance::finalizeUpdates() {
88-
m_stackNode.setAlignment(ARKUI_ALIGNMENT_CENTER);
89-
m_stackNode.setBackgroundColor(0XFFFFFF00);
90-
if (getParent().lock()) {
91-
LOG(INFO) << "[tyBrave] <RNCMaterialHeaderComponentInstance finalizeUpdates "
92-
<< getParent().lock()->getComponentName();
93-
}
94-
95-
}
96-
97-
void RNCMaterialHeaderComponentInstance::setImageRotate(float angle) {
98-
ArkUI_NumberValue opacityValue[] = {{.f32 = 0}, {.f32 = 0}, {.f32 = 1}, {.f32 = angle}, {.f32 = 0}};
99-
ArkUI_AttributeItem opacityItem = {opacityValue, sizeof(opacityValue) / sizeof(ArkUI_NumberValue)};
100-
NativeNodeApi::getInstance()->setAttribute(imageNode.getArkUINodeHandle(), NODE_ROTATE, &opacityItem);
101-
}
102100

103101
void RNCMaterialHeaderComponentInstance::onRefreshStatusChange(int32_t status) {
104102
switch (status) {
105103
case IS_FREE:
106-
case IS_PULL_DOWN_1: {
107-
104+
{
105+
float x = static_cast<float>((mWindowWidth - 45) / 2.0);
106+
float y = -45.0;
107+
ArkUI_NumberValue positionArray[] = {{.f32 = x}, {.f32 = y}};
108+
ArkUI_AttributeItem positionValue[] = {positionArray, 2};
109+
NativeNodeApi::getInstance()->setAttribute(imageStack, NODE_POSITION, positionValue);
110+
}
111+
case IS_PULL_DOWN_1:
112+
case IS_PULL_DOWN_2: {
113+
isRefreshed = false;
114+
progressNode.setLoadingProgressNodeColor(0xff0099cc);
108115
} break;
109116
case IS_REFRESHING: {
117+
progressNode.setLoadingProgressNodeColor(0xffff4444);
110118
}
111119

112120
break;
113-
case IS_PULL_DOWN_2: {
114-
} break;
115121
case IS_REFRESHED: {
116-
122+
isRefreshed = true;
123+
progressNode.setLoadingProgressNodeColor(0xffaa66cc);
124+
setScaleAnimate(1000);
117125
} break;
118126
}
119127
}

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "RNOH/CppComponentInstance.h"
1010
#include "RNOH/arkui/StackNode.h"
1111
#include "RNOH/arkui/TextNode.h"
12-
#include "RNOH/arkui/ImageNode.h"
12+
#include "RNOH/arkui/LoadingProgressNode.h"
1313
#include "ShadowNodes.h"
1414

1515
namespace rnoh {
@@ -19,16 +19,20 @@ namespace rnoh {
1919

2020
private:
2121
StackNode m_stackNode;
22-
ImageNode imageNode;
23-
22+
ArkUI_NodeHandle imageStack;
23+
LoadingProgressNode progressNode;
24+
float mWindowWidth{0.0};
25+
bool isRefreshed{false};
26+
2427
public:
2528
RNCMaterialHeaderComponentInstance(Context context);
2629
void onChildInserted(ComponentInstance::Shared const &childComponentInstance, std::size_t index) override;
2730
void onChildRemoved(ComponentInstance::Shared const &childComponentInstance) override;
28-
29-
void finalizeUpdates() override;
31+
3032
StackNode &getLocalRootArkUINode() override;
3133
void onRefreshStatusChange(int32_t status) override;
32-
void setImageRotate(float angle);
34+
void addHeader(int32_t screenWidth, int32_t index, ArkUINode *arkUI_Node) override;
35+
void onHeaderMove(float dur) override;
36+
void setScaleAnimate(int32_t dur);
3337
};
3438
} // namespace rnoh

harmony/smart_refresh_layout/src/main/cpp/SmartRefreshLayoutComponentInstance.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "RNOH/arkui/ArkUINode.h"
44
#include "RNOH/arkui/ScrollNode.h"
55
#include "RNOHCorePackage/ComponentInstances/ScrollViewComponentInstance.h"
6-
#include "react/renderer/components/scrollview/ScrollViewProps.h"
76
#include "react/renderer/graphics/Color.h"
87
#include <arkui/native_interface.h>
98
#include <arkui/native_node.h>
@@ -41,7 +40,8 @@ namespace rnoh {
4140
}
4241
auto nodeValue =
4342
NativeNodeApi::getInstance()->getAttribute(m_pullToRefreshNode.getArkUINodeHandle(), NODE_WIDTH);
44-
m_headerStackNode.setSize(facebook::react::Size({nodeValue->value[nodeValue->size - 1].f32, 0}));
43+
mWidth = nodeValue->value[nodeValue->size - 1].f32;
44+
m_headerStackNode.setSize(facebook::react::Size({mWidth, 0}));
4545
setOtherHeaderDelegate();
4646
}
4747

@@ -190,6 +190,7 @@ namespace rnoh {
190190
if (trYTop == 0) {
191191
state = IS_FREE;
192192
m_pullToRefreshNode.markDirty();
193+
this->changeStatus();
193194
}
194195
onHeaderReleasing(trYTop);
195196
});
@@ -200,8 +201,8 @@ namespace rnoh {
200201

201202
void SmartRefreshLayoutComponentInstance::finishRefresh() {
202203
state = IS_REFRESHED;
203-
closeRefresh(trYTop, 0, m_pullToRefreshNode.getPullToRefreshConfigurator().getAnimDuration());
204204
changeStatus();
205+
closeRefresh(trYTop, 0, m_pullToRefreshNode.getPullToRefreshConfigurator().getAnimDuration());
205206
}
206207

207208
bool SmartRefreshLayoutComponentInstance::isComponentTop() {
@@ -216,13 +217,13 @@ namespace rnoh {
216217
}
217218
return false;
218219
};
219-
void SmartRefreshLayoutComponentInstance::setNativeResponderBlocked(bool blocked) {
220+
void SmartRefreshLayoutComponentInstance::onNativeResponderBlockChange(bool blocked) {
220221
std::vector<ComponentInstance::Shared> child = getChildren();
221222
for (ComponentInstance::Shared c : child) {
222223
if (c->getComponentName() == "ScrollView") {
223224
auto scrollView = std::dynamic_pointer_cast<rnoh::ScrollViewComponentInstance>(c);
224225
if (blocked) {
225-
scrollView->setNativeResponderBlocked(!blocked);
226+
scrollView->onNativeResponderBlockChange(!blocked);
226227
}
227228
break;
228229
}
@@ -252,7 +253,12 @@ namespace rnoh {
252253
void SmartRefreshLayoutComponentInstance::onRefresh() { m_eventEmitter->onRefresh({}); };
253254

254255
void SmartRefreshLayoutComponentInstance::setPullHeaderHeight(float h) {
255-
m_pullToRefreshNode.setHeaderHeight(h);
256+
257+
if (globalHeaderType == "RNCMaterialHeader" &&delegate) {
258+
delegate->onHeaderMove(h);
259+
} else {
260+
m_pullToRefreshNode.setHeaderHeight(h);
261+
}
256262
onHeaderMoving(h);
257263
}
258264

@@ -262,7 +268,8 @@ namespace rnoh {
262268
};
263269

264270
void SmartRefreshLayoutComponentInstance::changeStatus() {
265-
if (globalHeaderType != "RNCDefaultHeader" && globalHeaderType != "RNCClassicsHeader") {
271+
if (globalHeaderType != "RNCDefaultHeader" && globalHeaderType != "RNCClassicsHeader" &&
272+
globalHeaderType != "RNCMaterialHeader") {
266273
return;
267274
}
268275
if (delegate == nullptr) {
@@ -277,8 +284,15 @@ namespace rnoh {
277284
if (delegate == nullptr) {
278285
std::vector<ComponentInstance::Shared> child = getChildren();
279286
for (ComponentInstance::Shared c : child) {
280-
if (c->getComponentName() == "RNCDefaultHeader" || c->getComponentName() == "RNCClassicsHeader") {
287+
if (c->getComponentName() == "RNCDefaultHeader" || c->getComponentName() == "RNCClassicsHeader" ||
288+
c->getComponentName() == "RNCMaterialHeader") {
281289
delegate = std::dynamic_pointer_cast<rnoh::HeaderNodeDelegate>(c);
290+
if (delegate != nullptr && c->getComponentName() == "RNCMaterialHeader") {
291+
ArkUI_NumberValue clipValue[] = {{.u32 = 1}};
292+
ArkUI_AttributeItem clipItem = {clipValue, sizeof(clipValue) / sizeof(ArkUI_NumberValue)};
293+
NativeNodeApi::getInstance()->setAttribute(m_pullToRefreshNode.getArkUINodeHandle(), NODE_CLIP, &clipItem);
294+
delegate->addHeader(mWidth, 3, &m_pullToRefreshNode);
295+
}
282296
// if (defaultHeaderInstance != nullptr &&
283297
// !defaultHeaderInstance->getDefaultHeaderBackGroundColor().empty()) {
284298
// std::string str =

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace rnoh {
3232
facebook::react::SmartRefreshLayoutAutoRefreshStruct autoRefresh{};
3333
bool isHeaderInserted{false}; // whether list child component inserted
3434
float trYTop{0.0};
35+
float mWidth{0.0};
3536
int32_t state{IS_FREE};
3637
int32_t touchYOld{0};
3738
int32_t touchYNew{0};
@@ -52,7 +53,7 @@ namespace rnoh {
5253
bool isComponentTop() override;
5354

5455
PullToRefreshNode &getLocalRootArkUINode() override;
55-
void setNativeResponderBlocked(bool blocked) override;
56+
void onNativeResponderBlockChange(bool isBlocked)override;
5657
void panGesture(ArkUI_NodeHandle arkUI_NodeHandle);
5758
float getTranslateYOfRefresh(float newTranslateY);
5859
void onActionUpdate();
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//
2+
// Created on 2024/4/3.
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+
//
8+
// Created on 10/3/2024.
9+
//
10+
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
11+
// please include "napi/native_api.h".
12+
13+
#ifndef HARMONY_ANIMATION_H
14+
#define HARMONY_ANIMATION_H
15+
#include <thread>
16+
#include <atomic>
17+
#include <chrono>
18+
19+
class TaskCommonThread {
20+
public:
21+
TaskCommonThread() {}
22+
~TaskCommonThread() { cancelTask(); }
23+
24+
void setTaskParams(std::chrono::milliseconds durationSeconds, std::function<void(double)> callback) {
25+
duration_ = durationSeconds;
26+
callback_ = callback;
27+
if (!callback_) {
28+
throw std::invalid_argument("Callback cannot be null");
29+
}
30+
}
31+
void execute() { updateThread_ = new std::thread(&TaskCommonThread::task, this); }
32+
33+
private:
34+
void task() {
35+
for (double t = 0.01; t <= 1.0; t += 0.01) {
36+
callback_(t);
37+
std::this_thread::sleep_for(duration_ * 0.01);
38+
}
39+
}
40+
41+
private:
42+
std::chrono::milliseconds duration_;
43+
std::thread *updateThread_;
44+
std::function<void(double)> callback_;
45+
void cancelTask() {
46+
if (updateThread_ != nullptr) {
47+
updateThread_->join();
48+
delete updateThread_;
49+
updateThread_ = nullptr;
50+
}
51+
}
52+
};
53+
#endif // HARMONY_ANIMATION_H

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@react-native-oh-tpl/react-native-smartrefreshlayout",
3-
"version": "0.6.7-0.3.1",
3+
"version": "0.6.7-0.3.2",
44
"description": "基于android SmartRefreshLayout的封装",
55
"harmony": {
66
"alias": "react-native-smartrefreshlayout"

0 commit comments

Comments
 (0)