Skip to content

Commit 14ce392

Browse files
authored
fix: Guard against null auto env attributes and async-storage. (#384)
1 parent be6b73b commit 14ce392

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable import/no-mutable-exports,global-require */
22

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

2220
try {
23-
// react-native version < 0.71
24-
ConditionalAsyncStorage = require('react-native').AsyncStorage;
25-
} catch (e) {
26-
// react-native version >= 0.71
2721
ConditionalAsyncStorage = require('@react-native-async-storage/async-storage').default;
22+
} catch (e) {
23+
// Use a mock if async-storage is unavailable
24+
ConditionalAsyncStorage = {
25+
getItem: (_key: string) => Promise.resolve(null),
26+
setItem: (_key: string, _value: string) => Promise.resolve(),
27+
removeItem: (_key: string) => Promise.resolve(),
28+
};
2829
}
2930

3031
export default ConditionalAsyncStorage;

packages/sdk/react-native/src/platform/autoEnv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ export const ldDevice: LDDevice = {
3737
default: Platform.OS,
3838
}),
3939
name: Platform.OS,
40-
version: Platform.Version.toString(),
40+
version: Platform.Version?.toString(),
4141
},
4242
};

packages/sdk/react-native/src/platform/locale.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ import { NativeModules, Platform } from 'react-native';
77
const locale =
88
Platform.OS === 'ios'
99
? NativeModules.SettingsManager.settings.AppleLocale // iOS
10-
: NativeModules.I18nManager.localeIdentifier; // Android and rest
10+
: NativeModules.I18nManager?.localeIdentifier;
1111

1212
export default locale;

0 commit comments

Comments
 (0)