public void reloadJs() {
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
Activity activity = getCurrentActivity();
Application application = activity.getApplication();
ReactInstanceManager instanceManager = ((ReactApplication) application).getReactNativeHost().getReactInstanceManager();
if (instanceManager.getClass().getSimpleName().equals("XReactInstanceManagerImpl")) {
JSBundleLoader loader = JSBundleLoader.createRemoteDebuggerBundleLoader(
instanceManager.getDevSupportManager().getJSBundleURLForRemoteDebugging(),
instanceManager.getDevSupportManager().getSourceUrl()
);
Field jsBundleField = instanceManager.getClass().getDeclaredField("mBundleLoader");
jsBundleField.setAccessible(true);
jsBundleField.set(instanceManager, loader);
} else {
Field jsBundleField = instanceManager.getClass().getDeclaredField("mJSBundleFile");
jsBundleField.setAccessible(true);
jsBundleField.set(instanceManager, instanceManager.getDevSupportManager().getSourceUrl());
}
final Method recreateMethod = instanceManager.getClass().getMethod("recreateReactContextInBackground");
final ReactInstanceManager finalizedInstanceManager = instanceManager;
recreateMethod.invoke(finalizedInstanceManager);
activity.recreate();
} catch (Throwable err) {
Log.e("hot-update", "Failed to restart application", err);
}
}
});
}