Multiple RCTRootView in a single App

前端 未结 1 1588
隐瞒了意图╮
隐瞒了意图╮ 2021-02-10 13:53

I am creating a react native app but i require the use of objective C to build my custom UIView. But issue is that this UIView need to display react content. e.g. a react text i

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-10 14:18

    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];
    

    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 and main2.jsbundle can then be added to your project and referenced normally.

    0 讨论(0)
提交回复
热议问题