Skip to content

Commit deb88bf

Browse files
committed
Update fallback to ensure that SDK <= 39 apps using this module will work as expected
1 parent 7865e48 commit deb88bf

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

src/shouldFallbackToLegacyNativeModule.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
const {NativeModules} = require('react-native');
22

33
export default function shouldFallbackToLegacyNativeModule() {
4-
const expoExecutionEnvironment = NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants?.executionEnvironment;
4+
const expoConstants =
5+
NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants;
56

6-
/**
7-
* Expo managed apps don't include the @react-native-async-storage/async-storage
8-
* native modules yet, but the API interface is the same, so we can use the version
9-
* exported from React Native still.
10-
*
11-
* If in future releases (eg: @react-native-async-storage/async-storage >= 2.0.0) this
12-
* will likely not be valid anymore, and the package will need to be included in the Expo SDK
13-
* to continue to work.
14-
*/
15-
if (expoExecutionEnvironment && ['storeClient', 'standalone'].includes(expoExecutionEnvironment)) {
16-
return true;
7+
if (expoConstants) {
8+
/**
9+
* In SDK <= 39, appOwnership is defined in managed apps but executionEnvironment is not.
10+
* In bare React Native apps using expo-constants, appOwnership is never defined, so
11+
* isLegacySdkVersion will be false in that context.
12+
*/
13+
const isLegacySdkVersion = expoConstants.appOwnership && !expoConstants.executionEnvironment;
14+
15+
/**
16+
* Expo managed apps don't include the @react-native-async-storage/async-storage
17+
* native modules yet, but the API interface is the same, so we can use the version
18+
* exported from React Native still.
19+
*
20+
* If in future releases (eg: @react-native-async-storage/async-storage >= 2.0.0) this
21+
* will likely not be valid anymore, and the package will need to be included in the Expo SDK
22+
* to continue to work.
23+
*/
24+
if (isLegacySdkVersion || ['storeClient', 'standalone'].includes(expoConstants.executionEnvironment)) {
25+
return true;
26+
}
1727
}
1828

1929
return false;

0 commit comments

Comments
 (0)