React Native之AppRegistry模块
我們在寫react native的js的時候,在最后總會加上一段代碼:
AppRegistry.registerComponent('ReactDemo', () => ReactDemo);代碼的意思:定義了一個名為ReactDemo的新的組件(Component),并且使用了名為AppRegistry的內置模塊進行了“注冊”操作。在編寫React Native應用時,肯定會寫出很多新的組件。而一個App的最終界面,其實也就是各式各樣的組件的組合。這和android和ios的思路不謀而合,其實React Native的組件也很豐富。看官方提供的常用組件:
AppRegistry模塊則是用來告知React Native哪一個組件被注冊為整個應用的根容器。
使用AppRegistry.registerComponent進行注冊自己,然后原生系統就可以進行加載運行bundle文件包,最后就會可以調用AppRegistry.runApplication進行運行起來應用。當一個視圖被摧毀的時候,為了結束應用需要調用AppRegistry.unmountApplictionComponentAtRootTag方法。
AppRegistry常用方法
.registerConfig(config:Array<AppConfig>)? static 靜態方法, 進行注冊配置信息
.registerComponent(appKey:string,getComponentFunc:ComponentProvider)? static靜態方法,進行注冊組件
.registerRunnable(appKey:string,func:Function)? static靜態方法 ,進行注冊線程
.registerAppKeys()? static靜態方法,進行獲取所有組件的keys值
.runApplication(appKey:string,appParameters:any)? static靜態方法, 進行運行應用
.unmountApplicationComponentAtRootTag()? static靜態方法,結束應用
AppRegistry是React中最基本的模塊,以后會慢慢講解。總結
以上是生活随笔為你收集整理的React Native之AppRegistry模块的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 动态新增元素的js无效的解决方法
- 下一篇: php 使用redis锁限制并发访问类