您的位置:首页 > 移动开发

React Native-13.React Native 常用API及实践 AppRegistry

2016-02-24 14:51 447 查看

AppRegistry简介

AppRegistry是RN应用的入口函数。

程序入口组件使用
AppRegistry.registerComponent
来注册。当注册完应用程序组件后,Native系统(OC)就会加载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

实例

在前边的文章中,我们都使用了
AppRegistry.registerComponent


如:

AppRegistry.registerComponent('wxsPrj', () => wxsPrj);


我们在XCode启动RN程序的时候会在log栏中看到这样的输出:

2016-02-24 12:05:36.838 [trace][tid:com.facebook.React.JavaScript] Running application "wxsPrj" with appParams: {"rootTag":1,"initialProps":{}}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF


这个日志信息是由
runApplication
打印出来的。

我们可以用
alert(AppRegistry.runApplication);


在程序中以提示框的形式看
runApplication
函数的定义。

我们还可以使用
registerRunnable
注册一些AppKey,实例:

AppRegistry.registerRunnable('wxs',function(){
console.log('was');
})
alert(AppRegistry.getAppKeys());
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: