Browse Source

added RNNViewController some functionality

Ran Greenberg 8 years ago
parent
commit
83fb6efc1f
3 changed files with 77 additions and 4 deletions
  1. 33
    3
      ios/RCCManagerModule.m
  2. 5
    0
      ios/RNNViewController.h
  3. 39
    1
      ios/RNNViewController.m

+ 33
- 3
ios/RCCManagerModule.m View File

10
 #import "RCCTheSideBarManagerViewController.h"
10
 #import "RCCTheSideBarManagerViewController.h"
11
 #import "RCCNotification.h"
11
 #import "RCCNotification.h"
12
 
12
 
13
+#import "RNNViewController.h"
14
+
13
 #define kSlideDownAnimationDuration 0.35
15
 #define kSlideDownAnimationDuration 0.35
14
 
16
 
15
 typedef NS_ENUM(NSInteger, RCCManagerModuleErrorCode)
17
 typedef NS_ENUM(NSInteger, RCCManagerModuleErrorCode)
170
     }
172
     }
171
 }
173
 }
172
 
174
 
175
+
176
+-(void)startAppHelper:(NSDictionary*)layout
177
+{
178
+    [[RCCManager sharedInstance] clearModuleRegistry];
179
+    
180
+    UIViewController *controller = [RNNViewController controllerWithLayout:layout bridge:[[RCCManager sharedInstance] getBridge]];
181
+    if (controller == nil) return;
182
+    
183
+    id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
184
+    
185
+    // set the new controller as the root
186
+    appDelegate.window.rootViewController = controller;
187
+    [appDelegate.window makeKeyAndVisible];
188
+}
189
+
190
+
173
 #pragma mark - RCT exported methods
191
 #pragma mark - RCT exported methods
174
 
192
 
175
 
193
 
176
 RCT_EXPORT_METHOD(
194
 RCT_EXPORT_METHOD(
177
-startApp:(NSDictionary*)layout) {
178
-
179
-    NSLog(@"layout:%@", layout);
195
+startApp:(NSDictionary*)layout)
196
+{
197
+    if ([[RCCManager sharedInstance] getBridge].loading) {
198
+        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0001 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
199
+            [self startAppHelper:layout];
200
+        });
201
+        return;
202
+    }
203
+    
204
+    dispatch_async(dispatch_get_main_queue(), ^{
205
+        [self startAppHelper:layout];
206
+    });
180
 }
207
 }
181
 
208
 
182
 
209
 
184
 RCT_EXPORT_METHOD(
211
 RCT_EXPORT_METHOD(
185
 setRootController:(NSDictionary*)layout animationType:(NSString*)animationType globalProps:(NSDictionary*)globalProps)
212
 setRootController:(NSDictionary*)layout animationType:(NSString*)animationType globalProps:(NSDictionary*)globalProps)
186
 {
213
 {
214
+    
187
     if ([[RCCManager sharedInstance] getBridge].loading) {
215
     if ([[RCCManager sharedInstance] getBridge].loading) {
188
         [self deferSetRootControllerWhileBridgeLoading:layout animationType:animationType globalProps:globalProps];
216
         [self deferSetRootControllerWhileBridgeLoading:layout animationType:animationType globalProps:globalProps];
189
         return;
217
         return;
194
    });
222
    });
195
 }
223
 }
196
 
224
 
225
+
226
+
197
 /**
227
 /**
198
  * on RN31 there's a timing issue, we must wait for the bridge to finish loading
228
  * on RN31 there's a timing issue, we must wait for the bridge to finish loading
199
  */
229
  */

+ 5
- 0
ios/RNNViewController.h View File

7
 //
7
 //
8
 
8
 
9
 #import <UIKit/UIKit.h>
9
 #import <UIKit/UIKit.h>
10
+#import "RCTBridge.h"
11
+
10
 
12
 
11
 @interface RNNViewController : UIViewController
13
 @interface RNNViewController : UIViewController
12
 
14
 
15
++ (UIViewController*)controllerWithLayout:(NSDictionary *)layout bridge:(RCTBridge *)bridge;
16
+
17
+
13
 @end
18
 @end

+ 39
- 1
ios/RNNViewController.m View File

7
 //
7
 //
8
 
8
 
9
 #import "RNNViewController.h"
9
 #import "RNNViewController.h"
10
+#import "RCTRootView.h"
11
+
12
+#define SCREEN              @"screen"
13
+#define SIDE_MENU           @"sideMenu"
14
+#define TABS                @"tabs"
15
+#define SCREEN_KEY          @"key"
10
 
16
 
11
-@interface RNNViewController ()
12
 
17
 
18
+@interface RNNViewController ()
13
 @end
19
 @end
14
 
20
 
21
+
15
 @implementation RNNViewController
22
 @implementation RNNViewController
16
 
23
 
17
 
24
 
25
+#pragma mark - Static function 
26
+
27
+
28
++ (UIViewController*)controllerWithLayout:(NSDictionary *)layout bridge:(RCTBridge *)bridge {
29
+    
30
+    UIViewController *controller = nil;
31
+    
32
+    NSDictionary *screen = layout[SCREEN];
33
+    if (screen) {
34
+        NSString *screenKey = screen[SCREEN_KEY];
35
+        if (screenKey)
36
+        
37
+        controller = [RNNViewController navigationControllerWithScreenKey:screenKey bridge:bridge];
38
+    }
39
+    
40
+    return controller;
41
+    
42
+}
43
+
44
++(UINavigationController*)navigationControllerWithScreenKey:(NSString*)screenKey bridge:(RCTBridge*)bridge {
45
+    
46
+    UINavigationController *controller = nil;
47
+
48
+    UIViewController *viewController = [UIViewController new];
49
+    RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:bridge moduleName:SCREEN_KEY initialProperties:nil];
50
+    controller = [[UINavigationController alloc] initWithRootViewController:viewController];
51
+    
52
+    return controller;
53
+}
54
+
18
 
55
 
19
 @end
56
 @end
57
+