1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
-
- #import "RNNReactRootViewCreator.h"
- #import "RNNReactView.h"
-
- @implementation RNNReactRootViewCreator {
- RCTBridge *_bridge;
- RNNEventEmitter* _eventEmitter;
- }
-
- - (instancetype)initWithBridge:(RCTBridge*)bridge eventEmitter:(RNNEventEmitter*)eventEmitter {
- self = [super init];
- _bridge = bridge;
- _eventEmitter = eventEmitter;
- return self;
- }
-
- - (RNNReactView*)createRootView:(NSString*)name rootViewId:(NSString*)rootViewId ofType:(RNNComponentType)componentType reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock {
- [self verifyRootViewId:rootViewId];
- return [[[self resolveComponentViewClass:componentType] alloc] initWithBridge:_bridge
- moduleName:name
- initialProperties:@{@"componentId": rootViewId}
- eventEmitter:_eventEmitter
- reactViewReadyBlock:reactViewReadyBlock];
- }
-
- - (Class)resolveComponentViewClass:(RNNComponentType)componentType {
- switch (componentType) {
- case RNNComponentTypeTopBarTitle:
- return RNNReactTitleView.class;
- case RNNComponentTypeTopBarButton:
- return RNNReactButtonView.class;
- case RNNComponentTypeTopBarBackground:
- return RNNReactBackgroundView.class;
- case RNNComponentTypeComponent:
- default:
- return RNNReactView.class;
- }
- }
-
- - (void)verifyRootViewId:(NSString *)rootViewId {
- if (!rootViewId) {
- @throw [NSException exceptionWithName:@"MissingViewId" reason:@"Missing view id" userInfo:nil];
- }
- }
-
- @end
|