-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
没有执行预加载的代码会报错 #86
Comments
ReactInstanceManager reactInstanceManager = ((ReactApplication)getApplication()).getReactNativeHost().getReactInstanceManager(); |
如果注释掉MainActivity中的这几行 ReactInstanceManager reactInstanceManager = ((ReactApplication)getApplication()).getReactNativeHost().getReactInstanceManager();
if (!reactInstanceManager.hasStartedCreatingInitialContext()) {
reactInstanceManager.createReactContextInBackground();
} 会导致崩溃 修复方法是: //默认給null的ComponentName
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, null);
}
//runApp中加载完成了Bundle再调用mDelegate.loadApp(getMainComponentName());
protected void runApp(String scriptPath){
if(scriptPath!=null){
scriptPath = "file://"+scriptPath.substring(0,scriptPath.lastIndexOf(File.separator)+1);
}
final String path = scriptPath;
final RnBundle bundle = getBundle();
final ReactInstanceManager reactInstanceManager = ((ReactApplication)getApplication()).getReactNativeHost().getReactInstanceManager();
if(bundle.scriptType == ScriptType.NETWORK){//如果是网络加载的话,此时正在子线程
runOnUiThread(new Runnable() {
@Override
public void run() {
ScriptLoadUtil.setJsBundleAssetPath(
reactInstanceManager.getCurrentReactContext(),
path);
mDelegate.loadApp(getMainComponentNameInner());
}
});
} else {//主线程运行
ScriptLoadUtil.setJsBundleAssetPath(
reactInstanceManager.getCurrentReactContext(),
path);
mDelegate.loadApp(getMainComponentName());
}
} |
可以参考 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: