Skip to content

Commit cadc753

Browse files
MengjueWFacebook Github Bot 7
authored andcommitted
Change NavigatorSceneConfig for RTL
Summary: For RTL experiment, we need to swap all the Left and Right gesture and animation. Provide RTL support for Navigator in RN. Reviewed By: hedgerwang Differential Revision: D3519811 fbshipit-source-id: b53d9bf901ec056614658b627823d2225bdc82b1
1 parent ca66383 commit cadc753

File tree

1 file changed

+92
-20
lines changed

1 file changed

+92
-20
lines changed

Libraries/CustomComponents/Navigator/NavigatorSceneConfigs.js

Lines changed: 92 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
/**
2-
* Copyright (c) 2015, Facebook, Inc. All rights reserved.
2+
* Copyright (c) 2013-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
38
*
49
* Facebook, Inc. ("Facebook") owns all right, title and interest, including
510
* all intellectual property and other proprietary rights, in and to the React
@@ -31,6 +36,9 @@ var PixelRatio = require('PixelRatio');
3136

3237
var buildStyleInterpolator = require('buildStyleInterpolator');
3338

39+
var I18nManager = require('NativeModules').I18nManager || {};
40+
var IS_RTL = I18nManager.isRTL;
41+
3442
var SCREEN_WIDTH = Dimensions.get('window').width;
3543
var SCREEN_HEIGHT = Dimensions.get('window').height;
3644

@@ -50,6 +58,14 @@ var ToTheLeftIOS = {
5058
},
5159
};
5260

61+
var ToTheRightIOS = {
62+
...ToTheLeftIOS,
63+
transformTranslate: {
64+
from: {x: 0, y: 0, z: 0},
65+
to: {x: SCREEN_WIDTH * 0.3, y: 0, z: 0},
66+
},
67+
};
68+
5369
var FadeToTheLeft = {
5470
// Rotate *requires* you to break out each individual component of
5571
// rotation (x, y, z, w)
@@ -126,7 +142,7 @@ var FadeToTheRight = {
126142
translateX: {
127143
from: 0,
128144
to: Math.round(SCREEN_WIDTH * 0.3),
129-
}
145+
},
130146
};
131147

132148
var FadeIn = {
@@ -179,6 +195,32 @@ var ToTheLeft = {
179195
},
180196
};
181197

198+
var ToTheRight = {
199+
transformTranslate: {
200+
from: {x: 0, y: 0, z: 0},
201+
to: {x: Dimensions.get('window').width, y: 0, z: 0},
202+
min: 0,
203+
max: 1,
204+
type: 'linear',
205+
extrapolate: true,
206+
round: PixelRatio.get(),
207+
},
208+
opacity: {
209+
value: 1.0,
210+
type: 'constant',
211+
},
212+
213+
translateX: {
214+
from: 0,
215+
to: Dimensions.get('window').width,
216+
min: 0,
217+
max: 1,
218+
type: 'linear',
219+
extrapolate: true,
220+
round: PixelRatio.get(),
221+
},
222+
};
223+
182224
var ToTheUp = {
183225
transformTranslate: {
184226
from: {x: 0, y: 0, z: 0},
@@ -500,10 +542,40 @@ var BaseUpDownGesture = {
500542
direction: 'up-to-down',
501543
};
502544

545+
// For RTL experiment, we need to swap all the Left and Right gesture and animation.
546+
// So we create a direction mapping for both LTR and RTL, and change left/right to start/end.
547+
let directionMapping = {
548+
ToTheStartIOS: ToTheLeftIOS,
549+
ToTheEndIOS: ToTheRightIOS,
550+
FadeToTheStart: FadeToTheLeft,
551+
FadeToTheEnd: FadeToTheRight,
552+
ToTheStart: ToTheLeft,
553+
ToTheEnd: ToTheRight,
554+
FromTheStart: FromTheLeft,
555+
FromTheEnd: FromTheRight,
556+
BaseStartToEndGesture: BaseLeftToRightGesture,
557+
BaseEndToStartGesture: BaseRightToLeftGesture,
558+
};
559+
560+
if (IS_RTL) {
561+
directionMapping = {
562+
ToTheStartIOS: ToTheRightIOS,
563+
ToTheEndIOS: ToTheLeftIOS,
564+
FadeToTheStart: FadeToTheRight,
565+
FadeToTheEnd: FadeToTheLeft,
566+
ToTheStart: ToTheRight,
567+
ToTheEnd: ToTheLeft,
568+
FromTheStart: FromTheRight,
569+
FromTheEnd: FromTheLeft,
570+
BaseStartToEndGesture: BaseRightToLeftGesture,
571+
BaseEndToStartGesture: BaseLeftToRightGesture,
572+
};
573+
}
574+
503575
var BaseConfig = {
504576
// A list of all gestures that are enabled on this scene
505577
gestures: {
506-
pop: BaseLeftToRightGesture,
578+
pop: directionMapping.BaseStartToEndGesture,
507579
},
508580

509581
// Rebound spring parameters when transitioning FROM this scene
@@ -515,17 +587,17 @@ var BaseConfig = {
515587

516588
// Animation interpolators for horizontal transitioning:
517589
animationInterpolators: {
518-
into: buildStyleInterpolator(FromTheRight),
519-
out: buildStyleInterpolator(FadeToTheLeft),
590+
into: buildStyleInterpolator(directionMapping.FromTheEnd),
591+
out: buildStyleInterpolator(directionMapping.FadeToTheStart),
520592
},
521593
};
522594

523595
var NavigatorSceneConfigs = {
524596
PushFromRight: {
525597
...BaseConfig,
526598
animationInterpolators: {
527-
into: buildStyleInterpolator(FromTheRight),
528-
out: buildStyleInterpolator(ToTheLeftIOS),
599+
into: buildStyleInterpolator(directionMapping.FromTheEnd),
600+
out: buildStyleInterpolator(directionMapping.ToTheStartIOS),
529601
},
530602
},
531603
FloatFromRight: {
@@ -535,18 +607,18 @@ var NavigatorSceneConfigs = {
535607
FloatFromLeft: {
536608
...BaseConfig,
537609
gestures: {
538-
pop: BaseRightToLeftGesture,
610+
pop: directionMapping.BaseEndToStartGesture,
539611
},
540612
animationInterpolators: {
541-
into: buildStyleInterpolator(FromTheLeft),
542-
out: buildStyleInterpolator(FadeToTheRight),
613+
into: buildStyleInterpolator(directionMapping.FromTheStart),
614+
out: buildStyleInterpolator(directionMapping.FadeToTheEnd),
543615
},
544616
},
545617
FloatFromBottom: {
546618
...BaseConfig,
547619
gestures: {
548620
pop: {
549-
...BaseLeftToRightGesture,
621+
...directionMapping.BaseStartToEndGesture,
550622
edgeHitWidth: 150,
551623
direction: 'top-to-bottom',
552624
fullDistance: SCREEN_HEIGHT,
@@ -579,43 +651,43 @@ var NavigatorSceneConfigs = {
579651
...BaseConfig,
580652
gestures: {
581653
jumpBack: {
582-
...BaseLeftToRightGesture,
654+
...directionMapping.BaseStartToEndGesture,
583655
overswipe: BaseOverswipeConfig,
584656
edgeHitWidth: null,
585657
isDetachable: true,
586658
},
587659
jumpForward: {
588-
...BaseRightToLeftGesture,
660+
...directionMapping.BaseEndToStartGesture,
589661
overswipe: BaseOverswipeConfig,
590662
edgeHitWidth: null,
591663
isDetachable: true,
592664
},
593665
},
594666
animationInterpolators: {
595-
into: buildStyleInterpolator(FromTheRight),
596-
out: buildStyleInterpolator(ToTheLeft),
667+
into: buildStyleInterpolator(directionMapping.FromTheEnd),
668+
out: buildStyleInterpolator(directionMapping.ToTheStart),
597669
},
598670
},
599671
HorizontalSwipeJumpFromRight: {
600672
...BaseConfig,
601673
gestures: {
602674
jumpBack: {
603-
...BaseRightToLeftGesture,
675+
...directionMapping.BaseEndToStartGesture,
604676
overswipe: BaseOverswipeConfig,
605677
edgeHitWidth: null,
606678
isDetachable: true,
607679
},
608680
jumpForward: {
609-
...BaseLeftToRightGesture,
681+
...directionMapping.BaseStartToEndGesture,
610682
overswipe: BaseOverswipeConfig,
611683
edgeHitWidth: null,
612684
isDetachable: true,
613685
},
614-
pop: BaseRightToLeftGesture,
686+
pop: directionMapping.BaseEndToStartGesture,
615687
},
616688
animationInterpolators: {
617-
into: buildStyleInterpolator(FromTheLeft),
618-
out: buildStyleInterpolator(FadeToTheRight),
689+
into: buildStyleInterpolator(directionMapping.FromTheStart),
690+
out: buildStyleInterpolator(directionMapping.FadeToTheEnd),
619691
},
620692
},
621693
VerticalUpSwipeJump: {

0 commit comments

Comments
 (0)