只有配合使用React Native的常用组件和常用API,才能更好的开发应用程序
AppRegistry是JS运行所有React Native应用的入口函数。
应用程序入口组件使用AppRegistry.registerComponent来注册。当注册完应用程序组件后,Native系统就会加载jsbundle文件并触发AppRegistry.runApplication运行应用。AppRegistry有以下方法:
registerConfig(config: Array):静态方法,注册配置registerComponent(appKey: string, getComponentFunc: ComponentProvider):注册入口组件registerRunnable(appKey: string , func: Function):注册函数监听getAppKeys():获取registerRunnable注册的监听键runApplication(appKey: string, appParameter: any):运行App
React Native应用程序启动时会在log栏中看到这样的输出,这些日志信息是由runApplication打印出来的。
Running application "RNAPP" with appParams: {"initialProps":{},"rootTag":1}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
我们可以使用alert(AppRegistry.runApplication),在程序中以提示框的形式查看runApplication函数的定义。
我们还可以使用registerRunnable注册一些AppKey,实例:
AppRegistry.registerRunnable('rnapp', function() {
console.log('rnapp');
})
alert(AppRegistry.getAppKeys());