From 65b7680720435c0d864df9c121c151b60bee08ad Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Wed, 16 Aug 2023 16:35:52 -0700 Subject: [PATCH] Fix bad comparison in RCTScrollViewComponentView RTL (#39030) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39030 D29164056 fixed `scrollTo` coordinate space in RTL, but D38499666 regressed it by adding a comparison before the RTL conversion happens. This makes `scrollTo` no-op if we are scrolling from the beginning to the end of the list, since the end of the list is `x: 0` in cartesian coordinates, and the start of the list is `x: 0` in flow-relative coordinates. Do coordinate conversion before the early exit check. Changelog: [iOS][Fixed] - Fix bad comparison in RCTScrollViewComponentView RTL Reviewed By: rshest Differential Revision: D48378414 fbshipit-source-id: 14b0b9bb3b22828c290bbbc93b907d8c0e264995 --- .../ScrollView/RCTScrollViewComponentView.mm | 10 +++++----- 1 file changed, 5 insertions(+), 5 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 5c3f18d1c16..b8894132b77 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm @@ -675,17 +675,17 @@ static void RCTSendScrollEventForNativeAnimations_DEPRECATED(UIScrollView *scrol - (void)scrollToOffset:(CGPoint)offset animated:(BOOL)animated { + if (_layoutMetrics.layoutDirection == LayoutDirection::RightToLeft) { + // Adjusting offset.x in right to left layout direction. + offset.x = self.contentSize.width - _scrollView.frame.size.width - offset.x; + } + if (CGPointEqualToPoint(_scrollView.contentOffset, offset)) { return; } [self _forceDispatchNextScrollEvent]; - if (_layoutMetrics.layoutDirection == LayoutDirection::RightToLeft) { - // Adjusting offset.x in right to left layout direction. - offset.x = self.contentSize.width - _scrollView.frame.size.width - offset.x; - } - [_scrollView setContentOffset:offset animated:animated]; if (!animated) {