-
Notifications
You must be signed in to change notification settings - Fork 612
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1854 from prathameshmm02/fix/jsi-compatibility
Add jsi support for newer react native versions(old-arch)
- Loading branch information
Showing
6 changed files
with
91 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
native/android-jsi/src/main/java/com/nozbe/watermelondb/WatermelonDBJSIModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.nozbe.watermelondb.jsi; | ||
|
||
import android.util.Log; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import com.facebook.react.bridge.JavaScriptContextHolder; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.facebook.react.module.annotations.ReactModule; | ||
|
||
@ReactModule(name = WatermelonDBJSIModule.NAME) | ||
public class WatermelonDBJSIModule extends ReactContextBaseJavaModule { | ||
ReactApplicationContext reactContext; | ||
public static final String NAME = "WMDatabaseJSIBridge"; | ||
|
||
public WatermelonDBJSIModule(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
this.reactContext = reactContext; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String getName() { | ||
return NAME; | ||
} | ||
|
||
@ReactMethod(isBlockingSynchronousMethod = true) | ||
public boolean install() { | ||
try { | ||
JavaScriptContextHolder jsContext = getReactApplicationContext().getJavaScriptContextHolder(); | ||
JSIInstaller.install(getReactApplicationContext(), jsContext.get()); | ||
Log.i(NAME, "Successfully installed Watermelon DB JSI Bindings!"); | ||
return true; | ||
} catch (Exception exception) { | ||
Log.e(NAME, "Failed to install Watermelon DB JSI Bindings!", exception); | ||
return false; | ||
} | ||
} | ||
} |
34 changes: 22 additions & 12 deletions
34
native/android-jsi/src/main/java/com/nozbe/watermelondb/jsi/WatermelonDBJSIPackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,29 @@ | ||
package com.nozbe.watermelondb.jsi; | ||
|
||
import com.facebook.react.bridge.JSIModulePackage; | ||
import com.facebook.react.bridge.JSIModuleSpec; | ||
import com.facebook.react.bridge.JavaScriptContextHolder; | ||
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.Arrays; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class WatermelonDBJSIPackage implements JSIModulePackage { | ||
@Override | ||
public List<JSIModuleSpec> getJSIModules(ReactApplicationContext reactApplicationContext, JavaScriptContextHolder jsContextHolder) { | ||
synchronized(jsContextHolder) { | ||
JSIInstaller.install(reactApplicationContext.getApplicationContext(), jsContextHolder.get()); | ||
public class WatermelonDBJSIPackage implements ReactPackage { | ||
|
||
@NonNull | ||
@Override | ||
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactAppContext) { | ||
List<NativeModule> modules = new ArrayList<>(); | ||
modules.add(new WatermelonDBJSIModule(reactAppContext)); | ||
return modules; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactAppContext) { | ||
return Collections.emptyList(); | ||
} | ||
return Arrays.asList(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters