@react-native-ohos/react-native-pager-view 6.2.4-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/harmony/pager_view/LICENSE +21 -0
- package/harmony/pager_view/NOTICE +33 -0
- package/harmony/pager_view/README.OpenSource +11 -0
- package/harmony/pager_view/build-profile.json5 +9 -0
- package/harmony/pager_view/consumer-rules.txt +0 -0
- package/harmony/pager_view/hvigorfile.ts +6 -0
- package/harmony/pager_view/index.ets +26 -0
- package/harmony/pager_view/obfuscation-rules.txt +18 -0
- package/harmony/pager_view/oh-package.json5 +14 -0
- package/harmony/pager_view/src/main/cpp/CMakeLists.txt +9 -0
- package/harmony/pager_view/src/main/cpp/RNCViewPagerTurbomodule.cpp +42 -0
- package/harmony/pager_view/src/main/cpp/RNCViewPagerTurbomodule.h +37 -0
- package/harmony/pager_view/src/main/cpp/SwiperNode.cpp +403 -0
- package/harmony/pager_view/src/main/cpp/SwiperNode.h +120 -0
- package/harmony/pager_view/src/main/cpp/ViewPagerComponentInstance.cpp +247 -0
- package/harmony/pager_view/src/main/cpp/ViewPagerComponentInstance.h +106 -0
- package/harmony/pager_view/src/main/cpp/ViewPagerPackage.h +64 -0
- package/harmony/pager_view/src/main/cpp/generated/RNOH/generated/BaseReactNativePagerViewPackage.h +70 -0
- package/harmony/pager_view/src/main/cpp/generated/RNOH/generated/components/BaseRNCViewPagerComponentInstance.h +16 -0
- package/harmony/pager_view/src/main/cpp/generated/RNOH/generated/components/RNCViewPagerJSIBinder.h +41 -0
- package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/ComponentDescriptors.h +22 -0
- package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/EventEmitters.cpp +43 -0
- package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/EventEmitters.h +47 -0
- package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/Props.cpp +38 -0
- package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/Props.h +139 -0
- package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/ShadowNodes.cpp +19 -0
- package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/ShadowNodes.h +34 -0
- package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/States.cpp +16 -0
- package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/States.h +38 -0
- package/harmony/pager_view/src/main/ets/Logger.ets +64 -0
- package/harmony/pager_view/src/main/ets/RNCViewPager.ets +281 -0
- package/harmony/pager_view/src/main/ets/RNCViewPagerManager.ets +58 -0
- package/harmony/pager_view/src/main/ets/ViewPagerModule.ts +34 -0
- package/harmony/pager_view/src/main/ets/ViewPagerPackage.ets +57 -0
- package/harmony/pager_view/src/main/module.json5 +7 -0
- package/harmony/pager_view/src/main/resources/base/element/string.json +8 -0
- package/harmony/pager_view/src/main/resources/en_US/element/string.json +8 -0
- package/harmony/pager_view/src/main/resources/zh_CN/element/string.json +8 -0
- package/harmony/pager_view/ts.ets +26 -0
- package/harmony/pager_view.har +0 -0
- package/lib/commonjs/PagerView.js +145 -0
- package/lib/commonjs/PagerView.js.map +1 -0
- package/lib/commonjs/PagerViewNativeComponent.js +14 -0
- package/lib/commonjs/PagerViewNativeComponent.js.map +1 -0
- package/lib/commonjs/index.js +9 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/utils.js +28 -0
- package/lib/commonjs/utils.js.map +1 -0
- package/lib/module/PagerView.js +138 -0
- package/lib/module/PagerView.js.map +1 -0
- package/lib/module/PagerViewNativeComponent.js +7 -0
- package/lib/module/PagerViewNativeComponent.js.map +1 -0
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/utils.js +20 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/typescript/PagerView.d.ts +70 -0
- package/lib/typescript/PagerViewNativeComponent.d.ts +36 -0
- package/lib/typescript/index.d.ts +8 -0
- package/lib/typescript/utils.d.ts +2 -0
- package/package.json +142 -0
- package/src/PagerView.tsx +163 -0
- package/src/PagerViewNativeComponent.ts +67 -0
- package/src/index.tsx +26 -0
- package/src/utils.tsx +19 -0
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
#include "SwiperNode.h"
|
|
26
|
+
#include "RNOH/arkui/NativeNodeApi.h"
|
|
27
|
+
#define MIN_THRESHOLD 0.1
|
|
28
|
+
|
|
29
|
+
namespace rnoh {
|
|
30
|
+
enum Index {
|
|
31
|
+
ONE_INDEX = 0,
|
|
32
|
+
TWO_INDEX = 1,
|
|
33
|
+
THREE_INDEX = 2
|
|
34
|
+
};
|
|
35
|
+
SwiperNode::SwiperNode()
|
|
36
|
+
: ArkUINode(NativeNodeApi::getInstance()->createNode(ArkUI_NodeType::ARKUI_NODE_SWIPER)),
|
|
37
|
+
m_stackArkUINodeHandle(nullptr), m_swiperNodeDelegate(nullptr)
|
|
38
|
+
{
|
|
39
|
+
maybeThrow(NativeNodeApi::getInstance()->registerNodeEvent(m_nodeHandle, NODE_SWIPER_EVENT_ON_ANIMATION_START,
|
|
40
|
+
NODE_SWIPER_EVENT_ON_ANIMATION_START, this));
|
|
41
|
+
maybeThrow(NativeNodeApi::getInstance()->registerNodeEvent(m_nodeHandle, NODE_SWIPER_EVENT_ON_ANIMATION_END,
|
|
42
|
+
NODE_SWIPER_EVENT_ON_ANIMATION_END, this));
|
|
43
|
+
maybeThrow(NativeNodeApi::getInstance()->registerNodeEvent(m_nodeHandle, NODE_SWIPER_EVENT_ON_CHANGE,
|
|
44
|
+
NODE_SWIPER_EVENT_ON_CHANGE, this));
|
|
45
|
+
maybeThrow(NativeNodeApi::getInstance()->registerNodeEvent(m_nodeHandle, NODE_SWIPER_EVENT_ON_GESTURE_SWIPE,
|
|
46
|
+
NODE_SWIPER_EVENT_ON_GESTURE_SWIPE, this));
|
|
47
|
+
maybeThrow(NativeNodeApi::getInstance()->registerNodeEvent(
|
|
48
|
+
m_nodeHandle, NODE_SWIPER_EVENT_ON_CONTENT_DID_SCROLL, NODE_SWIPER_EVENT_ON_CONTENT_DID_SCROLL, this));
|
|
49
|
+
maybeThrow(NativeNodeApi::getInstance()->registerNodeEvent(
|
|
50
|
+
m_nodeHandle, NODE_EVENT_ON_APPEAR, NODE_EVENT_ON_APPEAR, this));
|
|
51
|
+
// 开启嵌套滑动时的父子联动响应
|
|
52
|
+
ArkUI_NumberValue indexValue[] = {{.i32 = m_swiperNestedScrollMode}};
|
|
53
|
+
ArkUI_AttributeItem indexItem = {indexValue, sizeof(indexValue) / sizeof(ArkUI_NumberValue)};
|
|
54
|
+
maybeThrow(NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_SWIPER_NESTED_SCROLL, &indexItem));
|
|
55
|
+
}
|
|
56
|
+
SwiperNode::~SwiperNode()
|
|
57
|
+
{
|
|
58
|
+
NativeNodeApi::getInstance()->unregisterNodeEvent(m_nodeHandle, NODE_SWIPER_EVENT_ON_ANIMATION_START);
|
|
59
|
+
NativeNodeApi::getInstance()->unregisterNodeEvent(m_nodeHandle, NODE_SWIPER_EVENT_ON_ANIMATION_END);
|
|
60
|
+
NativeNodeApi::getInstance()->unregisterNodeEvent(m_nodeHandle, NODE_SWIPER_EVENT_ON_CHANGE);
|
|
61
|
+
NativeNodeApi::getInstance()->unregisterNodeEvent(m_nodeHandle, NODE_SWIPER_EVENT_ON_GESTURE_SWIPE);
|
|
62
|
+
NativeNodeApi::getInstance()->unregisterNodeEvent(m_nodeHandle, NODE_SWIPER_EVENT_ON_CONTENT_DID_SCROLL);
|
|
63
|
+
NativeNodeApi::getInstance()->unregisterNodeEvent(m_nodeHandle, NODE_EVENT_ON_APPEAR);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
void SwiperNode::insertChild(ArkUINode &child, std::size_t index)
|
|
68
|
+
{
|
|
69
|
+
m_stackArkUINodeHandle = NativeNodeApi::getInstance()->createNode(ArkUI_NodeType::ARKUI_NODE_STACK);
|
|
70
|
+
maybeThrow(NativeNodeApi::getInstance()->addChild(m_nodeHandle, m_stackArkUINodeHandle));
|
|
71
|
+
m_nodeHandleMap[&child] = m_stackArkUINodeHandle;
|
|
72
|
+
maybeThrow(NativeNodeApi::getInstance()->insertChildAt(m_stackArkUINodeHandle,
|
|
73
|
+
child.getArkUINodeHandle(), index));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
void SwiperNode::removeChild(ArkUINode &child)
|
|
77
|
+
{
|
|
78
|
+
if (m_nodeHandleMap.find(&child) != m_nodeHandleMap.end()) {
|
|
79
|
+
ArkUI_NodeHandle stackNodeHandle = m_nodeHandleMap.find(&child)->second;
|
|
80
|
+
maybeThrow(NativeNodeApi::getInstance()->removeChild(m_nodeHandle, stackNodeHandle));
|
|
81
|
+
maybeThrow(NativeNodeApi::getInstance()->removeChild(stackNodeHandle, child.getArkUINodeHandle()));
|
|
82
|
+
m_nodeHandleMap.erase(&child);
|
|
83
|
+
} else {
|
|
84
|
+
maybeThrow(NativeNodeApi::getInstance()->removeChild(m_stackArkUINodeHandle, child.getArkUINodeHandle()));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
void SwiperNode::setSwiperNodeDelegate(SwiperNodeDelegate *swiperNodeDelegate)
|
|
88
|
+
{
|
|
89
|
+
m_swiperNodeDelegate = swiperNodeDelegate;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
void SwiperNode::onNodeEvent(ArkUI_NodeEventType eventType, EventArgs &eventArgs)
|
|
93
|
+
{
|
|
94
|
+
if (m_swiperNodeDelegate == nullptr) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
DLOG(INFO) << "onNodeEvent-->start";
|
|
98
|
+
if (eventType == ArkUI_NodeEventType::NODE_SWIPER_EVENT_ON_ANIMATION_START) {
|
|
99
|
+
this->m_interceptSendOffset = false;
|
|
100
|
+
this->animationStart = std::chrono::high_resolution_clock::now();
|
|
101
|
+
this->m_currentIndex = eventArgs[ONE_INDEX].i32;
|
|
102
|
+
this->m_targetIndex = eventArgs[TWO_INDEX].i32;
|
|
103
|
+
DLOG(INFO) << "onNodeEvent-->NODE_SWIPER_EVENT_ON_ANIMATION_START m_currentIndex:"
|
|
104
|
+
<< eventArgs[ONE_INDEX].i32
|
|
105
|
+
<< " m_targetIndex:" << this->m_targetIndex;
|
|
106
|
+
this->m_pageSelectNotify = true;
|
|
107
|
+
m_swiperNodeDelegate->setKeyboardDismiss();
|
|
108
|
+
facebook::react::RNCViewPagerEventEmitter::OnPageScrollStateChanged event = {
|
|
109
|
+
facebook::react::RNCViewPagerEventEmitter::OnPageScrollStateChangedPageScrollState::SETTLING};
|
|
110
|
+
m_swiperNodeDelegate->onPageScrollStateChanged(event);
|
|
111
|
+
} else if (eventType == ArkUI_NodeEventType::NODE_SWIPER_EVENT_ON_ANIMATION_END) {
|
|
112
|
+
this->animationEnd = std::chrono::high_resolution_clock::now();
|
|
113
|
+
std::chrono::duration<double> duration = this->animationEnd - this->animationStart;
|
|
114
|
+
if (duration.count() < MIN_THRESHOLD) {
|
|
115
|
+
this->m_interceptSendOffset = true;
|
|
116
|
+
}
|
|
117
|
+
DLOG(INFO) << "onNodeEvent-->NODE_SWIPER_EVENT_ON_ANIMATION_END: " << eventArgs[ONE_INDEX].i32
|
|
118
|
+
<< " clock_diff:" << duration.count();
|
|
119
|
+
facebook::react::RNCViewPagerEventEmitter::OnPageScroll m_onPageScroll = {
|
|
120
|
+
static_cast<double>(eventArgs[ONE_INDEX].i32), 0};
|
|
121
|
+
m_swiperNodeDelegate->onPageScroll(m_onPageScroll);
|
|
122
|
+
m_swiperNodeDelegate->sendEventAnimationsPageScroll(m_onPageScroll);
|
|
123
|
+
facebook::react::RNCViewPagerEventEmitter::OnPageScrollStateChanged pageScrollStateChange = {
|
|
124
|
+
facebook::react::RNCViewPagerEventEmitter::OnPageScrollStateChangedPageScrollState::IDLE};
|
|
125
|
+
m_swiperNodeDelegate->onPageScrollStateChanged(pageScrollStateChange);
|
|
126
|
+
this->m_gestureSwipe = false;
|
|
127
|
+
m_swiperNodeDelegate->setGestureStatus(this->m_gestureSwipe);
|
|
128
|
+
} else if (eventType == ArkUI_NodeEventType::NODE_SWIPER_EVENT_ON_CHANGE) {
|
|
129
|
+
DLOG(INFO) << "onNodeEvent-->NODE_SWIPER_EVENT_ON_CHANGE: " << eventArgs[ONE_INDEX].i32;
|
|
130
|
+
m_swiperNodeDelegate->onPageSelected(eventArgs[ONE_INDEX].i32);
|
|
131
|
+
if (!this->m_pageSelectNotify) {
|
|
132
|
+
facebook::react::RNCViewPagerEventEmitter::OnPageScroll m_onPageScroll = {
|
|
133
|
+
static_cast<double>(eventArgs[ONE_INDEX].i32), 0};
|
|
134
|
+
m_swiperNodeDelegate->onPageScroll(m_onPageScroll);
|
|
135
|
+
m_swiperNodeDelegate->sendEventAnimationsPageScroll(m_onPageScroll);
|
|
136
|
+
}
|
|
137
|
+
this->m_offsetCount = 0;
|
|
138
|
+
this->m_firstSwipe = true;
|
|
139
|
+
this->m_preOffset = this->OFFSET_DEFAULT_VALUE;
|
|
140
|
+
this->m_pageSelectNotify = false;
|
|
141
|
+
} else if (eventType == ArkUI_NodeEventType::NODE_SWIPER_EVENT_ON_GESTURE_SWIPE) {
|
|
142
|
+
DLOG(INFO) << "onNodeEvent-->NODE_SWIPER_EVENT_ON_GESTURE_SWIPE";
|
|
143
|
+
m_swiperNodeDelegate->setClickTap(false);
|
|
144
|
+
this->m_interceptSendOffset = false;
|
|
145
|
+
this->m_gestureSwipe = true;
|
|
146
|
+
m_swiperNodeDelegate->setGestureStatus(this->m_gestureSwipe);
|
|
147
|
+
facebook::react::RNCViewPagerEventEmitter::OnPageScrollStateChanged event = {
|
|
148
|
+
facebook::react::RNCViewPagerEventEmitter::OnPageScrollStateChangedPageScrollState::DRAGGING};
|
|
149
|
+
m_swiperNodeDelegate->onPageScrollStateChanged(event);
|
|
150
|
+
} else if (eventType == ArkUI_NodeEventType::NODE_SWIPER_EVENT_ON_CONTENT_DID_SCROLL) {
|
|
151
|
+
DLOG(INFO) << "onNodeEvent-->NODE_SWIPER_EVENT_ON_CONTENT_DID_SCROLL selectedIndex: "
|
|
152
|
+
<< eventArgs[ONE_INDEX].i32
|
|
153
|
+
<< " index:" << eventArgs[TWO_INDEX].i32 << " position:" << eventArgs[THREE_INDEX].f32
|
|
154
|
+
<< " m_interceptSendOffset:" << this->m_interceptSendOffset
|
|
155
|
+
<< " getClickTap:" << m_swiperNodeDelegate->getClickTap();
|
|
156
|
+
if (this->m_interceptSendOffset || !m_swiperNodeDelegate->getScrollEnabled() ||
|
|
157
|
+
m_swiperNodeDelegate->getNativeLock()) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
double selectedIndex = eventArgs[ONE_INDEX].i32;
|
|
161
|
+
double index = eventArgs[TWO_INDEX].i32;
|
|
162
|
+
if (selectedIndex != index) {
|
|
163
|
+
static double offset;
|
|
164
|
+
if (((m_swiperNodeDelegate->getClickTap() && this->m_currentIndex > this->m_targetIndex) &&
|
|
165
|
+
(index < selectedIndex)) ||
|
|
166
|
+
(!m_swiperNodeDelegate->getClickTap() && (index < selectedIndex))) {
|
|
167
|
+
if ((this->m_gestureSwipe && !m_swiperNodeDelegate->getClickTap()) ||
|
|
168
|
+
(((selectedIndex - this->m_targetIndex) == 1) && (selectedIndex > index) &&
|
|
169
|
+
((selectedIndex - index) == 1))) {
|
|
170
|
+
if ((selectedIndex > index) && ((selectedIndex - index) == 1)) {
|
|
171
|
+
this->m_offsetCount++;
|
|
172
|
+
offset = -eventArgs[THREE_INDEX].f32;
|
|
173
|
+
if (selectedIndex >= 1) {
|
|
174
|
+
selectedIndex = selectedIndex - 1;
|
|
175
|
+
}
|
|
176
|
+
if (offset < 0) {
|
|
177
|
+
offset = 0;
|
|
178
|
+
}
|
|
179
|
+
facebook::react::RNCViewPagerEventEmitter::OnPageScroll m_onPageScroll = {selectedIndex,
|
|
180
|
+
offset};
|
|
181
|
+
m_swiperNodeDelegate->onPageScroll(m_onPageScroll);
|
|
182
|
+
m_swiperNodeDelegate->sendEventAnimationsPageScroll(m_onPageScroll);
|
|
183
|
+
}
|
|
184
|
+
} else {
|
|
185
|
+
if (this->m_firstSwipe) {
|
|
186
|
+
this->m_offsetCountIndex = selectedIndex;
|
|
187
|
+
this->m_firstSwipe = false;
|
|
188
|
+
}
|
|
189
|
+
this->m_offsetCount++;
|
|
190
|
+
if (((this->m_offsetCountIndex - 1) == index)) {
|
|
191
|
+
if (eventArgs[THREE_INDEX].f32 <= 0) {
|
|
192
|
+
offset = -eventArgs[THREE_INDEX].f32;
|
|
193
|
+
static double preoffset = this->m_preOffset;
|
|
194
|
+
if ((preoffset != this->OFFSET_DEFAULT_VALUE) && preoffset < offset) {
|
|
195
|
+
this->m_offsetCountIndex--;
|
|
196
|
+
if (this->m_offsetCountIndex <= 0) {
|
|
197
|
+
this->m_offsetCountIndex = 0;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
this->m_preOffset = offset;
|
|
201
|
+
} else {
|
|
202
|
+
offset = 1 - eventArgs[THREE_INDEX].f32;
|
|
203
|
+
static double preoffset = this->m_preOffset;
|
|
204
|
+
if ((preoffset != this->OFFSET_DEFAULT_VALUE) && (preoffset < offset)) {
|
|
205
|
+
this->m_offsetCountIndex--;
|
|
206
|
+
if (this->m_offsetCountIndex <= 0) {
|
|
207
|
+
this->m_offsetCountIndex = 0;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
this->m_preOffset = offset;
|
|
211
|
+
}
|
|
212
|
+
if (this->m_targetIndex == 1 && this->m_offsetCountIndex <= 1) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
facebook::react::RNCViewPagerEventEmitter::OnPageScroll m_onPageScroll = {
|
|
216
|
+
this->m_offsetCountIndex - 1, offset};
|
|
217
|
+
m_swiperNodeDelegate->onPageScroll(m_onPageScroll);
|
|
218
|
+
m_swiperNodeDelegate->sendEventAnimationsPageScroll(m_onPageScroll);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
} else if (((m_swiperNodeDelegate->getClickTap() && this->m_currentIndex < this->m_targetIndex) &&
|
|
222
|
+
(index > selectedIndex)) ||
|
|
223
|
+
(!m_swiperNodeDelegate->getClickTap() && (index > selectedIndex))) {
|
|
224
|
+
if ((this->m_gestureSwipe && !m_swiperNodeDelegate->getClickTap()) ||
|
|
225
|
+
((index - selectedIndex) == 1) && ((this->m_targetIndex - selectedIndex) == 1)) {
|
|
226
|
+
if ((index - selectedIndex) == 1) {
|
|
227
|
+
this->m_offsetCount++;
|
|
228
|
+
if (eventArgs[THREE_INDEX].f32 <= 0) {
|
|
229
|
+
eventArgs[THREE_INDEX].f32 = 0;
|
|
230
|
+
}
|
|
231
|
+
offset = 1 - eventArgs[THREE_INDEX].f32;
|
|
232
|
+
if (offset > 1) {
|
|
233
|
+
offset = 1;
|
|
234
|
+
}
|
|
235
|
+
facebook::react::RNCViewPagerEventEmitter::OnPageScroll m_onPageScroll = {selectedIndex,
|
|
236
|
+
offset};
|
|
237
|
+
m_swiperNodeDelegate->onPageScroll(m_onPageScroll);
|
|
238
|
+
m_swiperNodeDelegate->sendEventAnimationsPageScroll(m_onPageScroll);
|
|
239
|
+
}
|
|
240
|
+
} else {
|
|
241
|
+
if (this->m_firstSwipe) {
|
|
242
|
+
this->m_offsetCountIndex = (this->m_targetIndex - selectedIndex);
|
|
243
|
+
this->m_offsetIndex = this->m_currentIndex;
|
|
244
|
+
this->m_firstSwipe = false;
|
|
245
|
+
}
|
|
246
|
+
this->m_offsetCount++;
|
|
247
|
+
if (this->m_offsetIndex + 1 == index) {
|
|
248
|
+
if (eventArgs[THREE_INDEX].f32 <= 0) {
|
|
249
|
+
offset = -eventArgs[THREE_INDEX].f32;
|
|
250
|
+
static double preoffset = this->m_preOffset;
|
|
251
|
+
if ((preoffset != this->OFFSET_DEFAULT_VALUE) && (preoffset - offset) > 0) {
|
|
252
|
+
this->m_offsetIndex++;
|
|
253
|
+
this->m_offsetCountIndex--;
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
offset = 1 - eventArgs[THREE_INDEX].f32;
|
|
257
|
+
static double preoffset = this->m_preOffset;
|
|
258
|
+
if ((preoffset != this->OFFSET_DEFAULT_VALUE) && (preoffset - offset) > 0) {
|
|
259
|
+
this->m_offsetIndex++;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
this->m_preOffset = offset;
|
|
263
|
+
double offsetIndex = this->m_offsetIndex;
|
|
264
|
+
if (this->m_offsetCountIndex <= 0) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
facebook::react::RNCViewPagerEventEmitter::OnPageScroll m_onPageScroll = {offsetIndex,
|
|
268
|
+
offset};
|
|
269
|
+
m_swiperNodeDelegate->onPageScroll(m_onPageScroll);
|
|
270
|
+
m_swiperNodeDelegate->sendEventAnimationsPageScroll(m_onPageScroll);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
} else if (eventType == ArkUI_NodeEventType::NODE_EVENT_ON_APPEAR) {
|
|
276
|
+
DLOG(INFO) << "onNodeEvent-->NODE_EVENT_ON_APPEAR";
|
|
277
|
+
m_swiperNodeDelegate->onSwiperAppear();
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
SwiperNode &SwiperNode::setIndex(int const &initialPage)
|
|
282
|
+
{
|
|
283
|
+
ArkUI_NumberValue indexValue[] = {{.i32 = initialPage}, {.i32 = 1}};
|
|
284
|
+
ArkUI_AttributeItem indexItem = {indexValue, sizeof(indexValue) / sizeof(ArkUI_NumberValue)};
|
|
285
|
+
maybeThrow(NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_SWIPER_SWIPE_TO_INDEX, &indexItem));
|
|
286
|
+
return *this;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
SwiperNode &SwiperNode::setIndexNoAnimation(int const &initialPage)
|
|
290
|
+
{
|
|
291
|
+
ArkUI_NumberValue indexValue[] = {{.i32 = initialPage}};
|
|
292
|
+
ArkUI_AttributeItem indexItem = {indexValue, sizeof(indexValue) / sizeof(ArkUI_NumberValue)};
|
|
293
|
+
maybeThrow(NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_SWIPER_INDEX, &indexItem));
|
|
294
|
+
return *this;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
SwiperNode &SwiperNode::setVertical(std::string const &orientation)
|
|
298
|
+
{
|
|
299
|
+
if (orientation.empty()) {
|
|
300
|
+
return *this;
|
|
301
|
+
}
|
|
302
|
+
int orientationValue = (orientation == "horizontal") ? 0 : 1;
|
|
303
|
+
ArkUI_NumberValue indexValue[] = {{.i32 = orientationValue}};
|
|
304
|
+
ArkUI_AttributeItem item = {indexValue, sizeof(indexValue) / sizeof(ArkUI_NumberValue)};
|
|
305
|
+
maybeThrow(NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_SWIPER_VERTICAL, &item));
|
|
306
|
+
return *this;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
SwiperNode &SwiperNode::setDirection(std::string const &layoutDirection)
|
|
310
|
+
{
|
|
311
|
+
if (layoutDirection.empty()) {
|
|
312
|
+
return *this;
|
|
313
|
+
}
|
|
314
|
+
int layoutDirectionValue = (layoutDirection == "ltr") ? 0 : 1;
|
|
315
|
+
ArkUI_NumberValue indexValue[] = {{.i32 = layoutDirectionValue}};
|
|
316
|
+
ArkUI_AttributeItem indexItem = {indexValue, sizeof(indexValue) / sizeof(ArkUI_NumberValue)};
|
|
317
|
+
maybeThrow(NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_DIRECTION, &indexItem));
|
|
318
|
+
return *this;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
SwiperNode &SwiperNode::setItemSpace(float const &pageMargin)
|
|
322
|
+
{
|
|
323
|
+
ArkUI_NumberValue indexValue[] = {{.f32 = pageMargin}};
|
|
324
|
+
ArkUI_AttributeItem indexItem = {indexValue, sizeof(indexValue) / sizeof(ArkUI_NumberValue)};
|
|
325
|
+
maybeThrow(NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_SWIPER_ITEM_SPACE, &indexItem));
|
|
326
|
+
return *this;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
SwiperNode &SwiperNode::setCachedCount(int const &offscreenPageLimit)
|
|
330
|
+
{
|
|
331
|
+
ArkUI_NumberValue indexValue[] = {{.i32 = offscreenPageLimit}};
|
|
332
|
+
ArkUI_AttributeItem indexItem = {indexValue, sizeof(indexValue) / sizeof(ArkUI_NumberValue)};
|
|
333
|
+
maybeThrow(NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_SWIPER_CACHED_COUNT, &indexItem));
|
|
334
|
+
return *this;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
SwiperNode &SwiperNode::setDisableSwipe(bool const &disableSwipe)
|
|
338
|
+
{
|
|
339
|
+
int disableSwipeValue = disableSwipe ? 1 : 0;
|
|
340
|
+
ArkUI_NumberValue indexValue[] = {{.i32 = disableSwipeValue}};
|
|
341
|
+
ArkUI_AttributeItem indexItem = {indexValue, sizeof(indexValue) / sizeof(ArkUI_NumberValue)};
|
|
342
|
+
maybeThrow(NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_SWIPER_DISABLE_SWIPE, &indexItem));
|
|
343
|
+
return *this;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
SwiperNode &SwiperNode::setEffectMode(std::string const &effectMode)
|
|
347
|
+
{
|
|
348
|
+
if (effectMode.empty()) {
|
|
349
|
+
return *this;
|
|
350
|
+
}
|
|
351
|
+
if (effectMode == "SPRING") {
|
|
352
|
+
ArkUI_NumberValue indexValue[] = {{.i32 = 0}};
|
|
353
|
+
ArkUI_AttributeItem indexItem = {indexValue, sizeof(indexValue) / sizeof(ArkUI_NumberValue)};
|
|
354
|
+
maybeThrow(
|
|
355
|
+
NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_SWIPER_EDGE_EFFECT_MODE, &indexItem));
|
|
356
|
+
} else if (effectMode == "NONE") {
|
|
357
|
+
ArkUI_NumberValue indexValue[] = {{.i32 = 2}};
|
|
358
|
+
ArkUI_AttributeItem indexItem = {indexValue, sizeof(indexValue) / sizeof(ArkUI_NumberValue)};
|
|
359
|
+
maybeThrow(
|
|
360
|
+
NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_SWIPER_EDGE_EFFECT_MODE, &indexItem));
|
|
361
|
+
} else {
|
|
362
|
+
ArkUI_NumberValue indexValue[] = {{.i32 = 1}};
|
|
363
|
+
ArkUI_AttributeItem indexItem = {indexValue, sizeof(indexValue) / sizeof(ArkUI_NumberValue)};
|
|
364
|
+
maybeThrow(
|
|
365
|
+
NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_SWIPER_EDGE_EFFECT_MODE, &indexItem));
|
|
366
|
+
}
|
|
367
|
+
return *this;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
SwiperNode &SwiperNode::setLoop(bool const &loop)
|
|
371
|
+
{
|
|
372
|
+
int loopValue = loop ? 1 : 0;
|
|
373
|
+
ArkUI_NumberValue indexValue[] = {{.i32 = loopValue}};
|
|
374
|
+
ArkUI_AttributeItem indexItem = {indexValue, sizeof(indexValue) / sizeof(ArkUI_NumberValue)};
|
|
375
|
+
maybeThrow(NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_SWIPER_LOOP, &indexItem));
|
|
376
|
+
return *this;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
SwiperNode &SwiperNode::setIndicator(bool const &indicator)
|
|
380
|
+
{
|
|
381
|
+
int indicatorValue = indicator ? 1 : 0;
|
|
382
|
+
ArkUI_NumberValue indexValue[] = {{.i32 = indicatorValue}};
|
|
383
|
+
ArkUI_AttributeItem indexItem = {indexValue, sizeof(indexValue) / sizeof(ArkUI_NumberValue)};
|
|
384
|
+
maybeThrow(NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_SWIPER_SHOW_INDICATOR, &indexItem));
|
|
385
|
+
return *this;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
SwiperNode &SwiperNode::setDuration(float const &duration)
|
|
389
|
+
{
|
|
390
|
+
ArkUI_NumberValue indexValue[] = {{.f32 = duration}};
|
|
391
|
+
ArkUI_AttributeItem indexItem = {indexValue, sizeof(indexValue) / sizeof(ArkUI_NumberValue)};
|
|
392
|
+
maybeThrow(NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_SWIPER_DURATION, &indexItem));
|
|
393
|
+
return *this;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
SwiperNode &SwiperNode::setCurve(int const &curve)
|
|
397
|
+
{
|
|
398
|
+
ArkUI_NumberValue indexValue[] = {{.i32 = curve}};
|
|
399
|
+
ArkUI_AttributeItem indexItem = {indexValue, sizeof(indexValue) / sizeof(ArkUI_NumberValue)};
|
|
400
|
+
maybeThrow(NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_SWIPER_CURVE, &indexItem));
|
|
401
|
+
return *this;
|
|
402
|
+
}
|
|
403
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
#ifndef SWIPERNODE_H
|
|
25
|
+
#define SWIPERNODE_H
|
|
26
|
+
#pragma once
|
|
27
|
+
|
|
28
|
+
#include "RNOH/arkui/ArkUINode.h"
|
|
29
|
+
#include "generated/react/renderer/components/react_native_pager_view/EventEmitters.h"
|
|
30
|
+
#include <arkui/native_type.h>
|
|
31
|
+
|
|
32
|
+
namespace rnoh {
|
|
33
|
+
|
|
34
|
+
class SwiperNodeDelegate {
|
|
35
|
+
public:
|
|
36
|
+
virtual ~SwiperNodeDelegate() = default;
|
|
37
|
+
virtual void onPageSelected(double pageIndex) {};
|
|
38
|
+
virtual void onPageScroll(
|
|
39
|
+
facebook::react::RNCViewPagerEventEmitter::OnPageScroll pageScroll) {};
|
|
40
|
+
virtual void onPageScrollStateChanged(
|
|
41
|
+
facebook::react::RNCViewPagerEventEmitter::OnPageScrollStateChanged value) {};
|
|
42
|
+
virtual bool getScrollEnabled()
|
|
43
|
+
{
|
|
44
|
+
return true;
|
|
45
|
+
};
|
|
46
|
+
virtual bool getNativeLock()
|
|
47
|
+
{
|
|
48
|
+
return false;
|
|
49
|
+
};
|
|
50
|
+
virtual void setKeyboardDismiss() {};
|
|
51
|
+
virtual void setGestureStatus(bool gestureStatus) {};
|
|
52
|
+
virtual void setClickTap(bool clickTap) {};
|
|
53
|
+
virtual bool getClickTap()
|
|
54
|
+
{
|
|
55
|
+
return false;
|
|
56
|
+
};
|
|
57
|
+
virtual void sendEventAnimationsPageScroll(
|
|
58
|
+
facebook::react::RNCViewPagerEventEmitter::OnPageScroll pageScroll) {};
|
|
59
|
+
virtual void onSwiperAppear() {};
|
|
60
|
+
};
|
|
61
|
+
class SwiperNode : public ArkUINode {
|
|
62
|
+
protected:
|
|
63
|
+
SwiperNodeDelegate *m_swiperNodeDelegate;
|
|
64
|
+
ArkUI_NodeHandle m_stackArkUINodeHandle;
|
|
65
|
+
double m_targetIndex = 0;
|
|
66
|
+
double m_offset = 0;
|
|
67
|
+
double m_currentIndex = 0;
|
|
68
|
+
bool m_crossoverJump = false;
|
|
69
|
+
int m_offsetCount = 0;
|
|
70
|
+
double m_offsetIndex = 0;
|
|
71
|
+
double m_offsetCountIndex = 0;
|
|
72
|
+
const int OFFSET_DEFAULT_VALUE = 3;
|
|
73
|
+
double m_preOffset = OFFSET_DEFAULT_VALUE;
|
|
74
|
+
bool m_firstSwipe = true;
|
|
75
|
+
bool m_gestureSwipe = false;
|
|
76
|
+
bool m_pageSelectNotify = false;
|
|
77
|
+
std::chrono::high_resolution_clock::time_point animationStart;
|
|
78
|
+
std::chrono::high_resolution_clock::time_point animationEnd;
|
|
79
|
+
bool m_interceptSendOffset = false;
|
|
80
|
+
std::map<void*, ArkUI_NodeHandle> m_nodeHandleMap;
|
|
81
|
+
ArkUI_SwiperNestedScrollMode m_swiperNestedScrollMode = ARKUI_SWIPER_NESTED_SRCOLL_SELF_FIRST;
|
|
82
|
+
public:
|
|
83
|
+
SwiperNode();
|
|
84
|
+
|
|
85
|
+
~SwiperNode() override;
|
|
86
|
+
|
|
87
|
+
void setSwiperNodeDelegate(SwiperNodeDelegate *swiperNodeDelegate);
|
|
88
|
+
|
|
89
|
+
void insertChild(ArkUINode &child, std::size_t index);
|
|
90
|
+
|
|
91
|
+
void removeChild(ArkUINode &child);
|
|
92
|
+
|
|
93
|
+
void onNodeEvent(ArkUI_NodeEventType eventType, EventArgs& eventArgs) override;
|
|
94
|
+
|
|
95
|
+
SwiperNode &setIndex(int const &initialPage);
|
|
96
|
+
|
|
97
|
+
SwiperNode &setIndexNoAnimation(int const &initialPage);
|
|
98
|
+
|
|
99
|
+
SwiperNode &setVertical(std::string const &orientation);
|
|
100
|
+
|
|
101
|
+
SwiperNode &setDirection(std::string const &layoutDirection);
|
|
102
|
+
|
|
103
|
+
SwiperNode &setItemSpace(float const &pageMargin);
|
|
104
|
+
|
|
105
|
+
SwiperNode &setCachedCount(int const &offscreenPageLimit);
|
|
106
|
+
|
|
107
|
+
SwiperNode &setDisableSwipe(bool const &disableSwipe);
|
|
108
|
+
|
|
109
|
+
SwiperNode &setEffectMode(std::string const &effectMode);
|
|
110
|
+
|
|
111
|
+
SwiperNode &setLoop(bool const &loop);
|
|
112
|
+
|
|
113
|
+
SwiperNode &setDuration(float const &duration);
|
|
114
|
+
|
|
115
|
+
SwiperNode &setIndicator(bool const &indicator);
|
|
116
|
+
|
|
117
|
+
SwiperNode &setCurve(int const &curve);
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
#endif
|