Skip to content

Commit f2efc3b

Browse files
committed
add turbomodule for init
1 parent faef31d commit f2efc3b

File tree

6 files changed

+80
-55
lines changed

6 files changed

+80
-55
lines changed

package/android/src/main/java/com/margelo/rnquicksqlite/SequelModule.java renamed to package/android/src/main/java/com/margelo/rnquicksqlite/RNQuickSQLiteInitModule.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
package com.margelo.rnquicksqlite;
22

3-
import androidx.annotation.NonNull;
43
import android.util.Log;
5-
import com.facebook.react.bridge.ReactApplicationContext;
6-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
7-
import com.facebook.react.bridge.ReactMethod;
84

9-
class SequelModule extends ReactContextBaseJavaModule {
10-
public static final String NAME = "QuickSQLite";
5+
import androidx.annotation.NonNull;
6+
import com.facebook.react.bridge.ReactApplicationContext;
117

12-
public SequelModule(ReactApplicationContext context) {
13-
super(context);
8+
public class RNQuickSQLiteInitModule extends NativeQuickSQLiteInitSpec {
9+
public RNQuickSQLiteInitModule(ReactApplicationContext reactContext) {
10+
super(reactContext);
1411
}
1512

16-
@NonNull
1713
@Override
14+
@NonNull
1815
public String getName() {
1916
return NAME;
2017
}
2118

22-
@ReactMethod(isBlockingSynchronousMethod = true)
19+
@Override
2320
public boolean install() {
2421
try {
2522
System.loadLibrary("react-native-quick-sqlite");
@@ -30,13 +27,4 @@ public boolean install() {
3027
return false;
3128
}
3229
}
33-
34-
@Override
35-
public void onCatalystInstanceDestroy() {
36-
try {
37-
QuickSQLiteBridge.instance.clearState();
38-
} catch (Exception exception) {
39-
Log.e(NAME, "Failed to clear state!", exception);
40-
}
41-
}
4230
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.margelo.rnquicksqlite;
2+
3+
import androidx.annotation.NonNull;
4+
import androidx.annotation.Nullable;
5+
import com.facebook.react.bridge.NativeModule;
6+
import com.facebook.react.bridge.ReactApplicationContext;
7+
import com.facebook.react.module.model.ReactModuleInfo;
8+
import com.facebook.react.module.model.ReactModuleInfoProvider;
9+
import com.facebook.react.TurboReactPackage;
10+
11+
import java.util.Collections;
12+
import java.util.HashMap;
13+
import java.util.List;
14+
import java.util.Map;
15+
16+
public class RNQuickSQLitePackage extends TurboReactPackage {
17+
static {
18+
System.loadLibrary("RNQuickSQLite");
19+
}
20+
21+
@Nullable
22+
@Override
23+
public NativeModule getModule(String name, ReactApplicationContext reactContext) {
24+
if (name.equals(RNQuickSQLiteInitModule.NAME)) {
25+
return new RNQuickSQLiteInitModule(reactContext);
26+
} else {
27+
return null;
28+
}
29+
}
30+
31+
@Override
32+
public ReactModuleInfoProvider getReactModuleInfoProvider() {
33+
return () -> {
34+
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
35+
moduleInfos.put(
36+
RNQuickSQLiteInitModule.NAME,
37+
new ReactModuleInfo(
38+
RNQuickSQLiteInitModule.NAME,
39+
RNQuickSQLiteInitModule.NAME,
40+
false,
41+
true,
42+
true,
43+
false,
44+
true));
45+
return moduleInfos;
46+
};
47+
}
48+
}

package/android/src/main/java/com/margelo/rnquicksqlite/SequelPackage.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

package/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@
6161
"react": "*",
6262
"react-native": ">=0.74.0"
6363
},
64+
"codegenConfig": {
65+
"name": "RNQuickSQLite",
66+
"type": "modules",
67+
"jsSrcsDir": "src",
68+
"android": {
69+
"javaPackageName": "com.margelo.rnquicksqlite"
70+
}
71+
},
6472
"react-native-builder-bob": {
6573
"source": "src",
6674
"output": "lib",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { TurboModuleRegistry, type TurboModule } from 'react-native'
2+
3+
export interface Spec extends TurboModule {
4+
install(): boolean
5+
}
6+
7+
export default TurboModuleRegistry.getEnforcing<Spec>('RNQuickSQLiteInit')

package/src/index.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,39 @@
1+
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
2+
/* eslint-disable no-var */
13
/* eslint-disable @typescript-eslint/no-unsafe-argument */
24
/* eslint-disable no-return-await */
35
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
46
/* eslint-disable @typescript-eslint/no-unsafe-return */
57
/* eslint-disable @typescript-eslint/no-explicit-any */
6-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
8+
79
/* eslint-disable @typescript-eslint/no-unsafe-call */
8-
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
9-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
10-
/* eslint-disable no-var */
11-
import { NativeModules } from 'react-native'
10+
11+
import RNQuickSQLiteInit from './NativeRNQuickSQLiteInit'
1212

1313
declare global {
1414
function nativeCallSyncHook(): unknown
1515
var __QuickSQLiteProxy: object | undefined
1616
}
1717

1818
if (global.__QuickSQLiteProxy == null) {
19-
const QuickSQLiteModule = NativeModules.QuickSQLite
20-
21-
if (QuickSQLiteModule == null) {
19+
if (RNQuickSQLiteInit == null) {
2220
throw new Error(
23-
'Base quick-sqlite module not found. Maybe try rebuilding the app.'
21+
'QuickSQLite TurboModule not found. Maybe try rebuilding the app.'
2422
)
2523
}
2624

2725
// Check if we are running on-device (JSI)
28-
if (global.nativeCallSyncHook == null || QuickSQLiteModule.install == null) {
26+
if (global.nativeCallSyncHook == null || RNQuickSQLiteInit.install == null) {
2927
throw new Error(
3028
'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.'
3129
)
3230
}
3331

3432
// Call the synchronous blocking install() function
35-
const result = QuickSQLiteModule.install()
33+
const result = RNQuickSQLiteInit.install()
3634
if (result !== true) {
3735
throw new Error(
38-
`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}`
36+
`Failed to install react-native-quick-sqlite: The QuickSQLite TurboModule could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`
3937
)
4038
}
4139

0 commit comments

Comments
 (0)