@@ -34,6 +34,8 @@ SpringScrollViewNode::SpringScrollViewNode()
34
34
: ArkUINode(NativeNodeApi::getInstance()->createNode (ArkUI_NodeType::ARKUI_NODE_STACK)),
35
35
m_stackArkUINodeHandle(nullptr ) {}
36
36
SpringScrollViewNode::~SpringScrollViewNode () {
37
+ this ->isDestory = true ;
38
+ m_scrollNodeDelegate->callArkTSAnimationCancel ();
37
39
this ->isInitialContentOffset = false ;
38
40
this ->recordEventModel = std::make_shared<SpringScrollViewEvent>(5 );
39
41
this ->recordEventModel ->setRefreshStatus (" waiting" );
@@ -112,27 +114,30 @@ void SpringScrollViewNode::registerPanGesture() {
112
114
float y = OH_ArkUI_PanGesture_GetOffsetY (event);
113
115
114
116
if (actionType == GESTURE_EVENT_ACTION_ACCEPT) {
115
- DLOG (INFO) << " SpringScrollViewNode GESTURE_EVENT_ACTION_ACCEPT x:" << x << " y:" << y;
116
- springScrollViewNode->downX = x;
117
- springScrollViewNode->downY = y;
118
- springScrollViewNode->onDown (event);
117
+ DLOG (INFO) << " SpringScrollViewNode GESTURE_EVENT_ACTION_ACCEPT x:" << x << " y:" << y;
118
+ springScrollViewNode->downX = x;
119
+ springScrollViewNode->downY = y;
120
+ springScrollViewNode->onDown (event);
119
121
} else if (actionType == GESTURE_EVENT_ACTION_UPDATE) {
120
- DLOG (INFO) << " SpringScrollViewNode GESTURE_EVENT_ACTION_UPDATE x:" << x << " y:" << y;
121
- springScrollViewNode->moveX = x;
122
- springScrollViewNode->moveY = y;
123
- if ((springScrollViewNode->moveX - springScrollViewNode->downX > 1.5 ) ||
124
- (springScrollViewNode->moveX - springScrollViewNode->downX < -1.5 )) {
125
- springScrollViewNode->m_scrollNodeDelegate ->setSwiperStatus (true );
126
- }
127
- if ((springScrollViewNode->moveY - springScrollViewNode->downY > 1.5 ) ||
128
- (springScrollViewNode->moveY - springScrollViewNode->downY < -1.5 )) {
129
- springScrollViewNode->m_scrollNodeDelegate ->setSwiperStatus (true );
130
- }
131
- springScrollViewNode->onMove (event);
122
+ DLOG (INFO) << " SpringScrollViewNode GESTURE_EVENT_ACTION_UPDATE x:" << x << " y:" << y;
123
+ springScrollViewNode->moveX = x;
124
+ springScrollViewNode->moveY = y;
125
+ if ((springScrollViewNode->moveX - springScrollViewNode->downX > 1.5 ) ||
126
+ (springScrollViewNode->moveX - springScrollViewNode->downX < -1.5 )) {
127
+ springScrollViewNode->isMove = true ;
128
+ springScrollViewNode->m_scrollNodeDelegate ->setSwiperStatus (true );
129
+ }
130
+ if ((springScrollViewNode->moveY - springScrollViewNode->downY > 1.5 ) ||
131
+ (springScrollViewNode->moveY - springScrollViewNode->downY < -1.5 )) {
132
+ springScrollViewNode->isMove = true ;
133
+ springScrollViewNode->m_scrollNodeDelegate ->setSwiperStatus (true );
134
+ }
135
+ springScrollViewNode->onMove (event);
132
136
} else if (actionType == GESTURE_EVENT_ACTION_END) {
133
- springScrollViewNode->m_scrollNodeDelegate ->setSwiperStatus (false );
134
- DLOG (INFO) << " SpringScrollViewNode onUp GESTURE_EVENT_ACTION_END" ;
135
- springScrollViewNode->onUp (event);
137
+ springScrollViewNode->m_scrollNodeDelegate ->setSwiperStatus (false );
138
+ DLOG (INFO) << " SpringScrollViewNode onUp GESTURE_EVENT_ACTION_END" ;
139
+ springScrollViewNode->onUp (event);
140
+ springScrollViewNode->isMove = false ;
136
141
}
137
142
};
138
143
this ->panGestureApi ->setGestureEventTarget (
@@ -142,8 +147,8 @@ void SpringScrollViewNode::registerPanGesture() {
142
147
}
143
148
144
149
void SpringScrollViewNode::onMove (ArkUI_GestureEvent *evt) {
145
- if (!this ->scrollEnabled ) {
146
- return ;
150
+ if (!this ->scrollEnabled || !isMove ) {
151
+ return ;
147
152
}
148
153
float x = OH_ArkUI_PanGesture_GetOffsetX (evt);
149
154
float y = OH_ArkUI_PanGesture_GetOffsetY (evt);
@@ -153,6 +158,9 @@ void SpringScrollViewNode::onMove(ArkUI_GestureEvent *evt) {
153
158
}
154
159
155
160
void SpringScrollViewNode::onDown (ArkUI_GestureEvent *evt) {
161
+ auto recordEvent =
162
+ std::static_pointer_cast<SpringScrollViewEvent>(EventBus::EventBus::getInstance ()->getEvent ());
163
+ this ->contentOffset = recordEvent->getEventContentOffset ();
156
164
refreshStatus = " waiting" ;
157
165
loadingStatus = " waiting" ;
158
166
float x = OH_ArkUI_PanGesture_GetOffsetX (evt);
@@ -191,6 +199,7 @@ void SpringScrollViewNode::onDown(ArkUI_GestureEvent *evt) {
191
199
}
192
200
193
201
void SpringScrollViewNode::onUp (ArkUI_GestureEvent *evt) {
202
+ if (!isMove) return ;
194
203
this ->onMove (evt);
195
204
dragging = false ;
196
205
float vy = 0.020 ;
@@ -538,6 +547,7 @@ float SpringScrollViewNode::getXDampingCoefficient() {
538
547
}
539
548
540
549
void SpringScrollViewNode ::setContentOffset (float x, float y) {
550
+ if (this ->isDestory ) return ;
541
551
this ->contentOffset .x = x;
542
552
this ->contentOffset .y = y;
543
553
this ->recordEventModel = std::make_shared<SpringScrollViewEvent>(5 );
@@ -550,13 +560,13 @@ void SpringScrollViewNode ::setContentOffset(float x, float y) {
550
560
auto baseEvent = std::static_pointer_cast<EventBus::Event>(this ->recordEventModel );
551
561
EventBus::EventBus::getInstance ()->setEvent (baseEvent);
552
562
std::array<ArkUI_NumberValue, 3 > translateValue = {
553
- ArkUI_NumberValue{.f32 = -this ->contentOffset .x }, {.f32 = -this ->contentOffset .y }, {.f32 = 0 }};
554
- ArkUI_AttributeItem translateItem = {translateValue.data (), translateValue.size ()};
563
+ ArkUI_NumberValue{.f32 = -this ->contentOffset .x }, {.f32 = -this ->contentOffset .y }, {.f32 = 0 }};
564
+ ArkUI_AttributeItem translateItem = {translateValue.data (), translateValue.size ()};
555
565
NativeNodeApi::getInstance ()->setAttribute (m_stackArkUINodeHandle, NODE_TRANSLATE, &translateItem);
556
566
facebook::react::RNCSpringScrollViewEventEmitter::OnScroll onScroll = {
557
567
{contentOffset.x / 2 , contentOffset.y / 2 }, refreshStatus, loadingStatus};
558
568
m_scrollNodeDelegate->onScroll (onScroll);
559
- DLOG (INFO) << " SpringScrollViewNode registerPanGesture setContentOffset loadingStatus:" << loadingStatus
569
+ DLOG (INFO) << " SpringScrollViewNode setContentOffset loadingStatus:" << loadingStatus
560
570
<< " refreshStatus:" << refreshStatus << " contentOffset.y " << contentOffset.y << " contentOffset.x "
561
571
<< contentOffset.x ;
562
572
}
@@ -642,21 +652,34 @@ void SpringScrollViewNode ::endRefresh() {
642
652
contentOffset.x = 0 ;
643
653
}
644
654
645
- void SpringScrollViewNode ::scrollTo (float x, float y, bool animated) {
646
- DLOG (INFO) << " SpringScrollViewNode scrollTo x:" << x << " y:" << y << " animated:" << animated
647
- << " contentOffset.x:" << contentOffset.x ;
648
- cancelAllAnimations ();
649
- if (!animated) {
650
- moveToOffset (x, y);
651
- return ;
652
- }
653
- m_scrollNodeDelegate->callArkTSScrollYStart (contentOffset.y , y, 500 );
654
- if (x != contentOffset.x ) {
655
- m_scrollNodeDelegate->callArkTSScrollXStart (contentOffset.x , x, 500 );
655
+ void SpringScrollViewNode ::scrollTo (float x, float y, bool animated) {
656
+ if ( x == DISMINATE_KEYBOARD_SHOW_HIDE && this ->recordKeyBoardShow ) return ;
657
+ if (y == DISMINATE_KEYBOARD_SHOW_HIDE){
658
+ this ->recordKeyBoardShow = false ;
659
+ y = this ->recordKeyBoardPositioY ;
660
+ this ->keyboardHideLastTime = std::chrono::high_resolution_clock::now ();
661
+ }
662
+ else if (x == DISMINATE_KEYBOARD_SHOW_HIDE){
663
+ auto keyboardShowCurrentTime = std::chrono::high_resolution_clock::now ();
664
+ std::chrono::duration<double > duration = keyboardShowCurrentTime - this ->keyboardHideLastTime ;
665
+ this ->recordKeyBoardShow = true ;
666
+ if (duration.count () > 1.5 ) {
667
+ this ->recordKeyBoardPositioY = contentOffset.y ;
668
+ }
669
+ }
670
+ cancelAllAnimations ();
671
+ if (!animated) {
672
+ moveToOffset (x, y);
673
+ return ;
674
+ }
675
+ m_scrollNodeDelegate->callArkTSScrollYStart (contentOffset.y , y, 500 );
676
+ if (x != contentOffset.x && x!=DISMINATE_KEYBOARD_SHOW_HIDE) {
677
+ m_scrollNodeDelegate->callArkTSScrollXStart (contentOffset.x , x, 500 );
678
+ }
656
679
}
657
- }
658
680
659
681
void SpringScrollViewNode::onEvent (std::shared_ptr<SpringScrollViewEvent> &event) {
682
+ if (this ->isDestory ) return ;
660
683
auto recordEvent = std::static_pointer_cast<SpringScrollViewEvent>(EventBus::EventBus::getInstance ()->getEvent ());
661
684
this ->m_stackArkUINodeHandle = recordEvent->getNodeHandle ();
662
685
this ->m_scrollNodeDelegate = (SpringScrollViewNodeDelegate *)recordEvent->getEventSpringScrollViewNodeDelegate ();
0 commit comments