Skip to content

Commit a12e8fd

Browse files
authored
fix:修复allLoaded属性设置异常问题 (#15)
1 parent b6cb56d commit a12e8fd

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

harmony/spring_scrollview/src/main/cpp/SpringScrollViewEvent.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ class SpringScrollViewEvent : public EventBus::Event {
101101

102102
bool getEventMomentumScrolling() { return this->eventMomentumScrolling; }
103103

104+
void setEventRecordSwipeY(float eventRecordSwipeY) {
105+
this->eventRecordSwipeY = eventRecordSwipeY;
106+
}
107+
108+
float getEventRecordSwipeY() { return this->eventRecordSwipeY; }
109+
104110
protected:
105111
double animationValue;
106112
std::string eventType;
@@ -117,5 +123,6 @@ class SpringScrollViewEvent : public EventBus::Event {
117123
Types::Point eventBeginPoint;
118124
Types::EdgeInsets eventContentInsets;
119125
bool eventMomentumScrolling;
126+
float eventRecordSwipeY;
120127
};
121128
#endif // HARMONY_EXAMPLEEVENT_H

harmony/spring_scrollview/src/main/cpp/SpringScrollViewNode.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,11 @@ void SpringScrollViewNode::onDown(ArkUI_GestureEvent *evt) {
165165
auto recordEvent =
166166
std::static_pointer_cast<SpringScrollViewEvent>(EventBus::EventBus::getInstance()->getEvent());
167167
this->contentOffset = recordEvent->getEventContentOffset();
168+
this->recordSwipeY = recordEvent->getEventRecordSwipeY();
168169
refreshStatus = "waiting";
169-
loadingStatus = "waiting";
170+
if (recordEvent->getLoadingStatus() != "allLoaded") {
171+
loadingStatus = "waiting";
172+
}
170173
float x = OH_ArkUI_PanGesture_GetOffsetX(evt);
171174
float y = OH_ArkUI_PanGesture_GetOffsetY(evt);
172175
beginPoint.x = lastPoint.x = x;
@@ -196,6 +199,7 @@ void SpringScrollViewNode::onDown(ArkUI_GestureEvent *evt) {
196199
this->recordEventModel->setEventContentInsets(contentInsets);
197200
this->recordEventModel->setEventBeginPoint(beginPoint);
198201
this->recordEventModel->setEventLastPoint(lastPoint);
202+
this->recordEventModel->setEventRecordSwipeY(this->recordSwipeY);
199203
auto baseEvent = std::static_pointer_cast<EventBus::Event>(this->recordEventModel);
200204
EventBus::EventBus::getInstance()->setEvent(baseEvent);
201205
}
@@ -562,6 +566,7 @@ void SpringScrollViewNode ::setContentOffset(float x, float y) {
562566
this->recordEventModel->setLoadingStatus(loadingStatus);
563567
this->recordEventModel->setEventBounces(bounces);
564568
this->recordEventModel->setEventContentOffset(contentOffset);
569+
this->recordEventModel->setEventRecordSwipeY(contentOffset.y);
565570
auto baseEvent = std::static_pointer_cast<EventBus::Event>(this->recordEventModel);
566571
EventBus::EventBus::getInstance()->setEvent(baseEvent);
567572
std::array<ArkUI_NumberValue, 3> translateValue = {
@@ -583,6 +588,21 @@ void SpringScrollViewNode ::setAllLoaded(bool allLoaded) {
583588
if (allLoaded) {
584589
contentInsets.bottom = 0;
585590
}
591+
this->recordEventModel = std::make_shared<SpringScrollViewEvent>(5);
592+
this->recordEventModel->setEventMomentumScrolling(false);
593+
this->recordEventModel->setNodeHandle(m_stackArkUINodeHandle);
594+
this->recordEventModel->setEventSpringScrollViewNodeDelegate(this->m_scrollNodeDelegate);
595+
this->recordEventModel->setRefreshStatus(refreshStatus);
596+
this->recordEventModel->setLoadingStatus(loadingStatus);
597+
this->recordEventModel->setEventBounces(bounces);
598+
this->recordEventModel->setEventContentOffset(contentOffset);
599+
this->recordEventModel->setEventSize(size);
600+
this->recordEventModel->setEventContentSize(contentSize);
601+
this->recordEventModel->setEventContentInsets(contentInsets);
602+
this->recordEventModel->setEventBeginPoint(beginPoint);
603+
this->recordEventModel->setEventLastPoint(lastPoint);
604+
auto baseEvent = std::static_pointer_cast<EventBus::Event>(this->recordEventModel);
605+
EventBus::EventBus::getInstance()->setEvent(baseEvent);
586606
}
587607

588608
void SpringScrollViewNode ::setDecelerationRate(float rate) { decelerationRate = rate; }
@@ -623,6 +643,7 @@ void SpringScrollViewNode ::endLoading() {
623643
this->recordEventModel->setEventContentInsets(contentInsets);
624644
this->recordEventModel->setEventBeginPoint(beginPoint);
625645
this->recordEventModel->setEventLastPoint(lastPoint);
646+
this->recordEventModel->setEventRecordSwipeY(contentOffset.y);
626647
auto baseEvent = std::static_pointer_cast<EventBus::Event>(this->recordEventModel);
627648
EventBus::EventBus::getInstance()->setEvent(baseEvent);
628649
this->m_scrollNodeDelegate->callArkTSAnimationCancel();
@@ -660,9 +681,10 @@ void SpringScrollViewNode ::endRefresh() {
660681
void SpringScrollViewNode ::scrollTo(float x, float y, bool animated) {
661682
this->setRecordEventModel();
662683
if(x == BEGIN_REFRESH){
663-
m_scrollNodeDelegate->callArkTSScrollYStart(0, y, 500);
664-
this->beginRefresh();
665-
return;
684+
if (!this->bounces) return;
685+
m_scrollNodeDelegate->callArkTSScrollYStart(0, y, 500);
686+
this->beginRefresh();
687+
return;
666688
}
667689
if( x == DISMINATE_KEYBOARD_SHOW_HIDE && this->recordKeyBoardShow) return;
668690
if(y == DISMINATE_KEYBOARD_SHOW_HIDE){
@@ -702,6 +724,7 @@ void SpringScrollViewNode::onEvent(std::shared_ptr<SpringScrollViewEvent> &event
702724
this->contentInsets = recordEvent->getEventContentInsets();
703725
this->size = recordEvent->getEventSize();
704726
this->momentumScrolling = recordEvent->getEventMomentumScrolling();
727+
this->recordSwipeY = recordEvent->getEventRecordSwipeY();
705728
DLOG(INFO) << "SpringScrollViewNode onEvent " << event->getMessageType() << " getEventType "
706729
<< event->getEventType();
707730

0 commit comments

Comments
 (0)