Skip to content

Commit 18feded

Browse files
ericlewisfacebook-github-bot
authored andcommitted
add spec for I18nManager (#24908)
Summary: Part of #24875. ## Changelog [General] [Added] - add TM spec for I18nManager Pull Request resolved: #24908 Reviewed By: fkgozali Differential Revision: D15395163 Pulled By: RSNara fbshipit-source-id: 8fd3a5a8ce5d0f74132efff4fae7224eab03405b
1 parent 5e6cebe commit 18feded

File tree

5 files changed

+61
-19
lines changed

5 files changed

+61
-19
lines changed

Libraries/Inspector/resolveBoxStyle.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ function resolveBoxStyle(
6969

7070
const styleForEnd = style[prefix + 'End'];
7171
if (styleForEnd != null) {
72-
if (I18nManager.isRTL && I18nManager.doLeftAndRightSwapInRTL) {
72+
const constants = I18nManager.getConstants();
73+
if (constants.isRTL && constants.doLeftAndRightSwapInRTL) {
7374
result.left = styleForEnd;
7475
} else {
7576
result.right = styleForEnd;
@@ -78,7 +79,8 @@ function resolveBoxStyle(
7879
}
7980
const styleForStart = style[prefix + 'Start'];
8081
if (styleForStart != null) {
81-
if (I18nManager.isRTL && I18nManager.doLeftAndRightSwapInRTL) {
82+
const constants = I18nManager.getConstants();
83+
if (constants.isRTL && constants.doLeftAndRightSwapInRTL) {
8284
result.right = styleForStart;
8385
} else {
8486
result.left = styleForStart;

Libraries/Modal/Modal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class Modal extends React.Component<Props> {
271271
}
272272
}
273273

274-
const side = I18nManager.isRTL ? 'right' : 'left';
274+
const side = I18nManager.getConstants().isRTL ? 'right' : 'left';
275275
const styles = StyleSheet.create({
276276
modal: {
277277
position: 'absolute',

Libraries/ReactNative/I18nManager.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,26 @@
99
*/
1010
'use strict';
1111

12-
type I18nManagerStatus = {
13-
isRTL: boolean,
14-
doLeftAndRightSwapInRTL: boolean,
15-
allowRTL: (allowRTL: boolean) => {},
16-
forceRTL: (forceRTL: boolean) => {},
17-
swapLeftAndRightInRTL: (flipStyles: boolean) => {},
18-
};
12+
import NativeI18nManager from './NativeI18nManager';
1913

20-
const I18nManager: I18nManagerStatus = require('../BatchedBridge/NativeModules')
21-
.I18nManager || {
22-
isRTL: false,
23-
doLeftAndRightSwapInRTL: true,
24-
allowRTL: () => {},
25-
forceRTL: () => {},
26-
swapLeftAndRightInRTL: () => {},
27-
};
14+
module.exports = {
15+
getConstants: () => {
16+
return NativeI18nManager.getConstants();
17+
},
18+
19+
allowRTL: (shouldAllow: boolean) => {
20+
NativeI18nManager.allowRTL(shouldAllow);
21+
},
2822

29-
module.exports = I18nManager;
23+
forceRTL: (shouldForce: boolean) => {
24+
NativeI18nManager.forceRTL(shouldForce);
25+
},
26+
27+
swapLeftAndRightInRTL: (flipStyles: boolean) => {
28+
NativeI18nManager.swapLeftAndRightInRTL(flipStyles);
29+
},
30+
31+
isRTL: NativeI18nManager.getConstants().isRTL,
32+
doLeftAndRightSwapInRTL: NativeI18nManager.getConstants()
33+
.doLeftAndRightSwapInRTL,
34+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
* @format
9+
*/
10+
11+
'use strict';
12+
13+
import type {TurboModule} from '../TurboModule/RCTExport';
14+
import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry';
15+
16+
export interface Spec extends TurboModule {
17+
+getConstants: () => {|
18+
isRTL: boolean,
19+
doLeftAndRightSwapInRTL: boolean,
20+
|};
21+
allowRTL: (allowRTL: boolean) => void;
22+
forceRTL: (forceRTL: boolean) => void;
23+
swapLeftAndRightInRTL: (flipStyles: boolean) => void;
24+
}
25+
26+
export default TurboModuleRegistry.getEnforcing<Spec>('I18nManager');

jest/setup.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,15 @@ jest
312312
addListener: jest.fn(),
313313
removeListeners: jest.fn(),
314314
},
315+
I18nManager: {
316+
allowRTL: jest.fn(),
317+
forceRTL: jest.fn(),
318+
swapLeftAndRightInRTL: jest.fn(),
319+
getConstants: () => ({
320+
isRTL: false,
321+
doLeftAndRightSwapInRTL: true,
322+
}),
323+
},
315324
}))
316325
.mock('../Libraries/ReactNative/requireNativeComponent', () => {
317326
const React = require('react');

0 commit comments

Comments
 (0)