Skip to content

Commit

Permalink
fix(ios): on tab selection scroll when rtl enabled (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebasg0 authored Oct 4, 2022
1 parent bfad9a3 commit ce17576
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ios/ReactNativePageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,20 @@ - (void)goTo:(NSInteger)index animated:(BOOL)animated {
return;
}

BOOL isForward = (index > self.currentIndex && [self isLtrLayout]) || (index < self.currentIndex && ![self isLtrLayout]);
BOOL isRTL = ![self isLtrLayout];

BOOL isForward = (index > self.currentIndex && !isRTL) || (index < self.currentIndex && isRTL);


UIPageViewControllerNavigationDirection direction = isForward ? UIPageViewControllerNavigationDirectionForward : UIPageViewControllerNavigationDirectionReverse;

self.reactPageIndicatorView.numberOfPages = numberOfPages;
self.reactPageIndicatorView.currentPage = index;
long diff = labs(index - _currentIndex);

if (isForward && diff > 0) {
BOOL shouldGoForward = isRTL ? !isForward : isForward;

if (shouldGoForward && diff > 0) {
for (NSInteger i=_currentIndex; i<=index; i++) {
if (i == _currentIndex) {
continue;
Expand All @@ -263,7 +269,7 @@ - (void)goTo:(NSInteger)index animated:(BOOL)animated {
}
}

if (!isForward && diff > 0) {
if (!shouldGoForward && diff > 0) {
for (NSInteger i=_currentIndex; i>=index; i--) {
// Prevent removal of one or many pages at a time
if (i == _currentIndex || i >= numberOfPages) {
Expand Down

0 comments on commit ce17576

Please sign in to comment.