Skip to content

Commit

Permalink
fix: allow consumption of RCTAsyncStorage as TurboModule (#965)
Browse files Browse the repository at this point in the history
In react-native-windows, attributed C++ modules can be consumed as
either a legacy native module or TurboModule. This change enables
registration of RNCAsyncStorage as a TurboModule.
  • Loading branch information
rozele authored Jun 6, 2023
1 parent d68a48d commit 62732d9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/RCTAsyncStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
import { NativeModules, TurboModuleRegistry } from 'react-native';
import { shouldFallbackToLegacyNativeModule } from './shouldFallbackToLegacyNativeModule';

let RCTAsyncStorage =
NativeModules['PlatformLocalStorage'] || // Support for external modules, like react-native-windows
NativeModules['RNC_AsyncSQLiteDBStorage'] ||
NativeModules['RNCAsyncStorage'];
// TurboModuleRegistry falls back to NativeModules so we don't have to try go
// assign NativeModules' counterparts if TurboModuleRegistry would resolve
// with undefined.
let RCTAsyncStorage = TurboModuleRegistry
? TurboModuleRegistry.get('PlatformLocalStorage') || // Support for external modules, like react-native-windows
TurboModuleRegistry.get('RNC_AsyncSQLiteDBStorage') ||
TurboModuleRegistry.get('RNCAsyncStorage')
: NativeModules['PlatformLocalStorage'] || // Support for external modules, like react-native-windows
NativeModules['RNC_AsyncSQLiteDBStorage'] ||
NativeModules['RNCAsyncStorage'];

if (!RCTAsyncStorage && shouldFallbackToLegacyNativeModule()) {
// 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') ||
Expand Down

0 comments on commit 62732d9

Please sign in to comment.