Skip to content

Commit f9d1924

Browse files
authored
feat: Swap the native module used when in Expo managed workflow (#368)
* Add a .expo.js file to use the built-in react-native RCTAsyncStorage until RNC module ships with it
1 parent 22e7583 commit f9d1924

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Expo managed workflow supported native backend
2+
/src/RCTAsyncStorage.expo.js @brentvatne

src/AsyncStorage.native.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@
1111

1212
'use strict';
1313

14-
const {NativeModules} = require('react-native');
15-
16-
const RCTAsyncStorage =
17-
NativeModules.PlatformLocalStorage || // Support for external modules, like react-native-windows
18-
NativeModules.RNC_AsyncSQLiteDBStorage ||
19-
NativeModules.RNCAsyncStorage;
14+
import RCTAsyncStorage from './RCTAsyncStorage';
2015

2116
if (!RCTAsyncStorage) {
2217
throw new Error(`[@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.

src/RCTAsyncStorage.expo.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Expo managed apps don't include the @react-native-community/async-storage
3+
* native modules yet, but the API interface is the same, so we can use the version
4+
* exported from React Native still.
5+
*
6+
* If in future releases (eg: @react-native-community/async-storage >= 2.0.0) this
7+
* will likely not be valid anymore, and the package will need to be included in the Expo SDK
8+
* to continue to work.
9+
*/
10+
const {NativeModules} = require('react-native');
11+
const RCTAsyncStorage = NativeModules.AsyncSQLiteDBStorage || NativeModules.AsyncLocalStorage;
12+
13+
export default RCTAsyncStorage;

src/RCTAsyncStorage.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const {NativeModules} = require('react-native');
2+
3+
const RCTAsyncStorage =
4+
NativeModules.PlatformLocalStorage || // Support for external modules, like react-native-windows
5+
NativeModules.RNC_AsyncSQLiteDBStorage ||
6+
NativeModules.RNCAsyncStorage;
7+
8+
export default RCTAsyncStorage;

0 commit comments

Comments
 (0)