diff --git a/ios/LEGACY/Fabric/LEGACY_RNCPagerViewComponentView.mm b/ios/LEGACY/Fabric/LEGACY_RNCPagerViewComponentView.mm index 69093b08..3b21b8be 100644 --- a/ios/LEGACY/Fabric/LEGACY_RNCPagerViewComponentView.mm +++ b/ios/LEGACY/Fabric/LEGACY_RNCPagerViewComponentView.mm @@ -309,6 +309,10 @@ - (BOOL)isLtrLayout { return [_layoutDirection isEqualToString: @"ltr"]; } +- (BOOL)isHorizontalRtlLayout { + return self.isHorizontal && ![self isLtrLayout]; +} + - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGPoint point = scrollView.contentOffset; @@ -328,6 +332,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView { NSInteger position = self.currentIndex; + BOOL isHorizontalRtl = [self isHorizontalRtlLayout]; BOOL isAnimatingBackwards = offset<0; if (scrollView.isDragging) { @@ -341,8 +346,8 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (!_overdrag) { NSInteger maxIndex = _nativeChildrenViewControllers.count - 1; - NSInteger firstPageIndex = [self isLtrLayout] ? 0 : maxIndex; - NSInteger lastPageIndex = [self isLtrLayout] ? maxIndex : 0; + NSInteger firstPageIndex = !isHorizontalRtl ? 0 : maxIndex; + NSInteger lastPageIndex = !isHorizontalRtl ? maxIndex : 0; BOOL isFirstPage = _currentIndex == firstPageIndex; BOOL isLastPage = _currentIndex == lastPageIndex; CGFloat contentOffset =[self isHorizontal] ? scrollView.contentOffset.x : scrollView.contentOffset.y; diff --git a/ios/LEGACY/LEGACY_RNCPagerView.m b/ios/LEGACY/LEGACY_RNCPagerView.m index 5f6c5354..befa9335 100644 --- a/ios/LEGACY/LEGACY_RNCPagerView.m +++ b/ios/LEGACY/LEGACY_RNCPagerView.m @@ -260,11 +260,9 @@ - (void)goTo:(NSInteger)index animated:(BOOL)animated { return; } - BOOL isRTL = ![self isLtrLayout]; - - BOOL isForward = (index > self.currentIndex && !isRTL) || (index < self.currentIndex && isRTL); + BOOL isHorizontalRtl = [self isHorizontalRtlLayout]; + BOOL isForward = isHorizontalRtl ? index < self.currentIndex : index > self.currentIndex; - UIPageViewControllerNavigationDirection direction = isForward ? UIPageViewControllerNavigationDirectionForward : UIPageViewControllerNavigationDirectionReverse; long diff = labs(index - _currentIndex); @@ -353,13 +351,13 @@ - (void)pageViewController:(UIPageViewController *)pageViewController - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController { - UIPageViewControllerNavigationDirection direction = [self isLtrLayout] ? UIPageViewControllerNavigationDirectionForward : UIPageViewControllerNavigationDirectionReverse; + UIPageViewControllerNavigationDirection direction = ![self isHorizontalRtlLayout] ? UIPageViewControllerNavigationDirectionForward : UIPageViewControllerNavigationDirectionReverse; return [self nextControllerForController:viewController inDirection:direction]; } - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController { - UIPageViewControllerNavigationDirection direction = [self isLtrLayout] ? UIPageViewControllerNavigationDirectionReverse : UIPageViewControllerNavigationDirectionForward; + UIPageViewControllerNavigationDirection direction = ![self isHorizontalRtlLayout] ? UIPageViewControllerNavigationDirectionReverse : UIPageViewControllerNavigationDirectionForward; return [self nextControllerForController:viewController inDirection:direction]; } @@ -382,8 +380,8 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi if (!_overdrag) { NSInteger maxIndex = self.reactSubviews.count - 1; - BOOL isFirstPage = [self isLtrLayout] ? _currentIndex == 0 : _currentIndex == maxIndex; - BOOL isLastPage = [self isLtrLayout] ? _currentIndex == maxIndex : _currentIndex == 0; + BOOL isFirstPage = ![self isHorizontalRtlLayout] ? _currentIndex == 0 : _currentIndex == maxIndex; + BOOL isLastPage = ![self isHorizontalRtlLayout] ? _currentIndex == maxIndex : _currentIndex == 0; CGFloat contentOffset =[self isHorizontal] ? scrollView.contentOffset.x : scrollView.contentOffset.y; CGFloat topBound = [self isHorizontal] ? scrollView.bounds.size.width : scrollView.bounds.size.height; @@ -423,7 +421,8 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView { NSInteger position = self.currentIndex; - BOOL isAnimatingBackwards = ([self isLtrLayout] && offset<0) || (![self isLtrLayout] && offset > 0.05f); + BOOL isHorizontalRtl = [self isHorizontalRtlLayout]; + BOOL isAnimatingBackwards = isHorizontalRtl ? offset > 0.05f : offset < 0; if (scrollView.isDragging) { _destinationIndex = isAnimatingBackwards ? _currentIndex - 1 : _currentIndex + 1; @@ -436,8 +435,8 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (!_overdrag) { NSInteger maxIndex = self.reactSubviews.count - 1; - NSInteger firstPageIndex = [self isLtrLayout] ? 0 : maxIndex; - NSInteger lastPageIndex = [self isLtrLayout] ? maxIndex : 0; + NSInteger firstPageIndex = !isHorizontalRtl ? 0 : maxIndex; + NSInteger lastPageIndex = !isHorizontalRtl ? maxIndex : 0; BOOL isFirstPage = _currentIndex == firstPageIndex; BOOL isLastPage = _currentIndex == lastPageIndex; CGFloat contentOffset =[self isHorizontal] ? scrollView.contentOffset.x : scrollView.contentOffset.y; @@ -500,4 +499,8 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecogni - (BOOL)isLtrLayout { return [_layoutDirection isEqualToString:@"ltr"]; } + +- (BOOL)isHorizontalRtlLayout { + return self.isHorizontal && ![self isLtrLayout]; +} @end