Ver código fonte

added RNNViewController some functionality

Ran Greenberg 7 anos atrás
pai
commit
83fb6efc1f
3 arquivos alterados com 77 adições e 4 exclusões
  1. 33
    3
      ios/RCCManagerModule.m
  2. 5
    0
      ios/RNNViewController.h
  3. 39
    1
      ios/RNNViewController.m

+ 33
- 3
ios/RCCManagerModule.m Ver arquivo

@@ -10,6 +10,8 @@
10 10
 #import "RCCTheSideBarManagerViewController.h"
11 11
 #import "RCCNotification.h"
12 12
 
13
+#import "RNNViewController.h"
14
+
13 15
 #define kSlideDownAnimationDuration 0.35
14 16
 
15 17
 typedef NS_ENUM(NSInteger, RCCManagerModuleErrorCode)
@@ -170,13 +172,38 @@ RCT_EXPORT_MODULE(RCCManager);
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 191
 #pragma mark - RCT exported methods
174 192
 
175 193
 
176 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,6 +211,7 @@ startApp:(NSDictionary*)layout) {
184 211
 RCT_EXPORT_METHOD(
185 212
 setRootController:(NSDictionary*)layout animationType:(NSString*)animationType globalProps:(NSDictionary*)globalProps)
186 213
 {
214
+    
187 215
     if ([[RCCManager sharedInstance] getBridge].loading) {
188 216
         [self deferSetRootControllerWhileBridgeLoading:layout animationType:animationType globalProps:globalProps];
189 217
         return;
@@ -194,6 +222,8 @@ setRootController:(NSDictionary*)layout animationType:(NSString*)animationType g
194 222
    });
195 223
 }
196 224
 
225
+
226
+
197 227
 /**
198 228
  * on RN31 there's a timing issue, we must wait for the bridge to finish loading
199 229
  */

+ 5
- 0
ios/RNNViewController.h Ver arquivo

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

+ 39
- 1
ios/RNNViewController.m Ver arquivo

@@ -7,13 +7,51 @@
7 7
 //
8 8
 
9 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 19
 @end
14 20
 
21
+
15 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 56
 @end
57
+