|
1 | 1 | const {NativeModules} = require('react-native');
|
2 | 2 |
|
3 | 3 | export default function shouldFallbackToLegacyNativeModule() {
|
4 |
| - const expoExecutionEnvironment = NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants?.executionEnvironment; |
| 4 | + const expoConstants = |
| 5 | + NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants; |
5 | 6 |
|
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 | + } |
17 | 27 | }
|
18 | 28 |
|
19 | 29 | return false;
|
|
0 commit comments