RN启动流程分支-准备
为了简化分析,使用集成RN ARR的方式准备环境。方式:
https://reactnative.cn/docs/integration-with-existing-apps/
Java 层实例创建,其中核心代码如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| public class MainActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler {
private ReactRootView mReactRootView; private ReactInstanceManager mReactInstanceManager;
@Override protected void onCreate(Bundle savedInstanceState) { SoLoader.init(getApplicationContext(), /* native exopackage */ false); super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this); mReactInstanceManager = ReactInstanceManager.builder() .setApplication(getApplication()) .setCurrentActivity(this) .setBundleAssetName("index.android.bundle") .setJSMainModulePath("index") .addPackage(new MainReactPackage()) .setUseDeveloperSupport(BuildConfig.DEBUG) .setInitialLifecycleState(LifecycleState.RESUMED) .build(); mReactRootView.startReactApplication(mReactInstanceManager, "MyReactNativeApp", new Bundle());
setContentView(mReactRootView); } }
|
我们可以看出,启动流程主要分3部分
- 创建ReactRootView
- 创建ReactInstanceManager
- 启动ReactApplication