react-native-threads icon indicating copy to clipboard operation
react-native-threads copied to clipboard

Fails to load threads on RN 0.60.4

Open mauricioscotton opened this issue 6 years ago • 2 comments

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: image 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?

mauricioscotton avatar Dec 11 '19 07:12 mauricioscotton

I'm currently having this same issue

majiyd avatar Jan 03 '20 21:01 majiyd

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

mauricioscotton avatar Jan 21 '20 05:01 mauricioscotton