且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

单个应用程序中的多个 RCTRootView

更新时间:2023-11-22 20:30:16

创建另一个 RCTRootView,就像创建任何其他 UIView 一样.

Create another RCTRootView, as you would any other UIView.

RCTRootView *someRootView = [[RCTRootView alloc] initWithBundleURL:someJsCodeLocation 
                                                        moduleName:@"SomeRootComponent" 
                                                     launchOptions:nil];

RCTRootView *anotherRootView = [[RCTRootView alloc] initWithBundleURL:anotherJsCodeLocation 
                                                           moduleName:@"AnotherRootComponent" 
                                                        launchOptions:nil];

您可以为所有 RCTRootView 指定相同的包 (jsCodeLocation),或为每个 RCTRootView 指定不同的包.在任何一种情况下,***做法是使用不同的组件名称 (moduleName):

You can specify the same bundle (jsCodeLocation) for all RCTRootViews, or different bundles for each RCTRootView. In either case its a best practice to have different component names (moduleName):

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

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

如果您想维护多个包,您需要使用以下命令编译每个包:

If you would like to maintain multiple bundles you will need to compile each with the command:

curl 'http://localhost:8082/index1.ios.bundle?dev=false&minify=true' -o iOS/main1.jsbundle

curl 'http://localhost:8082/index2.ios.bundle?dev=false&minify=true' -o iOS/main2.jsbundle

main1.jsbundle 和 main2.jsbundle 然后可以添加到您的项目中并正常引用.

main1.jsbundle and main2.jsbundle can then be added to your project and referenced normally.