add spec for I18nManager (#24908)

Summary:
Part of #24875.

## Changelog

[General] [Added] - add TM spec for I18nManager
Pull Request resolved: https://github.com/facebook/react-native/pull/24908

Reviewed By: fkgozali

Differential Revision: D15395163

Pulled By: RSNara

fbshipit-source-id: 8fd3a5a8ce5d0f74132efff4fae7224eab03405b
This commit is contained in:
Eric Lewis
2019-05-31 19:56:37 -07:00
committed by Facebook Github Bot
parent 5e6cebe50b
commit 18fededae0
5 changed files with 61 additions and 19 deletions
+4 -2
View File
@@ -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;
+1 -1
View File
@@ -271,7 +271,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',
+21 -16
View File
@@ -9,21 +9,26 @@
*/
'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 = {
getConstants: () => {
return NativeI18nManager.getConstants();
},
module.exports = I18nManager;
allowRTL: (shouldAllow: boolean) => {
NativeI18nManager.allowRTL(shouldAllow);
},
forceRTL: (shouldForce: boolean) => {
NativeI18nManager.forceRTL(shouldForce);
},
swapLeftAndRightInRTL: (flipStyles: boolean) => {
NativeI18nManager.swapLeftAndRightInRTL(flipStyles);
},
isRTL: NativeI18nManager.getConstants().isRTL,
doLeftAndRightSwapInRTL: NativeI18nManager.getConstants()
.doLeftAndRightSwapInRTL,
};
@@ -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 '../TurboModule/RCTExport';
import * as TurboModuleRegistry from '../TurboModule/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');
+9
View File
@@ -312,6 +312,15 @@ jest
addListener: jest.fn(),
removeListeners: jest.fn(),
},
I18nManager: {
allowRTL: jest.fn(),
forceRTL: jest.fn(),
swapLeftAndRightInRTL: jest.fn(),
getConstants: () => ({
isRTL: false,
doLeftAndRightSwapInRTL: true,
}),
},
}))
.mock('../Libraries/ReactNative/requireNativeComponent', () => {
const React = require('react');