From d4845180386aba2c5f46c9eb501dfa398c0a0a7a Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 4 Oct 2024 13:07:05 +0200 Subject: [PATCH 01/12] enable newarch --- .../java/com/margelo/rnquicksqlite/example/MainApplication.kt | 2 +- example/android/gradle.properties | 2 +- example/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example/android/app/src/main/java/com/margelo/rnquicksqlite/example/MainApplication.kt b/example/android/app/src/main/java/com/margelo/rnquicksqlite/example/MainApplication.kt index 03141fa..dae4b34 100644 --- a/example/android/app/src/main/java/com/margelo/rnquicksqlite/example/MainApplication.kt +++ b/example/android/app/src/main/java/com/margelo/rnquicksqlite/example/MainApplication.kt @@ -37,7 +37,7 @@ class MainApplication : Application(), ReactApplication { SoLoader.init(this, false) if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { // If you opted-in for the New Architecture, we load the native entry point for this app. - load(bridgelessEnabled=false) + load() } } } diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 9fb1566..5e24e3a 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -32,7 +32,7 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 # your application. You should enable this flag either if you want # to write custom TurboModules/Fabric components OR use libraries that # are providing them. -newArchEnabled=false +newArchEnabled=true # Use this property to enable or disable the Hermes JS engine. # If set to false, you will be using JSC instead. diff --git a/example/package.json b/example/package.json index d7441d2..bc0a360 100644 --- a/example/package.json +++ b/example/package.json @@ -3,7 +3,7 @@ "version": "8.1.0", "private": true, "scripts": { - "pods": "cd ios && bundle exec pod install", + "pods": "cd ios && RCT_NEW_ARCH_ENABLED=1 bundle exec pod install", "android": "react-native run-android", "ios": "react-native run-ios", "start": "react-native start", From f2efc3b53d27ba347bbd279092e7c9ceeda90033 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 4 Oct 2024 14:10:55 +0200 Subject: [PATCH 02/12] add turbomodule for init --- ...dule.java => RNQuickSQLiteInitModule.java} | 26 +++------- .../rnquicksqlite/RNQuickSQLitePackage.java | 48 +++++++++++++++++++ .../margelo/rnquicksqlite/SequelPackage.java | 24 ---------- package/package.json | 8 ++++ package/src/NativeRNQuickSQLiteInit.ts | 7 +++ package/src/index.ts | 22 ++++----- 6 files changed, 80 insertions(+), 55 deletions(-) rename package/android/src/main/java/com/margelo/rnquicksqlite/{SequelModule.java => RNQuickSQLiteInitModule.java} (50%) create mode 100644 package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLitePackage.java delete mode 100644 package/android/src/main/java/com/margelo/rnquicksqlite/SequelPackage.java create mode 100644 package/src/NativeRNQuickSQLiteInit.ts diff --git a/package/android/src/main/java/com/margelo/rnquicksqlite/SequelModule.java b/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java similarity index 50% rename from package/android/src/main/java/com/margelo/rnquicksqlite/SequelModule.java rename to package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java index b0237f7..91de72f 100644 --- a/package/android/src/main/java/com/margelo/rnquicksqlite/SequelModule.java +++ b/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java @@ -1,25 +1,22 @@ package com.margelo.rnquicksqlite; -import androidx.annotation.NonNull; import android.util.Log; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.bridge.ReactContextBaseJavaModule; -import com.facebook.react.bridge.ReactMethod; -class SequelModule extends ReactContextBaseJavaModule { - public static final String NAME = "QuickSQLite"; +import androidx.annotation.NonNull; +import com.facebook.react.bridge.ReactApplicationContext; - public SequelModule(ReactApplicationContext context) { - super(context); +public class RNQuickSQLiteInitModule extends NativeQuickSQLiteInitSpec { + public RNQuickSQLiteInitModule(ReactApplicationContext reactContext) { + super(reactContext); } - @NonNull @Override + @NonNull public String getName() { return NAME; } - @ReactMethod(isBlockingSynchronousMethod = true) + @Override public boolean install() { try { System.loadLibrary("react-native-quick-sqlite"); @@ -30,13 +27,4 @@ public boolean install() { return false; } } - - @Override - public void onCatalystInstanceDestroy() { - try { - QuickSQLiteBridge.instance.clearState(); - } catch (Exception exception) { - Log.e(NAME, "Failed to clear state!", exception); - } - } } diff --git a/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLitePackage.java b/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLitePackage.java new file mode 100644 index 0000000..e86ca34 --- /dev/null +++ b/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLitePackage.java @@ -0,0 +1,48 @@ +package com.margelo.rnquicksqlite; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.module.model.ReactModuleInfo; +import com.facebook.react.module.model.ReactModuleInfoProvider; +import com.facebook.react.TurboReactPackage; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class RNQuickSQLitePackage extends TurboReactPackage { + static { + System.loadLibrary("RNQuickSQLite"); + } + + @Nullable + @Override + public NativeModule getModule(String name, ReactApplicationContext reactContext) { + if (name.equals(RNQuickSQLiteInitModule.NAME)) { + return new RNQuickSQLiteInitModule(reactContext); + } else { + return null; + } + } + + @Override + public ReactModuleInfoProvider getReactModuleInfoProvider() { + return () -> { + final Map moduleInfos = new HashMap<>(); + moduleInfos.put( + RNQuickSQLiteInitModule.NAME, + new ReactModuleInfo( + RNQuickSQLiteInitModule.NAME, + RNQuickSQLiteInitModule.NAME, + false, + true, + true, + false, + true)); + return moduleInfos; + }; + } +} diff --git a/package/android/src/main/java/com/margelo/rnquicksqlite/SequelPackage.java b/package/android/src/main/java/com/margelo/rnquicksqlite/SequelPackage.java deleted file mode 100644 index 8c2a2fa..0000000 --- a/package/android/src/main/java/com/margelo/rnquicksqlite/SequelPackage.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.margelo.rnquicksqlite; - -import androidx.annotation.NonNull; - -import com.facebook.react.ReactPackage; -import com.facebook.react.bridge.NativeModule; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.uimanager.ViewManager; -import java.util.Collections; -import java.util.List; - -public class SequelPackage implements ReactPackage { - @NonNull - @Override - public List createNativeModules(@NonNull ReactApplicationContext reactContext) { - return Collections.singletonList(new SequelModule(reactContext)); - } - - @NonNull - @Override - public List createViewManagers(@NonNull ReactApplicationContext reactContext) { - return Collections.emptyList(); - } -} diff --git a/package/package.json b/package/package.json index 2a4b162..0ed604a 100644 --- a/package/package.json +++ b/package/package.json @@ -61,6 +61,14 @@ "react": "*", "react-native": ">=0.74.0" }, + "codegenConfig": { + "name": "RNQuickSQLite", + "type": "modules", + "jsSrcsDir": "src", + "android": { + "javaPackageName": "com.margelo.rnquicksqlite" + } + }, "react-native-builder-bob": { "source": "src", "output": "lib", diff --git a/package/src/NativeRNQuickSQLiteInit.ts b/package/src/NativeRNQuickSQLiteInit.ts new file mode 100644 index 0000000..5f766d0 --- /dev/null +++ b/package/src/NativeRNQuickSQLiteInit.ts @@ -0,0 +1,7 @@ +import { TurboModuleRegistry, type TurboModule } from 'react-native' + +export interface Spec extends TurboModule { + install(): boolean +} + +export default TurboModuleRegistry.getEnforcing('RNQuickSQLiteInit') diff --git a/package/src/index.ts b/package/src/index.ts index 1bbcdca..4ae8a5a 100644 --- a/package/src/index.ts +++ b/package/src/index.ts @@ -1,14 +1,14 @@ +/* eslint-disable @typescript-eslint/no-unnecessary-condition */ +/* eslint-disable no-var */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ /* eslint-disable no-return-await */ /* eslint-disable @typescript-eslint/strict-boolean-expressions */ /* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ + /* eslint-disable @typescript-eslint/no-unsafe-call */ -/* eslint-disable @typescript-eslint/no-unnecessary-condition */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable no-var */ -import { NativeModules } from 'react-native' + +import RNQuickSQLiteInit from './NativeRNQuickSQLiteInit' declare global { function nativeCallSyncHook(): unknown @@ -16,26 +16,24 @@ declare global { } if (global.__QuickSQLiteProxy == null) { - const QuickSQLiteModule = NativeModules.QuickSQLite - - if (QuickSQLiteModule == null) { + if (RNQuickSQLiteInit == null) { throw new Error( - 'Base quick-sqlite module not found. Maybe try rebuilding the app.' + 'QuickSQLite TurboModule not found. Maybe try rebuilding the app.' ) } // Check if we are running on-device (JSI) - if (global.nativeCallSyncHook == null || QuickSQLiteModule.install == null) { + if (global.nativeCallSyncHook == null || RNQuickSQLiteInit.install == null) { throw new Error( 'Failed to install react-native-quick-sqlite: React Native is not running on-device. QuickSQLite 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 = QuickSQLiteModule.install() + const result = RNQuickSQLiteInit.install() if (result !== true) { throw new Error( - `Failed to install react-native-quick-sqlite: The native QuickSQLite Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}` + `Failed to install react-native-quick-sqlite: The QuickSQLite TurboModule could not be installed! Looks like something went wrong when installing JSI bindings: ${result}` ) } From e01591ce8da4d34a3c35b15e99201544bb5370ce Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 4 Oct 2024 14:13:36 +0200 Subject: [PATCH 03/12] fix: spec name --- .../java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java b/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java index c71265d..67720bf 100644 --- a/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java +++ b/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java @@ -5,7 +5,7 @@ import androidx.annotation.NonNull; import com.facebook.react.bridge.ReactApplicationContext; -public class RNQuickSQLiteInitModule extends NativeQuickSQLiteInitSpec { +public class RNQuickSQLiteInitModule extends NativeRNQuickSQLiteInitSpec { public RNQuickSQLiteInitModule(ReactApplicationContext reactContext) { super(reactContext); } From c2fa3fd8540db60680c23ff92c2c7774f7c3c2a3 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 4 Oct 2024 14:21:01 +0200 Subject: [PATCH 04/12] initialize using TurboModule --- .../margelo/rnquicksqlite/RNQuickSQLiteInitModule.java | 1 - package/src/index.ts | 10 ++-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java b/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java index 67720bf..bb96681 100644 --- a/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java +++ b/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java @@ -19,7 +19,6 @@ public String getName() { @Override public boolean install() { try { - System.loadLibrary("RNQuickSQLite"); QuickSQLiteBridge.instance.install(getReactApplicationContext()); return true; } catch (Exception exception) { diff --git a/package/src/index.ts b/package/src/index.ts index 4ae8a5a..2c6562d 100644 --- a/package/src/index.ts +++ b/package/src/index.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/prefer-optional-chain */ /* eslint-disable @typescript-eslint/no-unnecessary-condition */ /* eslint-disable no-var */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ @@ -16,19 +17,12 @@ declare global { } if (global.__QuickSQLiteProxy == null) { - if (RNQuickSQLiteInit == null) { + if (RNQuickSQLiteInit == null || RNQuickSQLiteInit.install == null) { throw new Error( 'QuickSQLite TurboModule not found. Maybe try rebuilding the app.' ) } - // Check if we are running on-device (JSI) - if (global.nativeCallSyncHook == null || RNQuickSQLiteInit.install == null) { - throw new Error( - 'Failed to install react-native-quick-sqlite: React Native is not running on-device. QuickSQLite 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 = RNQuickSQLiteInit.install() if (result !== true) { From 35edd286ce3ff52103e956cc727ccbc2686480cf Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 4 Oct 2024 15:38:19 +0200 Subject: [PATCH 05/12] async --- example/ios/Podfile.lock | 107 ++++++++++++++++-- .../RNQuickSQLiteInitModule.java | 8 +- package/ios/QuickSQLite.h | 9 +- package/ios/QuickSQLite.mm | 33 +++--- package/src/NativeRNQuickSQLiteInit.ts | 2 +- package/src/index.ts | 33 +++--- 6 files changed, 142 insertions(+), 50 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 4456226..85d185b 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1259,7 +1259,71 @@ PODS: - ReactCommon/turbomodule/core - Yoga - react-native-safe-area-context (4.11.0): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.01.01.00) + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - react-native-safe-area-context/common (= 4.11.0) + - react-native-safe-area-context/fabric (= 4.11.0) + - React-NativeModulesApple + - React-RCTFabric + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - Yoga + - react-native-safe-area-context/common (4.11.0): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.01.01.00) + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - React-NativeModulesApple + - React-RCTFabric + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - Yoga + - react-native-safe-area-context/fabric (4.11.0): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.01.01.00) + - RCTRequired + - RCTTypeSafety - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - react-native-safe-area-context/common + - React-NativeModulesApple + - React-RCTFabric + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - Yoga - React-nativeconfig (0.75.2) - React-NativeModulesApple (0.75.2): - glog @@ -1521,6 +1585,29 @@ PODS: - React-perflogger (= 0.75.2) - React-utils (= 0.75.2) - RNScreens (3.34.0): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.01.01.00) + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - React-NativeModulesApple + - React-RCTFabric + - React-RCTImage + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - RNScreens/common (= 3.34.0) + - Yoga + - RNScreens/common (3.34.0): - DoubleConversion - glog - hermes-engine @@ -1768,16 +1855,16 @@ SPEC CHECKSUMS: React-CoreModules: f92a2cb11d22f6066823ca547c61e900325dfe44 React-cxxreact: f5595a4cbfe5a4e9d401dffa2c1c78bbbbbe75e4 React-debug: 4a91c177b5b2efcc546fb50bc2f676f3f589efab - React-defaultsnativemodule: bb94c3db425b01c760f41a253de8536b3f5497f0 - React-domnativemodule: 6c581fd39812cafb024171e091c00905b2c3a3e2 + React-defaultsnativemodule: 6b666572abf5fe7fe87836a42776abd6ad5ed173 + React-domnativemodule: 785d767c4edbb9f011b8c976271077759ca5c4aa React-Fabric: a33cc1fdc62a3085774783bb30970531589d2028 React-FabricComponents: 98de5f94cbd35d407f4fc78855298b562d8289cb React-FabricImage: 0ce8fd83844d9edef5825116d38f0e208b9ad786 React-featureflags: 37a78859ad71db758e2efdcbdb7384afefa8701e - React-featureflagsnativemodule: 52b46e161a151b4653cf1762285e8e899d534e3f + React-featureflagsnativemodule: f94aacb52c463e200ee185bff90ae3b392e60263 React-graphics: c16f1bab97a5d473831a79360d84300e93a614e5 React-hermes: 7801f8c0e12f326524b461dc368d3e74f3d2a385 - React-idlecallbacksnativemodule: 58de2ac968ee80947d19dc8fe20def607e5c2de8 + React-idlecallbacksnativemodule: d81bb7b5d26cea9852a8edc6ad1979cd7ed0841f React-ImageManager: 98a1e5b0b05528dde47ebcd953d916ac66d46c09 React-jserrorhandler: 08f1c3465a71a6549c27ad82809ce145ad52d4f1 React-jsi: 161428ab2c706d5fcd9878d260ff1513fdb356ab @@ -1786,18 +1873,18 @@ SPEC CHECKSUMS: React-jsitracing: 52b849a77d02e2dc262a3031454c23be8dabb4d9 React-logger: 8db32983d75dc2ad54f278f344ccb9b256e694fc React-Mapbuffer: 1c08607305558666fd16678b85ef135e455d5c96 - React-microtasksnativemodule: 87b8de96f937faefece8afd2cb3a518321b2ef99 - react-native-quick-sqlite: b681131e6c1a741be3c928beba30722efbd4933b - react-native-safe-area-context: 851c62c48dce80ccaa5637b6aa5991a1bc36eca9 + React-microtasksnativemodule: f13f03163b6a5ec66665dfe80a0df4468bb766a6 + react-native-quick-sqlite: 9d2ea1b980fff3b5a39c61db61731ff405f0ce13 + react-native-safe-area-context: f1fda705dfe14355f41933debb5932887e234cc5 React-nativeconfig: 57781b79e11d5af7573e6f77cbf1143b71802a6d React-NativeModulesApple: 7ff2e2cfb2e5fa5bdedcecf28ce37e696c6ef1e1 React-perflogger: 8a360ccf603de6ddbe9ff8f54383146d26e6c936 React-performancetimeline: 3cfec915adcb3653a5a633b41e711903844c35d8 React-RCTActionSheet: 1c0e26a88eec41215089cf4436e38188cfe9f01a React-RCTAnimation: d87207841b1e2ae1389e684262ea8c73c887cb04 - React-RCTAppDelegate: 4ec7824c0cc9cc4b146ca8ee0fd81b10c316a440 + React-RCTAppDelegate: 328e56399c4f1c3d20cfe547ea24ebded2b3a87f React-RCTBlob: 79b42cb7db55f34079297687a480dbcf37f023f6 - React-RCTFabric: 1dd1661db93716f8cb116e451bd9c211a8d15716 + React-RCTFabric: 27636a6a5fa5622159297fce26881945d3658cf6 React-RCTImage: 0c10a75de59f7384a2a55545d5f36fe783e6ecda React-RCTLinking: bf08f4f655bf777af292b8d97449072c8bb196ca React-RCTNetwork: 1b690846b40fc5685af58e088720657db6814637 @@ -1815,7 +1902,7 @@ SPEC CHECKSUMS: React-utils: 81a715d9c0a2a49047e77a86f3a2247408540deb ReactCodegen: 4eedb2fdd079174d6fc3c80b1cccafbe4ff1be8d ReactCommon: 6ef348087d250257c44c0204461c03f036650e9b - RNScreens: 19719a9c326e925498ac3b2d35c4e50fe87afc06 + RNScreens: de6e57426ba0e6cbc3fb5b4f496e7f08cb2773c2 SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d Yoga: a1d7895431387402a674fd0d1c04ec85e87909b8 diff --git a/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java b/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java index bb96681..0cfeedb 100644 --- a/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java +++ b/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java @@ -3,6 +3,8 @@ import android.util.Log; import androidx.annotation.NonNull; + +import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; public class RNQuickSQLiteInitModule extends NativeRNQuickSQLiteInitSpec { @@ -17,13 +19,13 @@ public String getName() { } @Override - public boolean install() { + public void install(Promise promise) { try { QuickSQLiteBridge.instance.install(getReactApplicationContext()); - return true; + promise.resolve(true); } catch (Exception exception) { Log.e(NAME, "Failed to install JSI Bindings!", exception); - return false; + promise.resolve(false); } } } diff --git a/package/ios/QuickSQLite.h b/package/ios/QuickSQLite.h index 3276c8f..6590556 100644 --- a/package/ios/QuickSQLite.h +++ b/package/ios/QuickSQLite.h @@ -1,8 +1,11 @@ -#import -#import +#import -@interface QuickSQLite : NSObject +NS_ASSUME_NONNULL_BEGIN + +@interface RNQuickSQLiteInit : NSObject @property(nonatomic, assign) BOOL setBridgeOnMainQueue; @end + +NS_ASSUME_NONNULL_END diff --git a/package/ios/QuickSQLite.mm b/package/ios/QuickSQLite.mm index 519f31a..a0e6b96 100644 --- a/package/ios/QuickSQLite.mm +++ b/package/ios/QuickSQLite.mm @@ -1,32 +1,34 @@ -#import "QuickSQLite.h" - -#import - #import +#import #import #import - +#import "QuickSQLite.h" #import "../cpp/bindings.h" +using namespace facebook; + @implementation QuickSQLite -RCT_EXPORT_MODULE(QuickSQLite) +RCT_EXPORT_MODULE() +- (std::shared_ptr)getTurboModule: + (const facebook::react::ObjCTurboModule::InitParams &)params +{ + return std::make_shared(params); +} -RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) { +- (void)install:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { NSLog(@"Installing QuickSQLite module..."); RCTBridge *bridge = [RCTBridge currentBridge]; RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge; if (cxxBridge == nil) { - return @false; + return resolve(@false); } - using namespace facebook; - auto jsiRuntime = (jsi::Runtime *)cxxBridge.runtime; if (jsiRuntime == nil) { - return @false; + return resolve(@false); } auto &runtime = *jsiRuntime; auto callInvoker = bridge.jsCallInvoker; @@ -42,7 +44,7 @@ @implementation QuickSQLite if (storeUrl == nil) { NSLog(@"Invalid AppGroup ID provided (%@). Check the value of \"AppGroup\" in your Info.plist file", appGroupID); - return @false; + return resolve(@false); } NSLog(@"Configured with AppGroup ID: %@", appGroupID); @@ -54,12 +56,7 @@ @implementation QuickSQLite } osp::install(runtime, callInvoker, [documentPath UTF8String]); - return @true; + return resolve(@true); } -- (void)invalidate { - osp::clearState(); -} - - @end diff --git a/package/src/NativeRNQuickSQLiteInit.ts b/package/src/NativeRNQuickSQLiteInit.ts index 5f766d0..3f06472 100644 --- a/package/src/NativeRNQuickSQLiteInit.ts +++ b/package/src/NativeRNQuickSQLiteInit.ts @@ -1,7 +1,7 @@ import { TurboModuleRegistry, type TurboModule } from 'react-native' export interface Spec extends TurboModule { - install(): boolean + install(): Promise } export default TurboModuleRegistry.getEnforcing('RNQuickSQLiteInit') diff --git a/package/src/index.ts b/package/src/index.ts index 2c6562d..324771d 100644 --- a/package/src/index.ts +++ b/package/src/index.ts @@ -16,6 +16,8 @@ declare global { var __QuickSQLiteProxy: object | undefined } +export let QuickSQLite: ISQLite | null + if (global.__QuickSQLiteProxy == null) { if (RNQuickSQLiteInit == null || RNQuickSQLiteInit.install == null) { throw new Error( @@ -24,23 +26,24 @@ if (global.__QuickSQLiteProxy == null) { } // Call the synchronous blocking install() function - const result = RNQuickSQLiteInit.install() - if (result !== true) { - throw new Error( - `Failed to install react-native-quick-sqlite: The QuickSQLite TurboModule could not be installed! Looks like something went wrong when installing JSI bindings: ${result}` - ) - } + RNQuickSQLiteInit.install().then((result) => { + if (result !== true) { + throw new Error( + `Failed to install react-native-quick-sqlite: The QuickSQLite TurboModule could not be installed! Looks like something went wrong when installing JSI bindings: ${result}` + ) + } - // Check again if the constructor now exists. If not, throw an error. - if (global.__QuickSQLiteProxy == null) { - throw new Error( - 'Failed to install react-native-quick-sqlite, the native initializer function does not exist. Are you trying to use QuickSQLite from different JS Runtimes?' - ) - } -} + // Check again if the constructor now exists. If not, throw an error. + if (global.__QuickSQLiteProxy == null) { + throw new Error( + 'Failed to install react-native-quick-sqlite, the native initializer function does not exist. Are you trying to use QuickSQLite from different JS Runtimes?' + ) + } -const proxy = global.__QuickSQLiteProxy -export const QuickSQLite = proxy as ISQLite + QuickSQLite = global.__QuickSQLiteProxy as ISQLite + }) +} +QuickSQLite = global.__QuickSQLiteProxy as ISQLite /** * Object returned by SQL Query executions { From e2a463f5c33e93ad351afa6dcf47267d947d2bc2 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 4 Oct 2024 15:38:24 +0200 Subject: [PATCH 06/12] sync --- .../RNQuickSQLiteInitModule.java | 6 ++-- package/ios/QuickSQLite.mm | 12 +++---- package/src/NativeRNQuickSQLiteInit.ts | 2 +- package/src/index.ts | 32 ++++++++----------- 4 files changed, 23 insertions(+), 29 deletions(-) diff --git a/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java b/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java index 0cfeedb..d533f62 100644 --- a/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java +++ b/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java @@ -19,13 +19,13 @@ public String getName() { } @Override - public void install(Promise promise) { + public boolean install() { try { QuickSQLiteBridge.instance.install(getReactApplicationContext()); - promise.resolve(true); + return true; } catch (Exception exception) { Log.e(NAME, "Failed to install JSI Bindings!", exception); - promise.resolve(false); + return false; } } } diff --git a/package/ios/QuickSQLite.mm b/package/ios/QuickSQLite.mm index a0e6b96..610d097 100644 --- a/package/ios/QuickSQLite.mm +++ b/package/ios/QuickSQLite.mm @@ -7,7 +7,7 @@ using namespace facebook; -@implementation QuickSQLite +@implementation RNQuickSQLiteInit RCT_EXPORT_MODULE() @@ -17,18 +17,18 @@ @implementation QuickSQLite return std::make_shared(params); } -- (void)install:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { +- (NSNumber *) install { NSLog(@"Installing QuickSQLite module..."); RCTBridge *bridge = [RCTBridge currentBridge]; RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge; if (cxxBridge == nil) { - return resolve(@false); + return @false; } auto jsiRuntime = (jsi::Runtime *)cxxBridge.runtime; if (jsiRuntime == nil) { - return resolve(@false); + return @false; } auto &runtime = *jsiRuntime; auto callInvoker = bridge.jsCallInvoker; @@ -44,7 +44,7 @@ - (void)install:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)re if (storeUrl == nil) { NSLog(@"Invalid AppGroup ID provided (%@). Check the value of \"AppGroup\" in your Info.plist file", appGroupID); - return resolve(@false); + return @false; } NSLog(@"Configured with AppGroup ID: %@", appGroupID); @@ -56,7 +56,7 @@ - (void)install:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)re } osp::install(runtime, callInvoker, [documentPath UTF8String]); - return resolve(@true); + return @true; } @end diff --git a/package/src/NativeRNQuickSQLiteInit.ts b/package/src/NativeRNQuickSQLiteInit.ts index 3f06472..5f766d0 100644 --- a/package/src/NativeRNQuickSQLiteInit.ts +++ b/package/src/NativeRNQuickSQLiteInit.ts @@ -1,7 +1,7 @@ import { TurboModuleRegistry, type TurboModule } from 'react-native' export interface Spec extends TurboModule { - install(): Promise + install(): boolean } export default TurboModuleRegistry.getEnforcing('RNQuickSQLiteInit') diff --git a/package/src/index.ts b/package/src/index.ts index 324771d..ccfdebb 100644 --- a/package/src/index.ts +++ b/package/src/index.ts @@ -6,7 +6,6 @@ /* eslint-disable @typescript-eslint/strict-boolean-expressions */ /* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-explicit-any */ - /* eslint-disable @typescript-eslint/no-unsafe-call */ import RNQuickSQLiteInit from './NativeRNQuickSQLiteInit' @@ -16,8 +15,6 @@ declare global { var __QuickSQLiteProxy: object | undefined } -export let QuickSQLite: ISQLite | null - if (global.__QuickSQLiteProxy == null) { if (RNQuickSQLiteInit == null || RNQuickSQLiteInit.install == null) { throw new Error( @@ -26,24 +23,21 @@ if (global.__QuickSQLiteProxy == null) { } // Call the synchronous blocking install() function - RNQuickSQLiteInit.install().then((result) => { - if (result !== true) { - throw new Error( - `Failed to install react-native-quick-sqlite: The QuickSQLite TurboModule could not be installed! Looks like something went wrong when installing JSI bindings: ${result}` - ) - } - - // Check again if the constructor now exists. If not, throw an error. - if (global.__QuickSQLiteProxy == null) { - throw new Error( - 'Failed to install react-native-quick-sqlite, the native initializer function does not exist. Are you trying to use QuickSQLite from different JS Runtimes?' - ) - } + const result = RNQuickSQLiteInit.install() + if (result !== true) { + throw new Error( + `Failed to install react-native-quick-sqlite: The QuickSQLite TurboModule could not be installed! Looks like something went wrong when installing JSI bindings: ${result}` + ) + } - QuickSQLite = global.__QuickSQLiteProxy as ISQLite - }) + // Check again if the constructor now exists. If not, throw an error. + if (global.__QuickSQLiteProxy == null) { + throw new Error( + 'Failed to install react-native-quick-sqlite, the native initializer function does not exist. Are you trying to use QuickSQLite from different JS Runtimes?' + ) + } } -QuickSQLite = global.__QuickSQLiteProxy as ISQLite +export const QuickSQLite = global.__QuickSQLiteProxy as ISQLite /** * Object returned by SQL Query executions { From d73c254437b6200bfef8876da6ee2e0e9b6cec8f Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Tue, 15 Oct 2024 19:23:34 +0200 Subject: [PATCH 07/12] make iOS bridgeless --- example/ios/QuickSQLiteExample/AppDelegate.mm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/example/ios/QuickSQLiteExample/AppDelegate.mm b/example/ios/QuickSQLiteExample/AppDelegate.mm index a617319..bc8b8a8 100644 --- a/example/ios/QuickSQLiteExample/AppDelegate.mm +++ b/example/ios/QuickSQLiteExample/AppDelegate.mm @@ -24,4 +24,9 @@ - (NSURL *)bundleURL #endif } +- (BOOL)bridgelessEnabled +{ + return YES; +} + @end From f6ed7de7251523454c04d1458ffb3242b98c4b70 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Tue, 15 Oct 2024 19:28:27 +0200 Subject: [PATCH 08/12] rename turbomodule --- ...kSQLiteInitModule.java => RNQuickSQLiteModule.java} | 4 ++-- .../margelo/rnquicksqlite/RNQuickSQLitePackage.java | 10 +++++----- package/ios/QuickSQLite.h | 2 +- package/ios/QuickSQLite.mm | 6 +++--- ...QuickSQLiteInit.ts => NativeRNQuickSQLiteModule.ts} | 2 +- package/src/index.ts | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) rename package/android/src/main/java/com/margelo/rnquicksqlite/{RNQuickSQLiteInitModule.java => RNQuickSQLiteModule.java} (79%) rename package/src/{NativeRNQuickSQLiteInit.ts => NativeRNQuickSQLiteModule.ts} (93%) diff --git a/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java b/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteModule.java similarity index 79% rename from package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java rename to package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteModule.java index d533f62..fbcbf91 100644 --- a/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java +++ b/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteModule.java @@ -7,8 +7,8 @@ import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; -public class RNQuickSQLiteInitModule extends NativeRNQuickSQLiteInitSpec { - public RNQuickSQLiteInitModule(ReactApplicationContext reactContext) { +public class RNQuickSQLiteModule extends NativeRNQuickSQLiteModuleSpec { + public RNQuickSQLiteModule(ReactApplicationContext reactContext) { super(reactContext); } diff --git a/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLitePackage.java b/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLitePackage.java index e86ca34..8389edf 100644 --- a/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLitePackage.java +++ b/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLitePackage.java @@ -21,8 +21,8 @@ public class RNQuickSQLitePackage extends TurboReactPackage { @Nullable @Override public NativeModule getModule(String name, ReactApplicationContext reactContext) { - if (name.equals(RNQuickSQLiteInitModule.NAME)) { - return new RNQuickSQLiteInitModule(reactContext); + if (name.equals(RNQuickSQLiteModule.NAME)) { + return new RNQuickSQLiteModule(reactContext); } else { return null; } @@ -33,10 +33,10 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() { return () -> { final Map moduleInfos = new HashMap<>(); moduleInfos.put( - RNQuickSQLiteInitModule.NAME, + RNQuickSQLiteModule.NAME, new ReactModuleInfo( - RNQuickSQLiteInitModule.NAME, - RNQuickSQLiteInitModule.NAME, + RNQuickSQLiteModule.NAME, + RNQuickSQLiteModule.NAME, false, true, true, diff --git a/package/ios/QuickSQLite.h b/package/ios/QuickSQLite.h index 6590556..1811290 100644 --- a/package/ios/QuickSQLite.h +++ b/package/ios/QuickSQLite.h @@ -2,7 +2,7 @@ NS_ASSUME_NONNULL_BEGIN -@interface RNQuickSQLiteInit : NSObject +@interface RNQuickSQLiteModule : NSObject @property(nonatomic, assign) BOOL setBridgeOnMainQueue; diff --git a/package/ios/QuickSQLite.mm b/package/ios/QuickSQLite.mm index 711f86b..479ee86 100644 --- a/package/ios/QuickSQLite.mm +++ b/package/ios/QuickSQLite.mm @@ -7,18 +7,18 @@ using namespace facebook; -@implementation RNQuickSQLiteInit +@implementation RNQuickSQLiteModule @synthesize bridge = _bridge; - (std::shared_ptr)getTurboModule: (const facebook::react::ObjCTurboModule::InitParams &)params { - return std::make_shared(params); + return std::make_shared(params); } - (NSNumber *) install { - NSLog(@"Installing QuickSQLite module..."); + NSLog(@"Installing RNQuickSQLite module..."); RCTCxxBridge *cxxBridge = (RCTCxxBridge *)self.bridge; if (cxxBridge == nil) { diff --git a/package/src/NativeRNQuickSQLiteInit.ts b/package/src/NativeRNQuickSQLiteModule.ts similarity index 93% rename from package/src/NativeRNQuickSQLiteInit.ts rename to package/src/NativeRNQuickSQLiteModule.ts index 5f766d0..aec58d5 100644 --- a/package/src/NativeRNQuickSQLiteInit.ts +++ b/package/src/NativeRNQuickSQLiteModule.ts @@ -4,4 +4,4 @@ export interface Spec extends TurboModule { install(): boolean } -export default TurboModuleRegistry.getEnforcing('RNQuickSQLiteInit') +export default TurboModuleRegistry.getEnforcing('RNQuickSQLiteModule') diff --git a/package/src/index.ts b/package/src/index.ts index ccfdebb..a3b3772 100644 --- a/package/src/index.ts +++ b/package/src/index.ts @@ -8,7 +8,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unsafe-call */ -import RNQuickSQLiteInit from './NativeRNQuickSQLiteInit' +import RNQuickSQLiteModule from './NativeRNQuickSQLiteModule' declare global { function nativeCallSyncHook(): unknown @@ -16,14 +16,14 @@ declare global { } if (global.__QuickSQLiteProxy == null) { - if (RNQuickSQLiteInit == null || RNQuickSQLiteInit.install == null) { + if (RNQuickSQLiteModule == null || RNQuickSQLiteModule.install == null) { throw new Error( 'QuickSQLite TurboModule not found. Maybe try rebuilding the app.' ) } // Call the synchronous blocking install() function - const result = RNQuickSQLiteInit.install() + const result = RNQuickSQLiteModule.install() if (result !== true) { throw new Error( `Failed to install react-native-quick-sqlite: The QuickSQLite TurboModule could not be installed! Looks like something went wrong when installing JSI bindings: ${result}` From e931a5a3b633ee249be401445d4d988efb99e410 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 16 Oct 2024 00:59:14 +0200 Subject: [PATCH 09/12] fix: ios turbomodule and make backwards-compatible --- example/ios/Podfile | 2 ++ example/ios/Podfile.lock | 2 +- package/ios/QuickSQLite.h | 10 +++++++++- package/ios/QuickSQLite.mm | 8 +++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/example/ios/Podfile b/example/ios/Podfile index e34258d..0862af0 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -1,3 +1,5 @@ +ENV['RCT_NEW_ARCH_ENABLED'] = '1' + # Resolve react_native_pods.rb with node to allow for hoisting require Pod::Executable.execute_command('node', ['-p', 'require.resolve( diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 1cb4887..991d5d1 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1906,6 +1906,6 @@ SPEC CHECKSUMS: SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d Yoga: a1d7895431387402a674fd0d1c04ec85e87909b8 -PODFILE CHECKSUM: 4bce8267d9986e5cfbfb8604f802585607b49854 +PODFILE CHECKSUM: c6724dc625a6aa9f3f0577b2c2d3f9b39ece8968 COCOAPODS: 1.15.2 diff --git a/package/ios/QuickSQLite.h b/package/ios/QuickSQLite.h index 1811290..eb4a25d 100644 --- a/package/ios/QuickSQLite.h +++ b/package/ios/QuickSQLite.h @@ -1,11 +1,19 @@ +#ifdef RCT_NEW_ARCH_ENABLED #import NS_ASSUME_NONNULL_BEGIN -@interface RNQuickSQLiteModule : NSObject +@interface RNQuickSQLiteModule : NSObject +#else +#import + +@interface RNQuickSQLiteModule : NSObject +#endif @property(nonatomic, assign) BOOL setBridgeOnMainQueue; @end +#ifdef RCT_NEW_ARCH_ENABLED NS_ASSUME_NONNULL_END +#endif diff --git a/package/ios/QuickSQLite.mm b/package/ios/QuickSQLite.mm index 479ee86..e19a472 100644 --- a/package/ios/QuickSQLite.mm +++ b/package/ios/QuickSQLite.mm @@ -9,15 +9,21 @@ @implementation RNQuickSQLiteModule +RCT_EXPORT_MODULE() + @synthesize bridge = _bridge; +#if RCT_NEW_ARCH_ENABLED + - (std::shared_ptr)getTurboModule: (const facebook::react::ObjCTurboModule::InitParams &)params { return std::make_shared(params); } -- (NSNumber *) install { +#endif + +RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) { NSLog(@"Installing RNQuickSQLite module..."); RCTCxxBridge *cxxBridge = (RCTCxxBridge *)self.bridge; From 5e0fdc4886f41e7f453156486c82ba4ee85df41f Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 16 Oct 2024 00:59:22 +0200 Subject: [PATCH 10/12] re-structure index --- package/src/index.ts | 68 +++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/package/src/index.ts b/package/src/index.ts index a3b3772..95e31ab 100644 --- a/package/src/index.ts +++ b/package/src/index.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/prefer-optional-chain */ /* eslint-disable @typescript-eslint/no-unnecessary-condition */ /* eslint-disable no-var */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ @@ -11,14 +10,13 @@ import RNQuickSQLiteModule from './NativeRNQuickSQLiteModule' declare global { - function nativeCallSyncHook(): unknown var __QuickSQLiteProxy: object | undefined } if (global.__QuickSQLiteProxy == null) { - if (RNQuickSQLiteModule == null || RNQuickSQLiteModule.install == null) { + if (RNQuickSQLiteModule == null) { throw new Error( - 'QuickSQLite TurboModule not found. Maybe try rebuilding the app.' + 'RNQuickSQLite TurboModule not found. Maybe try rebuilding the app.' ) } @@ -26,7 +24,7 @@ if (global.__QuickSQLiteProxy == null) { const result = RNQuickSQLiteModule.install() if (result !== true) { throw new Error( - `Failed to install react-native-quick-sqlite: The QuickSQLite TurboModule could not be installed! Looks like something went wrong when installing JSI bindings: ${result}` + `Failed to install react-native-quick-sqlite: The RNQuickSQLite TurboModule could not be installed! Looks like something went wrong when installing JSI bindings: ${result}` ) } @@ -39,6 +37,36 @@ if (global.__QuickSQLiteProxy == null) { } export const QuickSQLite = global.__QuickSQLiteProxy as ISQLite +interface ISQLite { + open: (dbName: string, location?: string) => void + close: (dbName: string) => void + delete: (dbName: string, location?: string) => void + attach: ( + mainDbName: string, + dbNameToAttach: string, + alias: string, + location?: string + ) => void + detach: (mainDbName: string, alias: string) => void + transaction: ( + dbName: string, + fn: (tx: Transaction) => Promise | void + ) => Promise + execute: (dbName: string, query: string, params?: any[]) => QueryResult + executeAsync: ( + dbName: string, + query: string, + params?: any[] + ) => Promise + executeBatch: (dbName: string, commands: SQLBatchTuple[]) => BatchQueryResult + executeBatchAsync: ( + dbName: string, + commands: SQLBatchTuple[] + ) => Promise + loadFile: (dbName: string, location: string) => FileLoadResult + loadFileAsync: (dbName: string, location: string) => Promise +} + /** * Object returned by SQL Query executions { * insertId: Represent the auto-generated row id if applicable @@ -131,36 +159,6 @@ export interface PendingTransaction { start: () => void } -interface ISQLite { - open: (dbName: string, location?: string) => void - close: (dbName: string) => void - delete: (dbName: string, location?: string) => void - attach: ( - mainDbName: string, - dbNameToAttach: string, - alias: string, - location?: string - ) => void - detach: (mainDbName: string, alias: string) => void - transaction: ( - dbName: string, - fn: (tx: Transaction) => Promise | void - ) => Promise - execute: (dbName: string, query: string, params?: any[]) => QueryResult - executeAsync: ( - dbName: string, - query: string, - params?: any[] - ) => Promise - executeBatch: (dbName: string, commands: SQLBatchTuple[]) => BatchQueryResult - executeBatchAsync: ( - dbName: string, - commands: SQLBatchTuple[] - ) => Promise - loadFile: (dbName: string, location: string) => FileLoadResult - loadFileAsync: (dbName: string, location: string) => Promise -} - const locks: Record< string, { queue: PendingTransaction[]; inProgress: boolean } From dafc5f5fcfdae6f1e1797f6ea6b7a0602c20c030 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 16 Oct 2024 01:11:18 +0200 Subject: [PATCH 11/12] rename module --- .../rnquicksqlite/RNQuickSQLiteModule.java | 2 +- package/ios/QuickSQLite.h | 4 ++-- package/ios/QuickSQLite.mm | 18 ++++++++++++------ package/src/NativeRNQuickSQLiteModule.ts | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteModule.java b/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteModule.java index fbcbf91..97fee0c 100644 --- a/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteModule.java +++ b/package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteModule.java @@ -7,7 +7,7 @@ import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; -public class RNQuickSQLiteModule extends NativeRNQuickSQLiteModuleSpec { +public class RNQuickSQLiteModule extends NativeRNQuickSQLiteSpec { public RNQuickSQLiteModule(ReactApplicationContext reactContext) { super(reactContext); } diff --git a/package/ios/QuickSQLite.h b/package/ios/QuickSQLite.h index eb4a25d..1c6136f 100644 --- a/package/ios/QuickSQLite.h +++ b/package/ios/QuickSQLite.h @@ -3,11 +3,11 @@ NS_ASSUME_NONNULL_BEGIN -@interface RNQuickSQLiteModule : NSObject +@interface RNQuickSQLite : NSObject #else #import -@interface RNQuickSQLiteModule : NSObject +@interface RNQuickSQLite : NSObject #endif @property(nonatomic, assign) BOOL setBridgeOnMainQueue; diff --git a/package/ios/QuickSQLite.mm b/package/ios/QuickSQLite.mm index e19a472..fde072c 100644 --- a/package/ios/QuickSQLite.mm +++ b/package/ios/QuickSQLite.mm @@ -7,23 +7,29 @@ using namespace facebook; -@implementation RNQuickSQLiteModule +#ifdef RCT_NEW_ARCH_ENABLED +@implementation RNQuickSQLite RCT_EXPORT_MODULE() +#else +@implementation RNQuickSQLite -@synthesize bridge = _bridge; +RCT_EXPORT_MODULE(RNQuickSQLite) +#endif -#if RCT_NEW_ARCH_ENABLED +@synthesize bridge = _bridge; +#ifdef RCT_NEW_ARCH_ENABLED - (std::shared_ptr)getTurboModule: (const facebook::react::ObjCTurboModule::InitParams &)params { - return std::make_shared(params); + return std::make_shared(params); } -#endif - +- (NSNumber *) install { +#else RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) { +#endif NSLog(@"Installing RNQuickSQLite module..."); RCTCxxBridge *cxxBridge = (RCTCxxBridge *)self.bridge; diff --git a/package/src/NativeRNQuickSQLiteModule.ts b/package/src/NativeRNQuickSQLiteModule.ts index aec58d5..40965b7 100644 --- a/package/src/NativeRNQuickSQLiteModule.ts +++ b/package/src/NativeRNQuickSQLiteModule.ts @@ -4,4 +4,4 @@ export interface Spec extends TurboModule { install(): boolean } -export default TurboModuleRegistry.getEnforcing('RNQuickSQLiteModule') +export default TurboModuleRegistry.getEnforcing('RNQuickSQLite') From 188602aaf439b0949c2d5df3269c5d80edb3b100 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 16 Oct 2024 01:15:58 +0200 Subject: [PATCH 12/12] rename module --- example/ios/QuickSQLiteExample/AppDelegate.mm | 2 ++ package/ios/QuickSQLite.mm | 4 +--- .../{NativeRNQuickSQLiteModule.ts => NativeRNQuickSQLite.ts} | 0 package/src/index.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename package/src/{NativeRNQuickSQLiteModule.ts => NativeRNQuickSQLite.ts} (100%) diff --git a/example/ios/QuickSQLiteExample/AppDelegate.mm b/example/ios/QuickSQLiteExample/AppDelegate.mm index bc8b8a8..7896d2f 100644 --- a/example/ios/QuickSQLiteExample/AppDelegate.mm +++ b/example/ios/QuickSQLiteExample/AppDelegate.mm @@ -24,9 +24,11 @@ - (NSURL *)bundleURL #endif } +#ifdef RCT_NEW_ARCH_ENABLED - (BOOL)bridgelessEnabled { return YES; } +#endif @end diff --git a/package/ios/QuickSQLite.mm b/package/ios/QuickSQLite.mm index fde072c..530dfbd 100644 --- a/package/ios/QuickSQLite.mm +++ b/package/ios/QuickSQLite.mm @@ -7,13 +7,11 @@ using namespace facebook; -#ifdef RCT_NEW_ARCH_ENABLED @implementation RNQuickSQLite +#ifdef RCT_NEW_ARCH_ENABLED RCT_EXPORT_MODULE() #else -@implementation RNQuickSQLite - RCT_EXPORT_MODULE(RNQuickSQLite) #endif diff --git a/package/src/NativeRNQuickSQLiteModule.ts b/package/src/NativeRNQuickSQLite.ts similarity index 100% rename from package/src/NativeRNQuickSQLiteModule.ts rename to package/src/NativeRNQuickSQLite.ts diff --git a/package/src/index.ts b/package/src/index.ts index 95e31ab..d486d26 100644 --- a/package/src/index.ts +++ b/package/src/index.ts @@ -7,7 +7,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unsafe-call */ -import RNQuickSQLiteModule from './NativeRNQuickSQLiteModule' +import RNQuickSQLiteModule from './NativeRNQuickSQLite' declare global { var __QuickSQLiteProxy: object | undefined