{"id":503,"date":"2023-02-25T14:19:59","date_gmt":"2023-02-25T06:19:59","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=503"},"modified":"2023-04-29T20:48:30","modified_gmt":"2023-04-29T12:48:30","slug":"react-native-learning-for-appregistry-api","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/react-native-learning-for-appregistry-api\/","title":{"rendered":"React Native\u5b66\u4e60\u4e4bAppRegistry API"},"content":{"rendered":"<p>\u53ea\u6709\u914d\u5408\u4f7f\u7528React Native\u7684\u5e38\u7528\u7ec4\u4ef6\u548c\u5e38\u7528API\uff0c\u624d\u80fd\u66f4\u597d\u7684\u5f00\u53d1\u5e94\u7528\u7a0b\u5e8f<\/p>\n<p><code>AppRegistry<\/code>\u662fJS\u8fd0\u884c\u6240\u6709React Native\u5e94\u7528\u7684\u5165\u53e3\u51fd\u6570\u3002<\/p>\n<p>\u5e94\u7528\u7a0b\u5e8f\u5165\u53e3\u7ec4\u4ef6\u4f7f\u7528<code>AppRegistry.registerComponent<\/code>\u6765\u6ce8\u518c\u3002\u5f53\u6ce8\u518c\u5b8c\u5e94\u7528\u7a0b\u5e8f\u7ec4\u4ef6\u540e\uff0cNative\u7cfb\u7edf\u5c31\u4f1a\u52a0\u8f7d<code>jsbundle<\/code>\u6587\u4ef6\u5e76\u89e6\u53d1<code>AppRegistry.runApplication<\/code>\u8fd0\u884c\u5e94\u7528\u3002AppRegistry\u6709\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<p><!-- more --><\/p>\n<ul>\n<li><code>registerConfig(config: Array)<\/code>\uff1a\u9759\u6001\u65b9\u6cd5\uff0c\u6ce8\u518c\u914d\u7f6e<\/li>\n<li><code>registerComponent(appKey: string, getComponentFunc: ComponentProvider)<\/code>\uff1a\u6ce8\u518c\u5165\u53e3\u7ec4\u4ef6<\/li>\n<li><code>registerRunnable(appKey: string , func: Function)<\/code>\uff1a\u6ce8\u518c\u51fd\u6570\u76d1\u542c<\/li>\n<li><code>getAppKeys()<\/code>\uff1a\u83b7\u53d6<code>registerRunnable<\/code>\u6ce8\u518c\u7684\u76d1\u542c\u952e<\/li>\n<li><code>runApplication(appKey: string, appParameter: any)<\/code>\uff1a\u8fd0\u884cApp<\/li>\n<\/ul>\n<p>React Native\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u65f6\u4f1a\u5728log\u680f\u4e2d\u770b\u5230\u8fd9\u6837\u7684\u8f93\u51fa\uff0c\u8fd9\u4e9b\u65e5\u5fd7\u4fe1\u606f\u662f\u7531runApplication\u6253\u5370\u51fa\u6765\u7684\u3002 <\/p>\n<pre><code>Running application &quot;RNAPP&quot; with appParams: {&quot;initialProps&quot;:{},&quot;rootTag&quot;:1}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF<\/code><\/pre>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>alert(AppRegistry.runApplication)<\/code>\uff0c\u5728\u7a0b\u5e8f\u4e2d\u4ee5\u63d0\u793a\u6846\u7684\u5f62\u5f0f\u67e5\u770b<code>runApplication<\/code>\u51fd\u6570\u7684\u5b9a\u4e49\u3002<\/p>\n<p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>registerRunnable<\/code>\u6ce8\u518c\u4e00\u4e9bAppKey\uff0c\u5b9e\u4f8b\uff1a<\/p>\n<pre><code class=\"language-javascript\">AppRegistry.registerRunnable(&#039;rnapp&#039;, function() {\n    console.log(&#039;rnapp&#039;);\n})\nalert(AppRegistry.getAppKeys());<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u53ea\u6709\u914d\u5408\u4f7f\u7528React Native\u7684\u5e38\u7528\u7ec4\u4ef6\u548c\u5e38\u7528API\uff0c\u624d\u80fd\u66f4\u597d\u7684\u5f00\u53d1\u5e94\u7528\u7a0b\u5e8f AppRegistry\u662fJ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[163],"tags":[],"class_list":["post-503","post","type-post","status-publish","format-standard","hentry","category-react-native"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/503","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=503"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/503\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}