首先從組件的角度來(lái)看下RN的啟動(dòng)流程:(Android為例)
- Native初始化,主要流程:ReactNativeHost -> Activity -> ReactRootView -> startReactApplication -> createReactContextInBackground(期間有模塊/UI組件信息收集、JSC初始化等工作)
- 后臺(tái)異步加載、執(zhí)行JSBundle
- Native端執(zhí)行setupReactContext初始化React上下文,調(diào)用JS端AppRegistry.runApplication(key,params),key為模塊/組件名稱,參數(shù)包含rootTag、initialProps
- JS端找到注冊(cè)的對(duì)應(yīng)啟動(dòng)組件,執(zhí)行renderApplication渲染整個(gè)應(yīng)用
renderApplication函數(shù)中會(huì)執(zhí)行:
ReactNative.render( <AppContainer> <RootComponent {...initialProps} rootTag
網(wǎng)友評(píng)論