react-native-threads
react-native-threads copied to clipboard
Fails to load threads on RN 0.60.4
Hi, I've managed to implement your package on RN 0.60.4 in a boilerplate app, although when implementing on an app with RNNavigation it simply does not works when spawning a new thread by running:
this.thread = new Thread('./thread.js');
When executing this line I get this message:
P.s.: I am using ReactNativeNavigation by wix:
public class MainApplication extends NavigationApplication {
private final ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
@Override
protected String getJSMainModuleName() {
return "index.android";
}
};
@Override
protected ReactGateway createReactGateway() {
ReactGateway gateway = new ReactGateway(this, isDebug(), this.host);
return gateway;
}
@Override
public boolean isDebug() {
return BuildConfig.DEBUG;
}
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
packages.add( new RNThreadPackage(this.host) );
return packages;
}
@Override
public List<ReactPackage> createAdditionalReactPackages() {
return getPackages();
}
@Override
public ReactNativeHost getReactNativeHost() {
return this.host;
}
}
Can it be NavigationReactNativeHost not providing the first argument?
I'm currently having this same issue
I'm currently having this same issue
I just found the reason why it does not work... Apparently, when running with Wix ReactNativeNavigation, it fails to link to the correct instance of ReactInstanceManager, as the method dispatched by createAdditionalReactPackages from RNNavigation, references to null as "ReactNativeHost" is not present on memory yet. As observed on Wix ReactNativeNavigation source-code here: https://github.com/wix/react-native-navigation/blob/27ceea8fb92506fdd756e45768e7235e3e7babc6/lib/android/app/src/reactNative60/java/com/reactnativenavigation/react/NavigationReactNativeHost.java#L60
The solution was to override the already overridden method getPackages on NavigationReactNativeHost, call super and push RNThreadPackage into packages list which makes it work like a charm as the method getPackages will be caller later than the Host instantiation on memory.
private final ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
@Override
protected String getJSMainModuleName() {
return "index.android";
}
@Override
protected List<ReactPackage> getPackages() {
List<ReactPackage> packages = super.getPackages();
packages.add( new RNThreadPackage(this.host) );
return packages;
}
};
Cheers Mauricio Scotton