diff --git a/android/build.gradle b/android/build.gradle index 49223bc3..80c3a990 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -127,9 +127,11 @@ android { sourceSets.main { java { - if (!isNewArchitectureEnabled()) { + // TODO removed the codegen config to allow the package to be built under bridgeless + // Once there is a stable API for C++ Turbo Modules, maybe this can be enabled again + // if (!isNewArchitectureEnabled()) { srcDirs += 'src/paper/java' - } + // } } } } diff --git a/android/src/main/java/com/op/sqlite/OPSQLiteModule.kt b/android/src/main/java/com/op/sqlite/OPSQLiteModule.kt index 4ce3952b..d7d3dba9 100644 --- a/android/src/main/java/com/op/sqlite/OPSQLiteModule.kt +++ b/android/src/main/java/com/op/sqlite/OPSQLiteModule.kt @@ -3,26 +3,25 @@ package com.op.sqlite import android.util.Log import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactMethod -import com.facebook.react.module.annotations.ReactModule; +import com.facebook.react.bridge.ReactContextBaseJavaModule import java.io.File import java.io.FileOutputStream import java.io.InputStream import java.io.OutputStream -@ReactModule(name = OPSQLiteModule.NAME) -internal class OPSQLiteModule(context: ReactApplicationContext?) : - NativeOPSQLiteSpec(context) { +//@ReactModule(name = OPSQLiteModule.NAME) +internal class OPSQLiteModule(context: ReactApplicationContext?) : ReactContextBaseJavaModule(context) { override fun getName(): String { return NAME } - override fun getTypedExportedConstants(): MutableMap { + fun getTypedExportedConstants(): MutableMap { val constants: MutableMap = HashMap() val context = reactApplicationContext - val dbPath = context - .getDatabasePath("defaultDatabase") - .absolutePath - .replace("defaultDatabase", "") + val dbPath = + context.getDatabasePath("defaultDatabase") + .absolutePath + .replace("defaultDatabase", "") constants["ANDROID_DATABASE_PATH"] = dbPath val filesPath = context.filesDir.absolutePath constants["ANDROID_FILES_PATH"] = filesPath @@ -33,8 +32,12 @@ internal class OPSQLiteModule(context: ReactApplicationContext?) : return constants } + override fun getConstants(): MutableMap? { + return getTypedExportedConstants() + } + @ReactMethod(isBlockingSynchronousMethod = true) - override fun install(): Boolean { + fun install(): Boolean { return try { OPSQLiteBridge.instance.install(reactApplicationContext) true @@ -45,7 +48,7 @@ internal class OPSQLiteModule(context: ReactApplicationContext?) : } @ReactMethod(isBlockingSynchronousMethod = true) - override fun moveAssetsDatabase(name: String, extension: String): Boolean { + fun moveAssetsDatabase(name: String, extension: String): Boolean { val context = reactApplicationContext val assetsManager = context.assets @@ -54,10 +57,10 @@ internal class OPSQLiteModule(context: ReactApplicationContext?) : val inputStream: InputStream = assetsManager.open("custom/$name.$extension") // Create the output file in the documents directory - val databasesFolder = context - .getDatabasePath("defaultDatabase") - .absolutePath - .replace("defaultDatabase", "") + val databasesFolder = + context.getDatabasePath("defaultDatabase") + .absolutePath + .replace("defaultDatabase", "") val outputFile = File(databasesFolder, "$name.$extension") @@ -85,7 +88,7 @@ internal class OPSQLiteModule(context: ReactApplicationContext?) : } } - override fun invalidate() { + override fun invalidate() { super.invalidate() OPSQLiteBridge.instance.clearState() } @@ -97,4 +100,4 @@ internal class OPSQLiteModule(context: ReactApplicationContext?) : const val NAME = "OPSQLite" } -} \ No newline at end of file +} diff --git a/android/src/main/java/com/op/sqlite/OPSQLitePackage.kt b/android/src/main/java/com/op/sqlite/OPSQLitePackage.kt index e18d5d93..f51a0241 100644 --- a/android/src/main/java/com/op/sqlite/OPSQLitePackage.kt +++ b/android/src/main/java/com/op/sqlite/OPSQLitePackage.kt @@ -1,31 +1,18 @@ package com.op.sqlite -import com.facebook.react.TurboReactPackage +import com.facebook.react.ReactPackage import com.facebook.react.bridge.NativeModule import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.module.model.ReactModuleInfoProvider -import com.facebook.react.module.model.ReactModuleInfo +import com.facebook.react.uimanager.ViewManager -class OPSQLitePackage : TurboReactPackage() { - override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? { - if(name == OPSQLiteModule.NAME) { - return OPSQLiteModule(reactContext) - } else { - return null - } +class OPSQLitePackage : ReactPackage { + override fun createNativeModules(reactContext: ReactApplicationContext): List { + return listOf(OPSQLiteModule(reactContext)) } - override fun getReactModuleInfoProvider() = ReactModuleInfoProvider { - mapOf( - OPSQLiteModule.NAME to ReactModuleInfo( - OPSQLiteModule.NAME, - OPSQLiteModule.NAME, - false, // canOverrideExistingModule - false, // needsEagerInit - true, // hasConstants - false, // isCxxModule - true // isTurboModule - ) - ) + override fun createViewManagers( + reactContext: ReactApplicationContext + ): List> { + return emptyList() } -} \ No newline at end of file +} diff --git a/example/android/app/src/main/kotlin/com/op/sqlite/example/MainApplication.kt b/example/android/app/src/main/kotlin/com/op/sqlite/example/MainApplication.kt index 353273c4..b18cdf1b 100644 --- a/example/android/app/src/main/kotlin/com/op/sqlite/example/MainApplication.kt +++ b/example/android/app/src/main/kotlin/com/op/sqlite/example/MainApplication.kt @@ -1,11 +1,11 @@ -package com.op.sqlite.example; +package com.op.sqlite.example -import android.app.Application; -import com.facebook.react.PackageList; -import com.facebook.react.ReactApplication; +import android.app.Application +import com.facebook.react.PackageList +import com.facebook.react.ReactApplication import com.facebook.react.ReactHost -import com.facebook.react.ReactNativeHost; -import com.facebook.react.ReactPackage; +import com.facebook.react.ReactNativeHost +import com.facebook.react.ReactPackage import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost import com.facebook.react.defaults.DefaultReactNativeHost @@ -15,9 +15,7 @@ class MainApplication : Application(), ReactApplication { override val reactNativeHost: ReactNativeHost = object : DefaultReactNativeHost(this) { - override fun getPackages(): List = - PackageList(this).packages.apply { - } + override fun getPackages(): List = PackageList(this).packages.apply {} override fun getJSMainModuleName(): String = "index" @@ -34,7 +32,7 @@ class MainApplication : Application(), ReactApplication { super.onCreate() SoLoader.init(this, false) if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { - load(bridgelessEnabled = false) + load(bridgelessEnabled = true) } } -} \ No newline at end of file +} diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 709c10cc..106936ed 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -2,5 +2,5 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m android.useAndroidX=true android.enableJetifier=true reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 -newArchEnabled=false +newArchEnabled=true hermesEnabled=true \ No newline at end of file diff --git a/example/ios/OPSQLiteExample/AppDelegate.mm b/example/ios/OPSQLiteExample/AppDelegate.mm index 9409ef44..c07f2788 100644 --- a/example/ios/OPSQLiteExample/AppDelegate.mm +++ b/example/ios/OPSQLiteExample/AppDelegate.mm @@ -34,4 +34,9 @@ - (BOOL)concurrentRootEnabled return true; } +-(BOOL)bridgelessEnabled +{ + return YES; +} + @end diff --git a/ios/OPSQLite.h b/ios/OPSQLite.h index 779f4170..e0a1374f 100644 --- a/ios/OPSQLite.h +++ b/ios/OPSQLite.h @@ -1,15 +1,15 @@ -#ifdef RCT_NEW_ARCH_ENABLED -#import -#else +// #ifdef RCT_NEW_ARCH_ENABLED +// #import +// #else #import -#endif +// #endif @interface OPSQLite : NSObject -#ifdef RCT_NEW_ARCH_ENABLED - -#else +// #ifdef RCT_NEW_ARCH_ENABLED +// +// #else -#endif +// #endif @property(nonatomic, assign) BOOL setBridgeOnMainQueue; diff --git a/ios/OPSQLite.mm b/ios/OPSQLite.mm index a1fe1113..67ffcabe 100644 --- a/ios/OPSQLite.mm +++ b/ios/OPSQLite.mm @@ -94,13 +94,13 @@ - (NSDictionary *)getConstants { return @true; } -#if RCT_NEW_ARCH_ENABLED -- (std::shared_ptr)getTurboModule: - (const facebook::react::ObjCTurboModule::InitParams &)params -{ - return std::make_shared(params); -} -#endif +// #if RCT_NEW_ARCH_ENABLED +// - (std::shared_ptr)getTurboModule: +// (const facebook::react::ObjCTurboModule::InitParams &)params +// { +// return std::make_shared(params); +// } +// #endif - (void)invalidate { opsqlite::clearState(); diff --git a/package.json b/package.json index fc08c0e3..21cdefca 100644 --- a/package.json +++ b/package.json @@ -58,14 +58,6 @@ "react": "*", "react-native": "*" }, - "codegenConfig": { - "name": "OPSQLiteSpec", - "type": "modules", - "jsSrcsDir": "src", - "android": { - "javaPackageName": "com.op.sqlite" - } - }, "prettier": { "quoteProps": "consistent", "singleQuote": true, diff --git a/src/index.ts b/src/index.ts index 4f66f725..343059f9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ -import NativeOPSQLite from './NativeOPSQLite'; +// import NativeOPSQLite from './NativeOPSQLite'; +import { NativeModules } from 'react-native'; declare global { function nativeCallSyncHook(): unknown; @@ -6,18 +7,18 @@ declare global { } if (global.__OPSQLiteProxy == null) { - if (NativeOPSQLite == null) { + if (NativeModules.OPSQLite == null) { throw new Error('Base module not found. Maybe try rebuilding the app.'); } - if (NativeOPSQLite.install == null) { + if (NativeModules.OPSQLite.install == null) { throw new Error( 'Failed to install op-sqlite: React Native is not running on-device. OPSQLite can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.' ); } // Call the synchronous blocking install() function - const result = NativeOPSQLite.install(); + const result = NativeModules.OPSQLite.install(); if (result !== true) { throw new Error( `Failed to install op-sqlite: The native OPSQLite Module could not be installed! Looks like something went wrong when installing JSI bindings, check the native logs for more info` @@ -36,19 +37,14 @@ const proxy = global.__OPSQLiteProxy; export const OPSQLite = proxy as ISQLite; export const { - // @ts-expect-error IOS_DOCUMENT_PATH, - // @ts-expect-error IOS_LIBRARY_PATH, - // @ts-expect-error ANDROID_DATABASE_PATH, - // @ts-expect-error ANDROID_FILES_PATH, - // @ts-expect-error ANDROID_EXTERNAL_FILES_PATH, -} = !!NativeOPSQLite.getConstants - ? NativeOPSQLite.getConstants() - : NativeOPSQLite; +} = !!NativeModules.OPSQLite.getConstants + ? NativeModules.OPSQLite.getConstants() + : NativeModules.OPSQLite; /** * Object returned by SQL Query executions { @@ -472,5 +468,5 @@ export const moveAssetsDatabase = ( dbName: string, extension: string ): boolean => { - return NativeOPSQLite.moveAssetsDatabase(dbName, extension); + return NativeModules.OPSQLite.moveAssetsDatabase(dbName, extension); };