Skip to content

Commit fc864a2

Browse files
MengjueWFacebook Github Bot 3
authored andcommitted
Provide RTL support in NavigationCardStack
Summary: Provide RTL support in NavigationCardStack Reviewed By: fkgozali Differential Revision: D3740172 fbshipit-source-id: 69466d24e148d0d81cb9f21c55f545abda46ac35
1 parent 959c8b1 commit fc864a2

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

Libraries/CustomComponents/NavigationExperimental/NavigationCardStackPanResponder.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
'use strict';
1414

1515
const Animated = require('Animated');
16+
const I18nManager = require('I18nManager');
1617
const NavigationAbstractPanResponder = require('NavigationAbstractPanResponder');
1718

1819
const clamp = require('clamp');
@@ -150,10 +151,13 @@ class NavigationCardStackPanResponder extends NavigationAbstractPanResponder {
150151
const distance = isVertical ?
151152
layout.height.__getValue() :
152153
layout.width.__getValue();
154+
const currentValue = I18nManager.isRTL && axis === 'dx' ?
155+
this._startValue + (gesture[axis] / distance) :
156+
this._startValue - (gesture[axis] / distance);
153157

154158
const value = clamp(
155159
index - 1,
156-
this._startValue - (gesture[axis] / distance),
160+
currentValue,
157161
index
158162
);
159163

@@ -171,7 +175,9 @@ class NavigationCardStackPanResponder extends NavigationAbstractPanResponder {
171175
const isVertical = this._isVertical;
172176
const axis = isVertical ? 'dy' : 'dx';
173177
const index = props.navigationState.index;
174-
const distance = gesture[axis];
178+
const distance = I18nManager.isRTL && axis === 'dx' ?
179+
-gesture[axis] :
180+
gesture[axis];
175181

176182
props.position.stopAnimation((value: number) => {
177183
this._reset();

Libraries/CustomComponents/NavigationExperimental/NavigationCardStackStyleInterpolator.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
*/
3333
'use strict';
3434

35+
const I18nManager = require('I18nManager');
36+
3537
import type {
3638
NavigationSceneRendererProps,
3739
} from 'NavigationTypeDefinition';
@@ -87,6 +89,10 @@ function forHorizontal(props: NavigationSceneRendererProps): Object {
8789
const index = scene.index;
8890
const inputRange = [index - 1, index, index + 1];
8991
const width = layout.initWidth;
92+
const outputRange = I18nManager.isRTL ?
93+
([-width, 0, 10]: Array<number>) :
94+
([width, 0, -10]: Array<number>);
95+
9096

9197
const opacity = position.interpolate({
9298
inputRange,
@@ -101,7 +107,7 @@ function forHorizontal(props: NavigationSceneRendererProps): Object {
101107
const translateY = 0;
102108
const translateX = position.interpolate({
103109
inputRange,
104-
outputRange: ([width, 0, -10]: Array<number>),
110+
outputRange,
105111
});
106112

107113
return {

Libraries/CustomComponents/NavigationExperimental/NavigationHeaderBackButton.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const React = require('react');
2727
const ReactNative = require('react-native');
2828

2929
const {
30+
I18nManager,
3031
Image,
3132
Platform,
3233
StyleSheet,
@@ -58,7 +59,8 @@ const styles = StyleSheet.create({
5859
height: 24,
5960
width: 24,
6061
margin: Platform.OS === 'ios' ? 10 : 16,
61-
resizeMode: 'contain'
62+
resizeMode: 'contain',
63+
transform: [{scaleX: I18nManager.isRTL ? -1 : 1}],
6264
}
6365
});
6466

Libraries/CustomComponents/NavigationExperimental/NavigationHeaderStyleInterpolator.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*/
3333
'use strict';
3434

35+
const I18nManager = require('I18nManager');
3536

3637
import type {
3738
NavigationSceneRendererProps,
@@ -71,7 +72,9 @@ function forCenter(props: NavigationSceneRendererProps): Object {
7172
{
7273
translateX: position.interpolate({
7374
inputRange: [ index - 1, index + 1 ],
74-
outputRange: ([ 200, -200 ]: Array<number>),
75+
outputRange: I18nManager.isRTL ?
76+
([ -200, 200 ]: Array<number>) :
77+
([ 200, -200 ]: Array<number>),
7578
}),
7679
}
7780
],

0 commit comments

Comments
 (0)