Skip to content

Commit

Permalink
feat: Swap the native module used when in Expo managed workflow (#368)
Browse files Browse the repository at this point in the history
* Add a .expo.js file to use the built-in react-native RCTAsyncStorage until RNC module ships with it
  • Loading branch information
brentvatne committed May 25, 2020
1 parent 22e7583 commit f9d1924
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
@@ -0,0 +1,2 @@
# Expo managed workflow supported native backend
/src/RCTAsyncStorage.expo.js @brentvatne
7 changes: 1 addition & 6 deletions src/AsyncStorage.native.js
Expand Up @@ -11,12 +11,7 @@

'use strict';

const {NativeModules} = require('react-native');

const RCTAsyncStorage =
NativeModules.PlatformLocalStorage || // Support for external modules, like react-native-windows
NativeModules.RNC_AsyncSQLiteDBStorage ||
NativeModules.RNCAsyncStorage;
import RCTAsyncStorage from './RCTAsyncStorage';

if (!RCTAsyncStorage) {
throw new Error(`[@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.
Expand Down
13 changes: 13 additions & 0 deletions src/RCTAsyncStorage.expo.js
@@ -0,0 +1,13 @@
/**
* Expo managed apps don't include the @react-native-community/async-storage
* native modules yet, but the API interface is the same, so we can use the version
* exported from React Native still.
*
* If in future releases (eg: @react-native-community/async-storage >= 2.0.0) this
* will likely not be valid anymore, and the package will need to be included in the Expo SDK
* to continue to work.
*/
const {NativeModules} = require('react-native');
const RCTAsyncStorage = NativeModules.AsyncSQLiteDBStorage || NativeModules.AsyncLocalStorage;

export default RCTAsyncStorage;
8 changes: 8 additions & 0 deletions src/RCTAsyncStorage.js
@@ -0,0 +1,8 @@
const {NativeModules} = require('react-native');

const RCTAsyncStorage =
NativeModules.PlatformLocalStorage || // Support for external modules, like react-native-windows
NativeModules.RNC_AsyncSQLiteDBStorage ||
NativeModules.RNCAsyncStorage;

export default RCTAsyncStorage;

0 comments on commit f9d1924

Please sign in to comment.