@@ -260,11 +260,9 @@ - (void)goTo:(NSInteger)index animated:(BOOL)animated {
260
260
return ;
261
261
}
262
262
263
- BOOL isRTL = ![self isLtrLayout ];
264
-
265
- BOOL isForward = (index > self.currentIndex && !isRTL) || (index < self.currentIndex && isRTL);
263
+ BOOL isHorizontalRtl = [self isHorizontalRtlLayout ];
264
+ BOOL isForward = isHorizontalRtl ? index < self.currentIndex : index > self.currentIndex ;
266
265
267
-
268
266
UIPageViewControllerNavigationDirection direction = isForward ? UIPageViewControllerNavigationDirectionForward : UIPageViewControllerNavigationDirectionReverse;
269
267
270
268
long diff = labs (index - _currentIndex);
@@ -353,13 +351,13 @@ - (void)pageViewController:(UIPageViewController *)pageViewController
353
351
354
352
- (UIViewController *)pageViewController : (UIPageViewController *)pageViewController
355
353
viewControllerAfterViewController : (UIViewController *)viewController {
356
- UIPageViewControllerNavigationDirection direction = [self isLtrLayout ] ? UIPageViewControllerNavigationDirectionForward : UIPageViewControllerNavigationDirectionReverse;
354
+ UIPageViewControllerNavigationDirection direction = ! [self isHorizontalRtlLayout ] ? UIPageViewControllerNavigationDirectionForward : UIPageViewControllerNavigationDirectionReverse;
357
355
return [self nextControllerForController: viewController inDirection: direction];
358
356
}
359
357
360
358
- (UIViewController *)pageViewController : (UIPageViewController *)pageViewController
361
359
viewControllerBeforeViewController : (UIViewController *)viewController {
362
- UIPageViewControllerNavigationDirection direction = [self isLtrLayout ] ? UIPageViewControllerNavigationDirectionReverse : UIPageViewControllerNavigationDirectionForward;
360
+ UIPageViewControllerNavigationDirection direction = ! [self isHorizontalRtlLayout ] ? UIPageViewControllerNavigationDirectionReverse : UIPageViewControllerNavigationDirectionForward;
363
361
return [self nextControllerForController: viewController inDirection: direction];
364
362
}
365
363
@@ -382,8 +380,8 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi
382
380
383
381
if (!_overdrag) {
384
382
NSInteger maxIndex = self.reactSubviews .count - 1 ;
385
- BOOL isFirstPage = [self isLtrLayout ] ? _currentIndex == 0 : _currentIndex == maxIndex;
386
- BOOL isLastPage = [self isLtrLayout ] ? _currentIndex == maxIndex : _currentIndex == 0 ;
383
+ BOOL isFirstPage = ! [self isHorizontalRtlLayout ] ? _currentIndex == 0 : _currentIndex == maxIndex;
384
+ BOOL isLastPage = ! [self isHorizontalRtlLayout ] ? _currentIndex == maxIndex : _currentIndex == 0 ;
387
385
CGFloat contentOffset =[self isHorizontal ] ? scrollView.contentOffset .x : scrollView.contentOffset .y ;
388
386
CGFloat topBound = [self isHorizontal ] ? scrollView.bounds .size .width : scrollView.bounds .size .height ;
389
387
@@ -423,7 +421,8 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
423
421
424
422
NSInteger position = self.currentIndex ;
425
423
426
- BOOL isAnimatingBackwards = ([self isLtrLayout ] && offset<0 ) || (![self isLtrLayout ] && offset > 0 .05f );
424
+ BOOL isHorizontalRtl = [self isHorizontalRtlLayout ];
425
+ BOOL isAnimatingBackwards = isHorizontalRtl ? offset > 0 .05f : offset < 0 ;
427
426
428
427
if (scrollView.isDragging ) {
429
428
_destinationIndex = isAnimatingBackwards ? _currentIndex - 1 : _currentIndex + 1 ;
@@ -436,8 +435,8 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
436
435
437
436
if (!_overdrag) {
438
437
NSInteger maxIndex = self.reactSubviews .count - 1 ;
439
- NSInteger firstPageIndex = [ self isLtrLayout ] ? 0 : maxIndex;
440
- NSInteger lastPageIndex = [ self isLtrLayout ] ? maxIndex : 0 ;
438
+ NSInteger firstPageIndex = !isHorizontalRtl ? 0 : maxIndex;
439
+ NSInteger lastPageIndex = !isHorizontalRtl ? maxIndex : 0 ;
441
440
BOOL isFirstPage = _currentIndex == firstPageIndex;
442
441
BOOL isLastPage = _currentIndex == lastPageIndex;
443
442
CGFloat contentOffset =[self isHorizontal ] ? scrollView.contentOffset .x : scrollView.contentOffset .y ;
@@ -500,4 +499,5 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecogni
500
499
- (BOOL )isLtrLayout {
501
500
return [_layoutDirection isEqualToString: @" ltr" ];
502
501
}
502
+
503
503
@end
0 commit comments