Explorar el Código

added missing native changes

Daniel Zlotin hace 8 años
padre
commit
a6e337c468
Se han modificado 3 ficheros con 77 adiciones y 19 borrados
  1. 0
    3
      .gitignore
  2. 9
    0
      .vscode/launchReactNative.js
  3. 68
    16
      ios/RNNControllerFactory.m

+ 0
- 3
.gitignore Ver fichero

@@ -1,7 +1,4 @@
1 1
 dist
2
-.vscode/
3
-
4
-
5 2
 
6 3
 ############
7 4
 # Node

+ 9
- 0
.vscode/launchReactNative.js Ver fichero

@@ -0,0 +1,9 @@
1
+// This file is automatically generated by vscode-react-native@0.2.5
2
+// Please do not modify it manually. All changes will be lost.
3
+try {
4
+    var path = require("path");
5
+    var Launcher = require("/Users/danielzl/.vscode/extensions/vsmobile.vscode-react-native-0.2.5/out/debugger/launcher.js").Launcher;
6
+    new Launcher("/Users/danielzl/dev/react-native-navigation", "/Users/danielzl/dev/react-native-navigation").launch();
7
+} catch (e) {
8
+    throw new Error("Unable to launch application. Try deleting .vscode/launchReactNative.js and restarting vscode.");
9
+}

+ 68
- 16
ios/RNNControllerFactory.m Ver fichero

@@ -4,6 +4,42 @@
4 4
 #import "RNN.h"
5 5
 #import "RCTRootView.h"
6 6
 
7
+@interface RNNLayoutNode : NSObject
8
+@property NSString* type;
9
+@property NSString* nodeId;
10
+@property NSDictionary* data;
11
+@property NSArray* children;
12
+@end
13
+
14
+@implementation RNNLayoutNode
15
+
16
++(instancetype)create:(NSDictionary *)json
17
+{
18
+	RNNLayoutNode* node = [RNNLayoutNode new];
19
+	node.type = json[@"type"];
20
+	node.nodeId = json[@"id"];
21
+	node.data = json[@"data"];
22
+	node.children = json[@"children"];
23
+	return node;
24
+}
25
+
26
+-(BOOL)isContainer
27
+{
28
+	return [self.type isEqualToString:@"Container"];
29
+}
30
+
31
+-(BOOL)isContainerStack
32
+{
33
+	return [self.type isEqualToString:@"ContainerStack"];
34
+}
35
+
36
+-(BOOL)isTabs
37
+{
38
+	return [self.type isEqualToString:@"Tabs"];
39
+}
40
+
41
+@end
42
+
7 43
 @implementation RNNControllerFactory
8 44
 
9 45
 -(UIViewController *)createRootViewController:(NSDictionary *)layout
@@ -11,45 +47,61 @@
11 47
 	return [self fromTree:layout];
12 48
 }
13 49
 
14
--(UIViewController*)fromTree:(NSDictionary*)node
50
+-(UIViewController*)fromTree:(NSDictionary*)json
15 51
 {
16
-	NSString* nodeType = node[@"type"];
17
-	
18
-	NSString* nodeId = node[@"id"];
19
-	NSArray* children = node[@"children"];
20
-	NSDictionary* data = node[@"data"];
52
+	RNNLayoutNode* node = [RNNLayoutNode create:json];
21 53
 	
22
-	if ([nodeType isEqualToString:@"Container"])
54
+	if (node.isContainer)
23 55
 	{
24
-		return [self createContainer:nodeId data:data];
25
-	} else if([nodeType isEqualToString:@"ContainerStack"])
56
+		return [self createContainer:node];
57
+	} else if(node.isContainerStack)
26 58
 	{
27
-		return [self createContainerStack:nodeId data:data children:children];
59
+		return [self createContainerStack:node];
60
+	} else if(node.isTabs)
61
+	{
62
+		return [self createTabs:node];
28 63
 	}
29 64
 	
30 65
 	@throw @"unknown container type";
31 66
 }
32 67
 
33
--(UIViewController*)createContainer:(NSString*)containerId data:(NSDictionary*)data
68
+-(UIViewController*)createContainer:(RNNLayoutNode*)node
34 69
 {
35
-	NSString* containerName = data[@"name"];
70
+	NSString* containerName = node.data[@"name"];
36 71
 	
37 72
 	RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:RNN.instance.bridge
38 73
 													  moduleName:containerName
39
-											   initialProperties:@{@"containerId": containerId}];
74
+											   initialProperties:@{@"containerId": node.nodeId}];
40 75
 	
41 76
 	UIViewController* controller = [UIViewController new];
42 77
 	controller.view = reactView;
43 78
 	return controller;
44 79
 }
45 80
 
46
--(UINavigationController*)createContainerStack:(NSString*)containerId data:(NSDictionary*)data children:(NSArray*)children
81
+-(UINavigationController*)createContainerStack:(RNNLayoutNode*)node
47 82
 {
48 83
 	UINavigationController* vc = [[UINavigationController alloc] init];
49 84
 	
50 85
 	NSMutableArray* controllers = [NSMutableArray new];
51
-	for (NSDictionary* node in children) {
52
-		[controllers addObject:[self fromTree:node]];
86
+	for (NSDictionary* child in node.children) {
87
+		[controllers addObject:[self fromTree:child]];
88
+	}
89
+	[vc setViewControllers:controllers];
90
+	
91
+	return vc;
92
+}
93
+
94
+-(UITabBarController*)createTabs:(RNNLayoutNode*)node
95
+{
96
+	UITabBarController* vc = [[UITabBarController alloc] init];
97
+	
98
+	NSMutableArray* controllers = [NSMutableArray new];
99
+	for (NSDictionary* child in node.children) {
100
+		UIViewController* childVc = [self fromTree:child];
101
+		
102
+		UITabBarItem* item = [[UITabBarItem alloc] initWithTitle:@"A Tab" image:nil tag:1];
103
+		[childVc setTabBarItem:item];
104
+		[controllers addObject:childVc];
53 105
 	}
54 106
 	[vc setViewControllers:controllers];
55 107