question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to config getJSIModulePackage for multiple JSI packages?

See original GitHub issue

Pardon my ignorances here, I’m trying to implement WatermelonDB and React Native Reanimated together into one single app, and here’s my MainApplication.java

@Override
protected JSIModulePackage getJSIModulePackage() {
  return new JSIModulePackage() {
    @Override
    public List<JSIModuleSpec> getJSIModules(
      final ReactApplicationContext reactApplicationContext,
      final JavaScriptContextHolder jsContext
    ) {
      final List<JSIModuleSpec> specs = new ArrayList<>();
      specs.add(new ReanimatedJSIModulePackage());
      specs.add(new WatermelonDBJSIPackage());
      return specs;
    }
  };
}

Since I have no JAVA experience, so this code is total junk, but the idea of how to enable both JSI Modules in getJSIModulePackage() is a problem I cound’t overcome, could someone please to help?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
marcocesaratocommented, May 13, 2021

// Add imports
import java.util.Arrays;

import com.facebook.react.bridge.JSIModulePackage;
import com.facebook.react.bridge.JSIModuleSpec;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.JavaScriptContextHolder;
import com.nozbe.watermelondb.jsi.WatermelonDBJSIPackage;
import com.swmansion.reanimated.ReanimatedJSIModulePackage;

public class MainApplication extends Application implements ReactApplication {

// ...

  @Override
  protected JSIModulePackage getJSIModulePackage() {
    return new JSIModulePackage() {
      @Override
      public List<JSIModuleSpec> getJSIModules(
        final ReactApplicationContext reactApplicationContext,
        final JavaScriptContextHolder jsContext
      ) {
        List<JSIModuleSpec> modules = Arrays.asList();
        modules.addAll(new ReanimatedJSIModulePackage().getJSIModules(reactApplicationContext, jsContext));
        modules.addAll(new WatermelonDBJSIPackage().getJSIModules(reactApplicationContext, jsContext));
        return modules;
      }
    };
  }
1reaction
marcocesaratocommented, May 11, 2021

Something like this?

@Override
protected JSIModulePackage getJSIModulePackage() {
  return new JSIModulePackage() {
    @Override
    public List<JSIModuleSpec> getJSIModules(
      final ReactApplicationContext reactApplicationContext,
      final JavaScriptContextHolder jsContext
    ) {
      new ReanimatedJSIModulePackage().getJSIModules(reactApplicationContext, jsContext);
      new WatermelonDBJSIPackage().getJSIModules(reactApplicationContext, jsContext);
      return Arrays.asList();
    }
  };
}

Update Tested and it’s working for me

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add multiple JSIModule React-Native Android - Stack Overflow
This is the best way: change your code: @Override protected List<JSIModulePackage> getJSIModulePackage() { List<ReactPackage> packages = new ...
Read more >
[Android/Java] Allow third-party libraries to automatically setup ...
Add an abstract method like getJSIModulePackages to ReactNativeHost , and load the module packages returned by it into the catalystInstance on ...
Read more >
React Native JSI: Part 1 - Getting Started - Notesnook Blog
Inside our instance of ReactNativeHost we are overriding getJSIModulePackage method and returning an new instance of SimpleJsiModulePackage .
Read more >
Deep dive into React Native JSI - Teknasyon Engineering
For this reason, we need to do linking operations manually. In MainApplication.java, we need to override getJSIModulePackage method in the ReactNativeHost ...
Read more >
@tonclient/lib-react-native-jsi - npm
Start using @tonclient/lib-react-native-jsi in your project by running ... TypeScript icon, indicating that this package has built-in type ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found