Skip to content

Commit

Permalink
fix: Add support for enabled TurboModules in Expo (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjchmiela authored Aug 16, 2020
1 parent 3f868ca commit ae2c675
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/RCTAsyncStorage.expo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@
* 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;
const {NativeModules, TurboModuleRegistry} = require('react-native');

export default RCTAsyncStorage;
let RCTAsyncStorage;

// TurboModuleRegistry falls back to NativeModules
// so we don't have to try go assign NativeModules'
// counterparts if TurboModuleRegistry would resolve
// with undefined.
if (TurboModuleRegistry) {
RCTAsyncStorage = TurboModuleRegistry.get("AsyncSQLiteDBStorage") || TurboModuleRegistry.get("AsyncLocalStorage");
} else {
RCTAsyncStorage = NativeModules.AsyncSQLiteDBStorage || NativeModules.AsyncLocalStorage;
}

export default RCTAsyncStorage;

0 comments on commit ae2c675

Please sign in to comment.