Skip to content

Commit 62732d9

Browse files
authored
fix: allow consumption of RCTAsyncStorage as TurboModule (#965)
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.
1 parent d68a48d commit 62732d9

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/RCTAsyncStorage.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
import { NativeModules, TurboModuleRegistry } from 'react-native';
33
import { shouldFallbackToLegacyNativeModule } from './shouldFallbackToLegacyNativeModule';
44

5-
let RCTAsyncStorage =
6-
NativeModules['PlatformLocalStorage'] || // Support for external modules, like react-native-windows
7-
NativeModules['RNC_AsyncSQLiteDBStorage'] ||
8-
NativeModules['RNCAsyncStorage'];
5+
// TurboModuleRegistry falls back to NativeModules so we don't have to try go
6+
// assign NativeModules' counterparts if TurboModuleRegistry would resolve
7+
// with undefined.
8+
let RCTAsyncStorage = TurboModuleRegistry
9+
? TurboModuleRegistry.get('PlatformLocalStorage') || // Support for external modules, like react-native-windows
10+
TurboModuleRegistry.get('RNC_AsyncSQLiteDBStorage') ||
11+
TurboModuleRegistry.get('RNCAsyncStorage')
12+
: NativeModules['PlatformLocalStorage'] || // Support for external modules, like react-native-windows
13+
NativeModules['RNC_AsyncSQLiteDBStorage'] ||
14+
NativeModules['RNCAsyncStorage'];
915

1016
if (!RCTAsyncStorage && shouldFallbackToLegacyNativeModule()) {
11-
// TurboModuleRegistry falls back to NativeModules so we don't have to try go
12-
// assign NativeModules' counterparts if TurboModuleRegistry would resolve
13-
// with undefined.
1417
if (TurboModuleRegistry) {
1518
RCTAsyncStorage =
1619
TurboModuleRegistry.get('AsyncSQLiteDBStorage') ||

0 commit comments

Comments
 (0)