Skip to content

Commit 223560f

Browse files
authored
fix: deducing rtl device setup (#402)
1 parent d7e95d3 commit 223560f

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

android/src/main/java/com/reactnativepagerview/PagerViewViewManager.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,8 @@ class PagerViewViewManager : ViewGroupManager<ViewPager2>() {
171171
"rtl" -> {
172172
viewPager.layoutDirection = View.LAYOUT_DIRECTION_RTL
173173
}
174-
"ltr" -> {
175-
viewPager.layoutDirection = View.LAYOUT_DIRECTION_LTR
176-
}
177-
"locale" -> {
178-
viewPager.layoutDirection = View.LAYOUT_DIRECTION_LOCALE
179-
}
180174
else -> {
181-
viewPager.layoutDirection = View.LAYOUT_DIRECTION_INHERIT
175+
viewPager.layoutDirection = View.LAYOUT_DIRECTION_LTR
182176
}
183177
}
184178
}

ios/ReactNativePageView.m

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,6 @@ - (NSString *)determineScrollDirection:(UIScrollView *)scrollView {
437437
}
438438

439439
- (BOOL)isLtrLayout {
440-
if ([_layoutDirection isEqualToString:@"locale"]) {
441-
return [UIApplication sharedApplication].userInterfaceLayoutDirection == UIUserInterfaceLayoutDirectionLeftToRight;
442-
} else {
443-
return [_layoutDirection isEqualToString:@"ltr"];
444-
}
440+
return [_layoutDirection isEqualToString:@"ltr"];
445441
}
446442
@end

src/PagerView.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { ReactElement } from 'react';
22
import { Platform, UIManager, Keyboard } from 'react-native';
3-
import ReactNative from 'react-native';
3+
import ReactNative, { I18nManager } from 'react-native';
44
import type {
55
PagerViewOnPageScrollEvent,
66
PagerViewOnPageSelectedEvent,
@@ -147,12 +147,24 @@ export class PagerView extends React.Component<PagerViewProps> {
147147
return this.isScrolling;
148148
};
149149

150+
private get deducedLayoutDirection() {
151+
const shouldUseDeviceRtlSetup =
152+
!this.props.layoutDirection || this.props.layoutDirection === 'locale';
153+
154+
if (shouldUseDeviceRtlSetup) {
155+
return I18nManager.isRTL ? 'rtl' : 'ltr';
156+
} else {
157+
return this.props.layoutDirection;
158+
}
159+
}
160+
150161
render() {
151162
return (
152163
<PagerViewViewManager
153164
{...this.props}
154165
ref={this.PagerView as any /** TODO: Fix ref type */}
155166
style={this.props.style}
167+
layoutDirection={this.deducedLayoutDirection}
156168
onPageScroll={this._onPageScroll}
157169
onPageScrollStateChanged={this._onPageScrollStateChanged}
158170
onPageSelected={this._onPageSelected}

0 commit comments

Comments
 (0)