123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
-
- #import "RNNControllerFactory.h"
-
- #import "RNN.h"
- #import "RCTRootView.h"
-
- @implementation RNNControllerFactory
-
- -(UIViewController *)createRootViewController:(NSDictionary *)layout
- {
- return [self fromTree:layout];
- }
-
- -(UIViewController*)fromTree:(NSDictionary*)node
- {
- NSString* nodeType = node[@"type"];
-
- NSString* nodeId = node[@"id"];
- NSArray* children = node[@"children"];
- NSDictionary* data = node[@"data"];
-
- if ([nodeType isEqualToString:@"Container"])
- {
- return [self createContainer:nodeId data:data];
- } else if([nodeType isEqualToString:@"ContainerStack"])
- {
- return [self createContainerStack:nodeId data:data children:children];
- }
-
- @throw @"unknown container type";
- }
-
- -(UIViewController*)createContainer:(NSString*)containerId data:(NSDictionary*)data
- {
- NSString* containerName = data[@"name"];
-
- RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:RNN.instance.bridge
- moduleName:containerName
- initialProperties:@{@"containerId": containerId}];
-
- UIViewController* controller = [UIViewController new];
- controller.view = reactView;
- return controller;
- }
-
- -(UINavigationController*)createContainerStack:(NSString*)containerId data:(NSDictionary*)data children:(NSArray*)children
- {
- UINavigationController* vc = [[UINavigationController alloc] init];
-
- NSMutableArray* controllers = [NSMutableArray new];
- for (NSDictionary* node in children) {
- [controllers addObject:[self fromTree:node]];
- }
- [vc setViewControllers:controllers];
-
- return vc;
- }
-
- @end
|