diff --git a/Libraries/Inspector/resolveBoxStyle.js b/Libraries/Inspector/resolveBoxStyle.js index 15dfaf3061d810..1f013ed064ba3c 100644 --- a/Libraries/Inspector/resolveBoxStyle.js +++ b/Libraries/Inspector/resolveBoxStyle.js @@ -69,7 +69,8 @@ function resolveBoxStyle( const styleForEnd = style[prefix + 'End']; if (styleForEnd != null) { - if (I18nManager.isRTL && I18nManager.doLeftAndRightSwapInRTL) { + const constants = I18nManager.getConstants(); + if (constants.isRTL && constants.doLeftAndRightSwapInRTL) { result.left = styleForEnd; } else { result.right = styleForEnd; @@ -78,7 +79,8 @@ function resolveBoxStyle( } const styleForStart = style[prefix + 'Start']; if (styleForStart != null) { - if (I18nManager.isRTL && I18nManager.doLeftAndRightSwapInRTL) { + const constants = I18nManager.getConstants(); + if (constants.isRTL && constants.doLeftAndRightSwapInRTL) { result.right = styleForStart; } else { result.left = styleForStart; diff --git a/Libraries/Modal/Modal.js b/Libraries/Modal/Modal.js index e364ec0af7f74c..c31c226eab6293 100644 --- a/Libraries/Modal/Modal.js +++ b/Libraries/Modal/Modal.js @@ -272,7 +272,7 @@ class Modal extends React.Component { } } -const side = I18nManager.isRTL ? 'right' : 'left'; +const side = I18nManager.getConstants().isRTL ? 'right' : 'left'; const styles = StyleSheet.create({ modal: { position: 'absolute', diff --git a/Libraries/ReactNative/I18nManager.js b/Libraries/ReactNative/I18nManager.js index da2767a842068f..9ca6b9eaa8df41 100644 --- a/Libraries/ReactNative/I18nManager.js +++ b/Libraries/ReactNative/I18nManager.js @@ -9,21 +9,6 @@ */ 'use strict'; -type I18nManagerStatus = { - isRTL: boolean, - doLeftAndRightSwapInRTL: boolean, - allowRTL: (allowRTL: boolean) => {}, - forceRTL: (forceRTL: boolean) => {}, - swapLeftAndRightInRTL: (flipStyles: boolean) => {}, -}; +import NativeI18nManager from './NativeI18nManager'; -const I18nManager: I18nManagerStatus = require('../BatchedBridge/NativeModules') - .I18nManager || { - isRTL: false, - doLeftAndRightSwapInRTL: true, - allowRTL: () => {}, - forceRTL: () => {}, - swapLeftAndRightInRTL: () => {}, -}; - -module.exports = I18nManager; +module.exports = NativeI18nManager; diff --git a/Libraries/ReactNative/NativeI18nManager.js b/Libraries/ReactNative/NativeI18nManager.js new file mode 100644 index 00000000000000..649ef58253dc1c --- /dev/null +++ b/Libraries/ReactNative/NativeI18nManager.js @@ -0,0 +1,26 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ + +'use strict'; + +import type {TurboModule} from 'RCTExport'; +import * as TurboModuleRegistry from 'TurboModuleRegistry'; + +export interface Spec extends TurboModule { + +getConstants: () => {| + isRTL: boolean, + doLeftAndRightSwapInRTL: boolean, + |}; + allowRTL: (allowRTL: boolean) => void; + forceRTL: (forceRTL: boolean) => void; + swapLeftAndRightInRTL: (flipStyles: boolean) => void; +} + +export default TurboModuleRegistry.getEnforcing('I18nManager'); diff --git a/RNTester/js/RTLExample.js b/RNTester/js/RTLExample.js index 38462ee5bfabe7..3beae7a2f1bacd 100644 --- a/RNTester/js/RTLExample.js +++ b/RNTester/js/RTLExample.js @@ -46,7 +46,7 @@ const SCALE = PixelRatio.get(); const IMAGE_DIMENSION = 100 * SCALE; const IMAGE_SIZE = [IMAGE_DIMENSION, IMAGE_DIMENSION]; -const IS_RTL = I18nManager.isRTL; +const IS_RTL = I18nManager.getConstants().isRTL; function ListItem(props) { return (