React native应用程序注册表appRegistry

来源:互联网 发布:mac优酷弹幕怎么设置 编辑:程序博客网 时间:2024/06/07 11:57

AppRegistry 是运行所有 React Native 应用程序的 JS 入口点。应用程序跟组件需要通过 AppRegistry.registerComponent 来注册它们自身,然后本地系统就可以加载应用程序的包,再然后当 AppRegistry.runApplication准备就绪后就可以真正的运行该应用程序了。

AppRegistry 在 require 序列里是 required,确保在其他模块被需求之前 JS 执行环境已经被 required


方法

static **registerConfig**(config: Array<AppConfig>) 静态方法用来注册配置信息static **registerComponent**(appKey: string, getComponentFunc: Function) 注册组件static **registerRunnable**(appKey: string, func: Function) 注册线程static **runApplication**(appKey: string, appParameters: any)

我们在写react native的js的时候,在最后总会加上一段代码:

[html] view plain copy
 print?
  1. AppRegistry.registerComponent('ReactDemo', () => ReactDemo);  

代码的意思:定义了一个名为ReactDemo的新的组件(Component),并且使用了名为AppRegistry的内置模块进行了“注册”操作。在编写React Native应用时,肯定会写出很多新的组件。而一个App的最终界面,其实也就是各式各样的组件的组合。这和android和ios的思路不谋而合,其实React Native的组件也很丰富。
appRegister模块是用来告诉rn哪一个组件作为整个应用的根容器。
使用appRegister注册自己,原生系统就可以通过加载运行bundle文件包,最后通过appRegister.runapplication来运行应用。

原创粉丝点击