Ensure app doesn't crash when module is absent

Summary: Before we flow-typed NativeI18nManager, we defaulted the implementation of I18nManager to something safe when it wasn't available. After the flow-type, it became a requirement that NativeI18nManager be present in the app. This is leading to crashes: T45287329. This diff re-enables the defaults for I18nManager.

Reviewed By: fkgozali

Differential Revision: D15617660

fbshipit-source-id: c3a1c737663a1a4ceae484d0ad6cbf2bd86ffe5f
This commit is contained in:
Ramanpreet Nara 2019-06-03 20:51:10 -07:00 коммит произвёл Facebook Github Bot
Родитель 43d7664308
Коммит 22475ed38d
2 изменённых файлов: 23 добавлений и 5 удалений

Просмотреть файл

@ -11,24 +11,42 @@
import NativeI18nManager from './NativeI18nManager';
const i18nConstants = NativeI18nManager
? NativeI18nManager.getConstants()
: {
isRTL: false,
doLeftAndRightSwapInRTL: true,
};
module.exports = {
getConstants: () => {
return NativeI18nManager.getConstants();
return i18nConstants;
},
allowRTL: (shouldAllow: boolean) => {
if (!NativeI18nManager) {
return;
}
NativeI18nManager.allowRTL(shouldAllow);
},
forceRTL: (shouldForce: boolean) => {
if (!NativeI18nManager) {
return;
}
NativeI18nManager.forceRTL(shouldForce);
},
swapLeftAndRightInRTL: (flipStyles: boolean) => {
if (!NativeI18nManager) {
return;
}
NativeI18nManager.swapLeftAndRightInRTL(flipStyles);
},
isRTL: NativeI18nManager.getConstants().isRTL,
doLeftAndRightSwapInRTL: NativeI18nManager.getConstants()
.doLeftAndRightSwapInRTL,
isRTL: i18nConstants.isRTL,
doLeftAndRightSwapInRTL: i18nConstants.doLeftAndRightSwapInRTL,
};

Просмотреть файл

@ -23,4 +23,4 @@ export interface Spec extends TurboModule {
swapLeftAndRightInRTL: (flipStyles: boolean) => void;
}
export default TurboModuleRegistry.getEnforcing<Spec>('I18nManager');
export default TurboModuleRegistry.get<Spec>('I18nManager');