Skip to content

Commit ce17576

Browse files
authored
fix(ios): on tab selection scroll when rtl enabled (#613)
1 parent bfad9a3 commit ce17576

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

ios/ReactNativePageView.m

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,20 @@ - (void)goTo:(NSInteger)index animated:(BOOL)animated {
247247
return;
248248
}
249249

250-
BOOL isForward = (index > self.currentIndex && [self isLtrLayout]) || (index < self.currentIndex && ![self isLtrLayout]);
250+
BOOL isRTL = ![self isLtrLayout];
251+
252+
BOOL isForward = (index > self.currentIndex && !isRTL) || (index < self.currentIndex && isRTL);
253+
254+
251255
UIPageViewControllerNavigationDirection direction = isForward ? UIPageViewControllerNavigationDirectionForward : UIPageViewControllerNavigationDirectionReverse;
252256

253257
self.reactPageIndicatorView.numberOfPages = numberOfPages;
254258
self.reactPageIndicatorView.currentPage = index;
255259
long diff = labs(index - _currentIndex);
256260

257-
if (isForward && diff > 0) {
261+
BOOL shouldGoForward = isRTL ? !isForward : isForward;
262+
263+
if (shouldGoForward && diff > 0) {
258264
for (NSInteger i=_currentIndex; i<=index; i++) {
259265
if (i == _currentIndex) {
260266
continue;
@@ -263,7 +269,7 @@ - (void)goTo:(NSInteger)index animated:(BOOL)animated {
263269
}
264270
}
265271

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

0 commit comments

Comments
 (0)