Skip to content

Commit

Permalink
Ensure app doesn't crash when module is absent
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RSNara authored and facebook-github-bot committed Jun 4, 2019
1 parent 43d7664 commit 22475ed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 22 additions & 4 deletions Libraries/ReactNative/I18nManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
2 changes: 1 addition & 1 deletion Libraries/ReactNative/NativeI18nManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

0 comments on commit 22475ed

Please sign in to comment.