|
@@ -6,28 +6,34 @@
|
6
|
6
|
|
7
|
7
|
@implementation RNNControllerFactory
|
8
|
8
|
|
9
|
|
-+(UIViewController *)createRootViewController:(NSDictionary *)layout
|
|
9
|
+-(UIViewController *)createRootViewController:(NSDictionary *)layout
|
10
|
10
|
{
|
11
|
|
- if ([layout[@"type"] isEqualToString:@"ContainerStack"]) {
|
12
|
|
- UINavigationController* stack = [[UINavigationController alloc] init];
|
13
|
|
-
|
14
|
|
- NSString* containerName = [layout[@"children"] objectAtIndex:0][@"data"][@"name"];
|
15
|
|
- NSString* containerId = [layout[@"children"] objectAtIndex:0][@"id"];
|
16
|
|
-
|
17
|
|
- [stack setViewControllers:@[[RNNControllerFactory create:containerName containerId:containerId]] animated:false];
|
18
|
|
-
|
19
|
|
- return stack;
|
20
|
|
- }
|
|
11
|
+ return [self fromTree:layout];
|
|
12
|
+}
|
|
13
|
+
|
|
14
|
+-(UIViewController*)fromTree:(NSDictionary*)node
|
|
15
|
+{
|
|
16
|
+ NSString* nodeType = node[@"type"];
|
|
17
|
+
|
|
18
|
+ NSString* nodeId = node[@"id"];
|
|
19
|
+ NSArray* children = node[@"children"];
|
|
20
|
+ NSDictionary* data = node[@"data"];
|
21
|
21
|
|
22
|
|
-// NSString* containerName = layout[@"container"][@"name"];
|
23
|
|
-// NSString* containerId = layout[@"container"][@"id"];
|
|
22
|
+ if ([nodeType isEqualToString:@"Container"])
|
|
23
|
+ {
|
|
24
|
+ return [self createContainer:nodeId data:data];
|
|
25
|
+ } else if([nodeType isEqualToString:@"ContainerStack"])
|
|
26
|
+ {
|
|
27
|
+ return [self createContainerStack:nodeId data:data children:children];
|
|
28
|
+ }
|
24
|
29
|
|
25
|
|
-// return [RNNControllerFactory create:containerName containerId:containerId];
|
26
|
|
- return nil;
|
|
30
|
+ @throw @"unknown container type";
|
27
|
31
|
}
|
28
|
32
|
|
29
|
|
-+(UIViewController*)create:(NSString*)containerName containerId:(NSString*)containerId
|
|
33
|
+-(UIViewController*)createContainer:(NSString*)containerId data:(NSDictionary*)data
|
30
|
34
|
{
|
|
35
|
+ NSString* containerName = data[@"name"];
|
|
36
|
+
|
31
|
37
|
RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:RNN.instance.bridge
|
32
|
38
|
moduleName:containerName
|
33
|
39
|
initialProperties:@{@"containerId": containerId}];
|
|
@@ -37,4 +43,17 @@
|
37
|
43
|
return controller;
|
38
|
44
|
}
|
39
|
45
|
|
|
46
|
+-(UINavigationController*)createContainerStack:(NSString*)containerId data:(NSDictionary*)data children:(NSArray*)children
|
|
47
|
+{
|
|
48
|
+ UINavigationController* vc = [[UINavigationController alloc] init];
|
|
49
|
+
|
|
50
|
+ NSMutableArray* controllers = [NSMutableArray new];
|
|
51
|
+ for (NSDictionary* node in children) {
|
|
52
|
+ [controllers addObject:[self fromTree:node]];
|
|
53
|
+ }
|
|
54
|
+ [vc setViewControllers:controllers];
|
|
55
|
+
|
|
56
|
+ return vc;
|
|
57
|
+}
|
|
58
|
+
|
40
|
59
|
@end
|