Swap the native module used when in Expo managed workflow #368
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
Currently tools like AWS Amplify and redux-persist need separate instructions for using AsyncStorage whether you are in an Expo managed project or a bare React Native project, because Expo manage projects do not yet include @react-native-community/async-storage. We would like to include it, but it's a bit trickier than most packages due to complexity around scoping storage access when switching between different projects within the Expo client app.
In order to let library authors just tell people to use @react-native-community/async-storage, I think the easiest solution for now is to swap out the backing native module when in the Expo managed workflow to the solution provided by React Native, which is still included in core as recently as 0.62.2. I did this by moving out the logic for picking which native module to use into
RCTAsyncStorage.js
andRCTAsyncStorage.expo.js
. The.expo.js
extension is only used in the Expo managed workflow (more info if you're curious).As far as I can tell, the API interface is the same and this should not cause any issues. When we update to 0.63 we will likely investigate what it will take to fully integrate this library.
The changes here have no impact on any environment other than Expo managed projects.
Test Plan:
To make this very easy to test I published an alpha version of the package:
@react-native-community/async-storage@1.11.0-alpha.0
.You can test that this works in Expo managed apps by running the following:
npx crna --template blank
@react-native-community/async-storage@1.11.0-alpha.0
yarn ios
and/oryarn android
And in a bare React Native app:
npx react-native init
@react-native-community/async-storage@1.11.0-alpha.0
npx pod-install
yarn ios
and/oryarn android