From 22475ed38d181754d64a69f3d2143fa7d4b22a35 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Mon, 3 Jun 2019 20:51:10 -0700 Subject: [PATCH] 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 --- Libraries/ReactNative/I18nManager.js | 26 ++++++++++++++++++---- Libraries/ReactNative/NativeI18nManager.js | 2 +- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Libraries/ReactNative/I18nManager.js b/Libraries/ReactNative/I18nManager.js index e5fd02e7c13..f5616c807ae 100644 --- a/Libraries/ReactNative/I18nManager.js +++ b/Libraries/ReactNative/I18nManager.js @@ -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, }; diff --git a/Libraries/ReactNative/NativeI18nManager.js b/Libraries/ReactNative/NativeI18nManager.js index 0220b2471ba..9da9a6ade2b 100644 --- a/Libraries/ReactNative/NativeI18nManager.js +++ b/Libraries/ReactNative/NativeI18nManager.js @@ -23,4 +23,4 @@ export interface Spec extends TurboModule { swapLeftAndRightInRTL: (flipStyles: boolean) => void; } -export default TurboModuleRegistry.getEnforcing('I18nManager'); +export default TurboModuleRegistry.get('I18nManager');