From 0daae683fb2dea25204c0908631a3f6cba74b7e8 Mon Sep 17 00:00:00 2001 From: Calham Northway Date: Wed, 10 Sep 2025 12:41:04 -0700 Subject: [PATCH] fix: app crashing due to undefined settings constant accessor - add check for undefined settings constant - add null coalescing operation to use getConstants to prevent undefined settings object --- .../sdk/react-native/src/platform/locale.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/sdk/react-native/src/platform/locale.ts b/packages/sdk/react-native/src/platform/locale.ts index 3fff16028b..f5fbf25b48 100644 --- a/packages/sdk/react-native/src/platform/locale.ts +++ b/packages/sdk/react-native/src/platform/locale.ts @@ -1,12 +1,15 @@ import { NativeModules, Platform } from 'react-native'; - /** - * Ripped from: - * https://dev.to/medaimane/localization-and-internationalization-in-react-native-reaching-global-audiences-3acj + * Apps opted into Fabric (the new architecture of React Native) + * may not have access to the SettingsManager.settings.AppleLocale property. + * It is now common to use the `getConstants` method to access these constant properties with Fabric enabled apps. */ -const locale = - Platform.OS === 'ios' - ? NativeModules.SettingsManager?.settings?.AppleLocale // iOS - : NativeModules.I18nManager?.localeIdentifier; +const getAppleLocale = () => { + const settings = NativeModules.SettingsManager?.settings ?? NativeModules.SettingsManager?.getConstants()?.settings; + return settings?.AppleLocale; +} -export default locale; +export default Platform.select({ + ios: getAppleLocale(), + android: NativeModules.I18nManager?.localeIdentifier, +})