From fa5802de457c3d056cfa5d821ae8afa67726d6e7 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Thu, 19 Dec 2024 00:10:03 +0800 Subject: [PATCH] update --- .../ScrollView/RCTScrollViewComponentView.mm | 26 +++++++++---------- .../components/scrollview/ScrollEvent.h | 3 +++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm index 2c6dd96a16e3d7..d029337fb0d40f 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm @@ -530,8 +530,9 @@ - (BOOL)_shouldDisableScrollInteraction return NO; } -- (void)_setScrollViewMetrics:(ScrollViewEventEmitter::Metrics &)metrics +- (ScrollViewEventEmitter::Metrics)_scrollViewMetrics { + auto metrics = ScrollViewEventEmitter::Metrics{}; metrics.contentSize = RCTSizeFromCGSize(_scrollView.contentSize); metrics.contentOffset = RCTPointFromCGPoint(_scrollView.contentOffset); metrics.contentInset = RCTEdgeInsetsFromUIEdgeInsets(_scrollView.contentInset); @@ -542,13 +543,18 @@ - (void)_setScrollViewMetrics:(ScrollViewEventEmitter::Metrics &)metrics if (_layoutMetrics.layoutDirection == LayoutDirection::RightToLeft) { metrics.contentOffset.x = metrics.contentSize.width - metrics.containerSize.width - metrics.contentOffset.x; } + + return metrics; } -- (ScrollViewEventEmitter::Metrics)_scrollViewMetrics +- (ScrollViewEventEmitter::EndDragMetrics)_scrollViewMetricsWithVelocity:(CGPoint)velocity + andTargetContentOffset:(CGPoint)targetContentOffset { - auto metrics = ScrollViewEventEmitter::Metrics{}; - [self _setScrollViewMetrics:metrics]; - + ScrollViewEventEmitter::EndDragMetrics metrics = [self _scrollViewMetrics]; + metrics.targetContentOffset.x = targetContentOffset.x; + metrics.targetContentOffset.y = targetContentOffset.y; + metrics.velocity.x = velocity.x; + metrics.velocity.y = velocity.y; return metrics; } @@ -612,12 +618,7 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView return; } - auto metrics = ScrollViewEventEmitter::EndDragMetrics{}; - [self _setScrollViewMetrics:metrics]; - metrics.targetContentOffset.x = targetContentOffset->x; - metrics.targetContentOffset.y = targetContentOffset->y; - metrics.velocity.x = velocity.x; - metrics.velocity.y = velocity.y; + auto metrics = [self _scrollViewMetricsWithVelocity:velocity andTargetContentOffset:*targetContentOffset]; static_cast(*_eventEmitter).onScrollEndDrag(metrics); } @@ -786,8 +787,7 @@ - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UI return; } - auto metrics = ScrollViewEventEmitter::EndDragMetrics{}; - [self _setScrollViewMetrics:metrics]; + auto metrics = [self _scrollViewMetricsWithVelocity:{} andTargetContentOffset:{}]; static_cast(*_eventEmitter).onScrollEndDrag(metrics); [self _updateStateWithContentOffset]; diff --git a/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollEvent.h b/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollEvent.h index 5b41c0cc4332d1..cb55148cf5d888 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollEvent.h +++ b/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollEvent.h @@ -43,6 +43,9 @@ struct ScrollEndDragEvent : public ScrollEvent { ScrollEndDragEvent() = default; + ScrollEndDragEvent(const ScrollEvent& scrollEvent) + : ScrollEvent(scrollEvent), targetContentOffset({}), velocity({}) {} + folly::dynamic asDynamic() const; /*