Browse Source

added skeleton support

Ran Greenberg 8 years ago
parent
commit
2dc32df48d
3 changed files with 125 additions and 22 deletions
  1. 3
    4
      ios/RCCManagerModule.m
  2. 112
    11
      ios/RNNViewController.m
  3. 10
    7
      src2/commands/valid-commands.js

+ 3
- 4
ios/RCCManagerModule.m View File

@@ -173,7 +173,7 @@ RCT_EXPORT_MODULE(RCCManager);
173 173
 }
174 174
 
175 175
 
176
--(void)startAppHelper:(NSDictionary*)layout
176
+-(void)startAppAfterBridgeFinishLoading:(NSDictionary*)layout
177 177
 {
178 178
     [[RCCManager sharedInstance] clearModuleRegistry];
179 179
     
@@ -182,7 +182,6 @@ RCT_EXPORT_MODULE(RCCManager);
182 182
     
183 183
     id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
184 184
     
185
-    // set the new controller as the root
186 185
     appDelegate.window.rootViewController = controller;
187 186
     [appDelegate.window makeKeyAndVisible];
188 187
 }
@@ -196,13 +195,13 @@ startApp:(NSDictionary*)layout)
196 195
 {
197 196
     if ([[RCCManager sharedInstance] getBridge].loading) {
198 197
         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0001 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
199
-            [self startAppHelper:layout];
198
+            [self startAppAfterBridgeFinishLoading:layout];
200 199
         });
201 200
         return;
202 201
     }
203 202
     
204 203
     dispatch_async(dispatch_get_main_queue(), ^{
205
-        [self startAppHelper:layout];
204
+        [self startAppAfterBridgeFinishLoading:layout];
206 205
     });
207 206
 }
208 207
 

+ 112
- 11
ios/RNNViewController.m View File

@@ -8,11 +8,14 @@
8 8
 
9 9
 #import "RNNViewController.h"
10 10
 #import "RCTRootView.h"
11
+#import "MMDrawerController.h"
11 12
 
12
-#define SCREEN              @"screen"
13
-#define SIDE_MENU           @"sideMenu"
14
-#define TABS                @"tabs"
15
-#define SCREEN_KEY          @"key"
13
+#define SCREEN                  @"screen"
14
+#define SIDE_MENU               @"sideMenu"
15
+#define TABS                    @"tabs"
16
+#define SCREEN_KEY              @"key"
17
+#define SIDE_MENU_LEFT          @"left"
18
+#define SIDE_MENU_RIGHT         @"right"
16 19
 
17 20
 
18 21
 @interface RNNViewController ()
@@ -22,36 +25,134 @@
22 25
 @implementation RNNViewController
23 26
 
24 27
 
25
-#pragma mark - Static function 
28
+#pragma mark - Static function
26 29
 
27 30
 
28 31
 + (UIViewController*)controllerWithLayout:(NSDictionary *)layout bridge:(RCTBridge *)bridge {
29 32
     
30 33
     UIViewController *controller = nil;
31
-    
32 34
     NSDictionary *screen = layout[SCREEN];
35
+    NSArray *tabs = layout[TABS];
36
+    NSDictionary *sideMenu = layout[SIDE_MENU];
37
+    
38
+    if (sideMenu) {
39
+        NSDictionary *centerScreenDictionary;
40
+        if (screen) {
41
+            centerScreenDictionary = @{SCREEN: screen};
42
+        }
43
+        else if (tabs){
44
+            centerScreenDictionary = @{TABS: layout[TABS]};
45
+        }
46
+        else {
47
+            return nil;
48
+        }
49
+        
50
+        UIViewController *centerViewController = [RNNViewController controllerWithLayout:centerScreenDictionary bridge:bridge];
51
+        controller = [RNNViewController sideMenuWithLayout:sideMenu centerViewController:centerViewController bridge:bridge];
52
+        
53
+        return controller;
54
+    }
55
+    
56
+    if (tabs) {
57
+        controller = [RNNViewController tabBarWithTabsArray:tabs bridge:bridge];
58
+        return controller;
59
+    }
60
+    
33 61
     if (screen) {
34 62
         NSString *screenKey = screen[SCREEN_KEY];
35
-        if (screenKey)
63
+        if (screenKey) {
64
+            controller = [RNNViewController navigationControllerWithScreenKey:screenKey bridge:bridge];
65
+        }
36 66
         
37
-        controller = [RNNViewController navigationControllerWithScreenKey:screenKey bridge:bridge];
67
+        return controller;
38 68
     }
39 69
     
40 70
     return controller;
71
+}
72
+
73
+
74
++(UIViewController*)controllerWithScreenKey:(NSString*)screenKey bridge:(RCTBridge *)bridge {
41 75
     
76
+    UIViewController *controller = nil;
77
+    
78
+    RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:bridge moduleName:screenKey initialProperties:nil];
79
+    if (!reactView) return nil;
80
+    
81
+    controller = [UIViewController new];
82
+    controller.view = reactView;
83
+    
84
+    return controller;
42 85
 }
43 86
 
87
+
44 88
 +(UINavigationController*)navigationControllerWithScreenKey:(NSString*)screenKey bridge:(RCTBridge*)bridge {
45 89
     
46 90
     UINavigationController *controller = nil;
47
-
48
-    UIViewController *viewController = [UIViewController new];
49
-    RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:bridge moduleName:SCREEN_KEY initialProperties:nil];
91
+    
92
+    UIViewController *viewController = [RNNViewController controllerWithScreenKey:screenKey bridge:bridge];
93
+    if (!viewController) return nil;
94
+    
50 95
     controller = [[UINavigationController alloc] initWithRootViewController:viewController];
96
+    [controller.tabBarItem setTitle:@"tab"];
51 97
     
52 98
     return controller;
53 99
 }
54 100
 
55 101
 
102
++(UIViewController*)sideMenuWithLayout:(NSDictionary*)layout centerViewController:(UIViewController*)centerViewController bridge:(RCTBridge*)bridge {
103
+    
104
+    UIViewController *leftViewController, *rightViewController, *sideMenuViewController = nil;
105
+    
106
+    NSDictionary *left = layout[SIDE_MENU_LEFT];
107
+    if (left) {
108
+        NSString *leftScreenKey = left[SCREEN_KEY];
109
+        leftViewController = [RNNViewController controllerWithScreenKey:leftScreenKey bridge:bridge];
110
+    }
111
+    
112
+    NSDictionary *right = layout[SIDE_MENU_RIGHT];
113
+    if (right) {
114
+        NSString *rightScreenKey = right[SCREEN_KEY];
115
+        rightViewController = [RNNViewController controllerWithScreenKey:rightScreenKey bridge:bridge];
116
+    }
117
+    
118
+    if (rightViewController || leftViewController) {
119
+        sideMenuViewController = [[MMDrawerController alloc] initWithCenterViewController:centerViewController leftDrawerViewController:leftViewController rightDrawerViewController:rightViewController];
120
+        
121
+        // TODO: CHANGE THIS
122
+        ((MMDrawerController*)sideMenuViewController).openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
123
+        ((MMDrawerController*)sideMenuViewController).closeDrawerGestureModeMask = MMCloseDrawerGestureModeAll;
124
+    }
125
+    
126
+    return sideMenuViewController;
127
+}
128
+
129
++(UITabBarController*)tabBarWithTabsArray:(NSArray*)tabsArray bridge:(RCTBridge*)bridge {
130
+    
131
+    UITabBarController *tabBarController = nil;
132
+    NSMutableArray *tabsViewControllersArray = [[NSMutableArray alloc] init];
133
+    
134
+    for (NSDictionary *tab in tabsArray) {
135
+        UIViewController *tabViewController = [RNNViewController controllerWithLayout:tab bridge:bridge];
136
+        if (tabViewController) {
137
+            [tabsViewControllersArray addObject:tabViewController];
138
+        }
139
+    }
140
+    if ([tabsViewControllersArray count] > 0) {
141
+        tabBarController = [UITabBarController new];
142
+        tabBarController.viewControllers = tabsViewControllersArray;
143
+    }
144
+    
145
+    return tabBarController;
146
+}
147
+
148
+-(void)viewWillAppear:(BOOL)animated {
149
+    [super viewWillAppear:animated];
150
+    
151
+}
152
+
153
+
154
+
155
+
156
+
56 157
 @end
57 158
 

+ 10
- 7
src2/commands/valid-commands.js View File

@@ -1,6 +1,6 @@
1 1
 export const singleScreenApp = {
2 2
   screen: {
3
-    key: 'com.example.MyScreen'
3
+    key: 'example.FirstTabScreen'
4 4
   }
5 5
 };
6 6
 
@@ -8,17 +8,17 @@ export const tabBasedApp = {
8 8
   tabs: [
9 9
     {
10 10
       screen: {
11
-        key: 'com.example.FirstTab'
11
+        key: 'com.example.FirstTabScreen'
12 12
       }
13 13
     },
14 14
     {
15 15
       screen: {
16
-        key: 'com.example.SecondTab'
16
+        key: 'com.example.SecondTabScreen'
17 17
       }
18 18
     },
19 19
     {
20 20
       screen: {
21
-        key: 'com.example.ThirdTab'
21
+        key: 'com.example.FirstTabScreen'
22 22
       }
23 23
     }
24 24
   ]
@@ -64,23 +64,26 @@ export const tabBasedWithSideMenu = {
64 64
   tabs: [
65 65
     {
66 66
       screen: {
67
-        key: 'com.example.FirstTab'
67
+        key: 'com.example.FirstTabScreen'
68 68
       }
69 69
     },
70 70
     {
71 71
       screen: {
72
-        key: 'com.example.SecondTab'
72
+        key: 'com.example.SecondTabScreen'
73 73
       }
74 74
     },
75 75
     {
76 76
       screen: {
77
-        key: 'com.example.ThirdTab'
77
+        key: 'com.example.FirstTabScreen'
78 78
       }
79 79
     }
80 80
   ],
81 81
   sideMenu: {
82 82
     left: {
83 83
       key: 'com.example.Menu1'
84
+    },
85
+    right: {
86
+        key: 'com.example.Menu2'
84 87
     }
85 88
   }
86 89
 };