Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TM] add spec for I18nManager #24908

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Libraries/Inspector/resolveBoxStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class Modal extends React.Component<Props> {
}
}

const side = I18nManager.isRTL ? 'right' : 'left';
const side = I18nManager.getConstants().isRTL ? 'right' : 'left';
const styles = StyleSheet.create({
modal: {
position: 'absolute',
Expand Down
19 changes: 2 additions & 17 deletions Libraries/ReactNative/I18nManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
26 changes: 26 additions & 0 deletions Libraries/ReactNative/NativeI18nManager.js
Original file line number Diff line number Diff line change
@@ -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<Spec>('I18nManager');
2 changes: 1 addition & 1 deletion RNTester/js/RTLExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down