mirror of
https://github.com/status-im/react-native.git
synced 2025-02-26 16:10:58 +00:00
Provide RTL support in NavigationCardStack
Summary: Provide RTL support in NavigationCardStack Reviewed By: fkgozali Differential Revision: D3740172 fbshipit-source-id: 69466d24e148d0d81cb9f21c55f545abda46ac35
This commit is contained in:
parent
959c8b170e
commit
fc864a22bd
@ -13,6 +13,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Animated = require('Animated');
|
const Animated = require('Animated');
|
||||||
|
const I18nManager = require('I18nManager');
|
||||||
const NavigationAbstractPanResponder = require('NavigationAbstractPanResponder');
|
const NavigationAbstractPanResponder = require('NavigationAbstractPanResponder');
|
||||||
|
|
||||||
const clamp = require('clamp');
|
const clamp = require('clamp');
|
||||||
@ -150,10 +151,13 @@ class NavigationCardStackPanResponder extends NavigationAbstractPanResponder {
|
|||||||
const distance = isVertical ?
|
const distance = isVertical ?
|
||||||
layout.height.__getValue() :
|
layout.height.__getValue() :
|
||||||
layout.width.__getValue();
|
layout.width.__getValue();
|
||||||
|
const currentValue = I18nManager.isRTL && axis === 'dx' ?
|
||||||
|
this._startValue + (gesture[axis] / distance) :
|
||||||
|
this._startValue - (gesture[axis] / distance);
|
||||||
|
|
||||||
const value = clamp(
|
const value = clamp(
|
||||||
index - 1,
|
index - 1,
|
||||||
this._startValue - (gesture[axis] / distance),
|
currentValue,
|
||||||
index
|
index
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -171,7 +175,9 @@ class NavigationCardStackPanResponder extends NavigationAbstractPanResponder {
|
|||||||
const isVertical = this._isVertical;
|
const isVertical = this._isVertical;
|
||||||
const axis = isVertical ? 'dy' : 'dx';
|
const axis = isVertical ? 'dy' : 'dx';
|
||||||
const index = props.navigationState.index;
|
const index = props.navigationState.index;
|
||||||
const distance = gesture[axis];
|
const distance = I18nManager.isRTL && axis === 'dx' ?
|
||||||
|
-gesture[axis] :
|
||||||
|
gesture[axis];
|
||||||
|
|
||||||
props.position.stopAnimation((value: number) => {
|
props.position.stopAnimation((value: number) => {
|
||||||
this._reset();
|
this._reset();
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const I18nManager = require('I18nManager');
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
NavigationSceneRendererProps,
|
NavigationSceneRendererProps,
|
||||||
} from 'NavigationTypeDefinition';
|
} from 'NavigationTypeDefinition';
|
||||||
@ -87,6 +89,10 @@ function forHorizontal(props: NavigationSceneRendererProps): Object {
|
|||||||
const index = scene.index;
|
const index = scene.index;
|
||||||
const inputRange = [index - 1, index, index + 1];
|
const inputRange = [index - 1, index, index + 1];
|
||||||
const width = layout.initWidth;
|
const width = layout.initWidth;
|
||||||
|
const outputRange = I18nManager.isRTL ?
|
||||||
|
([-width, 0, 10]: Array<number>) :
|
||||||
|
([width, 0, -10]: Array<number>);
|
||||||
|
|
||||||
|
|
||||||
const opacity = position.interpolate({
|
const opacity = position.interpolate({
|
||||||
inputRange,
|
inputRange,
|
||||||
@ -101,7 +107,7 @@ function forHorizontal(props: NavigationSceneRendererProps): Object {
|
|||||||
const translateY = 0;
|
const translateY = 0;
|
||||||
const translateX = position.interpolate({
|
const translateX = position.interpolate({
|
||||||
inputRange,
|
inputRange,
|
||||||
outputRange: ([width, 0, -10]: Array<number>),
|
outputRange,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -27,6 +27,7 @@ const React = require('react');
|
|||||||
const ReactNative = require('react-native');
|
const ReactNative = require('react-native');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
I18nManager,
|
||||||
Image,
|
Image,
|
||||||
Platform,
|
Platform,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
@ -58,7 +59,8 @@ const styles = StyleSheet.create({
|
|||||||
height: 24,
|
height: 24,
|
||||||
width: 24,
|
width: 24,
|
||||||
margin: Platform.OS === 'ios' ? 10 : 16,
|
margin: Platform.OS === 'ios' ? 10 : 16,
|
||||||
resizeMode: 'contain'
|
resizeMode: 'contain',
|
||||||
|
transform: [{scaleX: I18nManager.isRTL ? -1 : 1}],
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const I18nManager = require('I18nManager');
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
NavigationSceneRendererProps,
|
NavigationSceneRendererProps,
|
||||||
@ -71,7 +72,9 @@ function forCenter(props: NavigationSceneRendererProps): Object {
|
|||||||
{
|
{
|
||||||
translateX: position.interpolate({
|
translateX: position.interpolate({
|
||||||
inputRange: [ index - 1, index + 1 ],
|
inputRange: [ index - 1, index + 1 ],
|
||||||
outputRange: ([ 200, -200 ]: Array<number>),
|
outputRange: I18nManager.isRTL ?
|
||||||
|
([ -200, 200 ]: Array<number>) :
|
||||||
|
([ 200, -200 ]: Array<number>),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user