加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 04:39:33 所属栏目:百科 来源:网络整理
导读:AppRegistry简介 AppRegistry是RN应用的入口函数。 程序入口组件使用 AppRegistry.registerComponent 来注册。当注册完应用程序组件后,Native系统(OC)就会加载jsbundle文件并触发 AppRegistry.runApplication 运行应用。AppRegistry有以下方法: register

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());

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读