I want to develop a react native app. But js files aren't on my local machine. I will download bundle from remote server.
Below code works for now. But how can I reload js bundle from file path?
public class MainApplication extends Application implements ReactApplication {
public static String mBundleFilePath = "sdcard/Download/index.android.bundle";
public final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage()
);
}
@Override
protected String getJSMainModuleName() {
return "index";
}
@Override
protected String getJSBundleFile() {
return mBundleFilePath;
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}
There are some methods for reloading. But it doesn't support external path. reloadJSFromServer works for only http/https.
getReactNativeHost().getReactInstanceManager().getDevSupportManager().reloadJSFromServer(httpUrl);
handleReloadJS loads from localhost/8081
getReactNativeHost().getReactInstanceManager().getDevSupportManager().handleReloadJS();
EDIT
Restart activity doesn't work for me :)
Intent myIntent = new Intent(getApplicationContext(), MainActivity.class);
finish();
startActivity(myIntent);