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
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.