From 253126d08c9d26e407782995134231639b71bce5 Mon Sep 17 00:00:00 2001 From: Kudo Chien Date: Wed, 28 Feb 2024 17:53:36 +0800 Subject: [PATCH] fix(android): bridgeless mode broken on react-native 0.74 (#1068) --- packages/default-storage/android/build.gradle | 1 + .../asyncstorage/AsyncStoragePackage.java | 11 ++--------- .../asyncstorage/AsyncStoragePackage.kt | 9 +++------ 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/packages/default-storage/android/build.gradle b/packages/default-storage/android/build.gradle index f620adb4..4560dc7d 100644 --- a/packages/default-storage/android/build.gradle +++ b/packages/default-storage/android/build.gradle @@ -62,6 +62,7 @@ android { buildConfigField "Long", "AsyncStorage_db_size", "${project.ext.AsyncStorageConfig.databaseSizeMB}L" buildConfigField "boolean", "AsyncStorage_useDedicatedExecutor", "${project.ext.AsyncStorageConfig.useDedicatedExecutor}" buildConfigField "boolean", "AsyncStorage_useNextStorage", "${useNextStorage}" + buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", "${isNewArchitectureEnabled}" } lintOptions { abortOnError false diff --git a/packages/default-storage/android/src/javaPackage/java/com/reactnativecommunity/asyncstorage/AsyncStoragePackage.java b/packages/default-storage/android/src/javaPackage/java/com/reactnativecommunity/asyncstorage/AsyncStoragePackage.java index 253cd9f0..0b9f2198 100644 --- a/packages/default-storage/android/src/javaPackage/java/com/reactnativecommunity/asyncstorage/AsyncStoragePackage.java +++ b/packages/default-storage/android/src/javaPackage/java/com/reactnativecommunity/asyncstorage/AsyncStoragePackage.java @@ -8,7 +8,6 @@ package com.reactnativecommunity.asyncstorage; import com.facebook.react.TurboReactPackage; -import com.facebook.react.ViewManagerOnDemandReactPackage; import com.facebook.react.bridge.ModuleSpec; import com.facebook.react.bridge.JavaScriptModule; import com.facebook.react.bridge.NativeModule; @@ -17,7 +16,6 @@ import com.facebook.react.module.annotations.ReactModuleList; import com.facebook.react.module.model.ReactModuleInfo; import com.facebook.react.module.model.ReactModuleInfoProvider; -import com.facebook.react.turbomodule.core.interfaces.TurboModule; import com.facebook.react.uimanager.ViewManager; import java.util.Collections; import java.util.HashMap; @@ -25,7 +23,6 @@ import java.util.Map; import javax.annotation.Nonnull; -import javax.annotation.Nullable; @ReactModuleList( nativeModules = { @@ -62,6 +59,7 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() { @Override public Map getReactModuleInfos() { final Map reactModuleInfoMap = new HashMap<>(); + boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; Class[] moduleList = new Class[] { @@ -80,7 +78,7 @@ public Map getReactModuleInfos() { reactModule.needsEagerInit(), reactModule.hasConstants(), reactModule.isCxxModule(), - TurboModule.class.isAssignableFrom(moduleClass))); + isTurboModule)); } return reactModuleInfoMap; @@ -92,11 +90,6 @@ public Map getReactModuleInfos() { } } - // Deprecated in RN 0.47 - public List> createJSModules() { - return Collections.emptyList(); - } - @Override @SuppressWarnings("rawtypes") public List createViewManagers(ReactApplicationContext reactContext) { diff --git a/packages/default-storage/android/src/kotlinPackage/java/com/reactnativecommunity/asyncstorage/AsyncStoragePackage.kt b/packages/default-storage/android/src/kotlinPackage/java/com/reactnativecommunity/asyncstorage/AsyncStoragePackage.kt index f8d26b6e..0ddacf1b 100644 --- a/packages/default-storage/android/src/kotlinPackage/java/com/reactnativecommunity/asyncstorage/AsyncStoragePackage.kt +++ b/packages/default-storage/android/src/kotlinPackage/java/com/reactnativecommunity/asyncstorage/AsyncStoragePackage.kt @@ -1,7 +1,6 @@ package com.reactnativecommunity.asyncstorage import com.facebook.react.TurboReactPackage -import com.facebook.react.ViewManagerOnDemandReactPackage import com.facebook.react.bridge.ModuleSpec import com.facebook.react.bridge.NativeModule import com.facebook.react.bridge.ReactApplicationContext @@ -9,9 +8,6 @@ import com.facebook.react.module.annotations.ReactModule import com.facebook.react.module.annotations.ReactModuleList import com.facebook.react.module.model.ReactModuleInfo import com.facebook.react.module.model.ReactModuleInfoProvider -import com.facebook.react.turbomodule.core.interfaces.TurboModule -import com.facebook.react.uimanager.ReactShadowNode -import com.facebook.react.uimanager.ViewManager import com.reactnativecommunity.asyncstorage.next.StorageModule @ReactModuleList( @@ -32,10 +28,11 @@ class AsyncStoragePackage : TurboReactPackage() { return reactModuleInfoProviderClass.newInstance() as ReactModuleInfoProvider } catch (e: ClassNotFoundException) { return ReactModuleInfoProvider { + val isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED val reactModule: ReactModule = StorageModule::class.java.getAnnotation( ReactModule::class.java)!! - mutableMapOf( + mapOf( StorageModule.NAME to ReactModuleInfo( reactModule.name, StorageModule::class.java.name, @@ -43,7 +40,7 @@ class AsyncStoragePackage : TurboReactPackage() { reactModule.needsEagerInit, reactModule.hasConstants, reactModule.isCxxModule, - TurboModule::class.java.isAssignableFrom(StorageModule::class.java) + isTurboModule ) ) }