Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable import/no-mutable-exports,global-require */

/**
* For react-native version >= 0.71, the LaunchDarkly React-Native SDK uses
* The LaunchDarkly React-Native SDK uses
* @react-native-async-storage/async-storage for bootstrapping. This is a native
* dependency.
*
Expand All @@ -14,17 +14,18 @@
* does not work with transitive dependencies:
* https://github.com/react-native-community/cli/issues/1347
*
* For react-native version < 0.71, the built-in react-native AsyncStorage
* module is used.
*/
let ConditionalAsyncStorage: any;

try {
// react-native version < 0.71
ConditionalAsyncStorage = require('react-native').AsyncStorage;
} catch (e) {
// react-native version >= 0.71
ConditionalAsyncStorage = require('@react-native-async-storage/async-storage').default;
} catch (e) {
// Use a mock if async-storage is unavailable
ConditionalAsyncStorage = {
getItem: (_key: string) => Promise.resolve(null),
setItem: (_key: string, _value: string) => Promise.resolve(),
removeItem: (_key: string) => Promise.resolve(),
};
}

export default ConditionalAsyncStorage;
2 changes: 1 addition & 1 deletion packages/sdk/react-native/src/platform/autoEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ export const ldDevice: LDDevice = {
default: Platform.OS,
}),
name: Platform.OS,
version: Platform.Version.toString(),
version: Platform.Version?.toString(),
},
};
2 changes: 1 addition & 1 deletion packages/sdk/react-native/src/platform/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import { NativeModules, Platform } from 'react-native';
const locale =
Platform.OS === 'ios'
? NativeModules.SettingsManager.settings.AppleLocale // iOS
: NativeModules.I18nManager.localeIdentifier; // Android and rest
: NativeModules.I18nManager?.localeIdentifier;

export default locale;