88 * @format
99 */
1010
11- import type { I18nManagerConstants } from './NativeI18nManager' ;
12-
11+ import warnOnce from '../Utilities/warnOnce' ;
1312import NativeI18nManager from './NativeI18nManager' ;
1413
14+ type I18nManagerConstants = {
15+ /**
16+ * @deprecated `left` and `right` style properties are no longer swapped in
17+ * RTL. Use `start` and `end` style properties, such as `marginStart`,
18+ * instead.
19+ */
20+ doLeftAndRightSwapInRTL : boolean ,
21+ isRTL : boolean ,
22+ localeIdentifier ?: ?string ,
23+ } ;
24+
1525const i18nConstants : I18nManagerConstants = getI18nManagerConstants ( ) ;
1626
1727function getI18nManagerConstants ( ) : I18nManagerConstants {
1828 if ( NativeI18nManager ) {
1929 const { isRTL, doLeftAndRightSwapInRTL, localeIdentifier} =
2030 NativeI18nManager . getConstants ( ) ;
21- return { isRTL, doLeftAndRightSwapInRTL, localeIdentifier} ;
31+ return {
32+ isRTL,
33+ // Older native binaries still swap left and right styles in RTL
34+ doLeftAndRightSwapInRTL : doLeftAndRightSwapInRTL ?? false ,
35+ localeIdentifier,
36+ } ;
2237 }
2338
2439 return {
2540 isRTL : false ,
26- doLeftAndRightSwapInRTL : true ,
41+ doLeftAndRightSwapInRTL : false ,
2742 } ;
2843}
2944
@@ -38,15 +53,18 @@ export default {
3853 } ,
3954
4055 /**
41- * Allows the app to opt in to RTL layout behavior. Should be called early
42- * in app startup. Takes effect on the next app reload.
56+ * @deprecated Has no effect. Set `RCTSupportsRTL` to `true` in Info.plist on
57+ * iOS, or `android:supportsRtl="true"` in AndroidManifest.xml on Android,
58+ * instead.
4359 */
44- allowRTL : ( shouldAllow : boolean ) => {
45- if ( ! NativeI18nManager ) {
46- return ;
47- }
48-
49- NativeI18nManager . allowRTL ( shouldAllow ) ;
60+ allowRTL : ( shouldAllow : boolean ) : void => {
61+ warnOnce (
62+ 'I18nManager.allowRTL' ,
63+ 'I18nManager.allowRTL() is deprecated and has no effect. Set ' +
64+ '`RCTSupportsRTL` to `true` in Info.plist on iOS, or ' +
65+ '`android:supportsRtl="true"` in AndroidManifest.xml on Android, ' +
66+ 'instead.' ,
67+ ) ;
5068 } ,
5169
5270 /**
@@ -62,21 +80,34 @@ export default {
6280 } ,
6381
6482 /**
65- * Controls whether `left`/`right ` style properties are automatically swapped
66- * in RTL layouts. When enabled, `left` becomes `right` and vice versa .
83+ * @deprecated Has no effect. Use `start` and `end ` style properties, such as
84+ * `marginStart`, instead .
6785 */
68- swapLeftAndRightInRTL : ( flipStyles : boolean ) => {
69- if ( ! NativeI18nManager ) {
70- return ;
71- }
72-
73- NativeI18nManager . swapLeftAndRightInRTL ( flipStyles ) ;
86+ swapLeftAndRightInRTL : ( flipStyles : boolean ) : void => {
87+ warnOnce (
88+ 'I18nManager.swapLeftAndRightInRTL' ,
89+ 'I18nManager.swapLeftAndRightInRTL() is deprecated and has no effect. ' +
90+ 'Use `start` and `end` style properties, such as `marginStart`, ' +
91+ 'instead.' ,
92+ ) ;
7493 } ,
7594
7695 /** Whether the current layout direction is Right-to-Left. */
7796 isRTL : i18nConstants . isRTL as I18nManagerConstants [ 'isRTL' ] ,
7897
79- /** Whether left and right style properties are swapped in RTL mode. */
80- doLeftAndRightSwapInRTL :
81- i18nConstants . doLeftAndRightSwapInRTL as I18nManagerConstants [ 'doLeftAndRightSwapInRTL' ] ,
98+ /**
99+ * @deprecated `left` and `right` style properties are no longer swapped in
100+ * RTL. Use `start` and `end` style properties, such as `marginStart`,
101+ * instead.
102+ */
103+ // $FlowFixMe[unsafe-getters-setters]
104+ get doLeftAndRightSwapInRTL ( ) : I18nManagerConstants [ 'doLeftAndRightSwapInRTL' ] {
105+ warnOnce (
106+ 'I18nManager.doLeftAndRightSwapInRTL' ,
107+ 'I18nManager.doLeftAndRightSwapInRTL is deprecated. `left` and `right` ' +
108+ 'style properties are no longer swapped in RTL. Use `start` and ' +
109+ '`end` style properties, such as `marginStart`, instead.' ,
110+ ) ;
111+ return i18nConstants . doLeftAndRightSwapInRTL ;
112+ } ,
82113} ;
0 commit comments