Bladeren bron

bootstrapping

Daniel Zlotin 7 jaren geleden
bovenliggende
commit
b3006d3fac

+ 8
- 0
ios/RNNBridgeModule.m Bestand weergeven

@@ -1,4 +1,6 @@
1 1
 #import "RNNBridgeModule.h"
2
+#import "RNNStore.h"
3
+#import "RCTRootView.h"
2 4
 
3 5
 @implementation RNNBridgeModule
4 6
 
@@ -11,7 +13,13 @@ RCT_EXPORT_MODULE(NativeNavigation);
11 13
 
12 14
 RCT_EXPORT_METHOD(startApp:(NSDictionary*)layout)
13 15
 {
16
+    RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:RNNStore.sharedInstance.bridge moduleName:@"com.example.WelcomeScreen" initialProperties:@[@{@"containerId": @"123"}]];
14 17
     
18
+    UIViewController* controller = [UIViewController new];
19
+    controller.view = reactView;
20
+
21
+    RNNStore.appDelegate.window.rootViewController = controller;
22
+    [RNNStore.appDelegate.window makeKeyAndVisible];
15 23
 }
16 24
 
17 25
 @end

+ 7
- 0
ios/RNNSplashScreen.h Bestand weergeven

@@ -0,0 +1,7 @@
1
+#import <Foundation/Foundation.h>
2
+
3
+@interface RNNSplashScreen : NSObject
4
+
5
+-(void)showSplashScreen;
6
+
7
+@end

+ 76
- 0
ios/RNNSplashScreen.m Bestand weergeven

@@ -0,0 +1,76 @@
1
+
2
+#import "RNNSplashScreen.h"
3
+#import <UIKit/UIKit.h>
4
+
5
+@implementation RNNSplashScreen
6
+
7
+-(void)showSplashScreen
8
+{
9
+    CGRect screenBounds = [UIScreen mainScreen].bounds;
10
+    UIView *splashView = nil;
11
+    
12
+    NSString* launchStoryBoard = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
13
+    if (launchStoryBoard != nil)
14
+    {//load the splash from the storyboard that's defined in the info.plist as the LaunchScreen
15
+        @try
16
+        {
17
+            splashView = [[NSBundle mainBundle] loadNibNamed:launchStoryBoard owner:self options:nil][0];
18
+            if (splashView != nil)
19
+            {
20
+                splashView.frame = CGRectMake(0, 0, screenBounds.size.width, screenBounds.size.height);
21
+            }
22
+        }
23
+        @catch(NSException *e)
24
+        {
25
+            splashView = nil;
26
+        }
27
+    }
28
+    else
29
+    {//load the splash from the DEfault image or from LaunchImage in the xcassets
30
+        CGFloat screenHeight = screenBounds.size.height;
31
+        
32
+        NSString* imageName = @"Default";
33
+        if (screenHeight == 568)
34
+            imageName = [imageName stringByAppendingString:@"-568h"];
35
+        else if (screenHeight == 667)
36
+            imageName = [imageName stringByAppendingString:@"-667h"];
37
+        else if (screenHeight == 736)
38
+            imageName = [imageName stringByAppendingString:@"-736h"];
39
+        
40
+        //xcassets LaunchImage files
41
+        UIImage *image = [UIImage imageNamed:imageName];
42
+        if (image == nil)
43
+        {
44
+            imageName = @"LaunchImage";
45
+            
46
+            if (screenHeight == 480)
47
+                imageName = [imageName stringByAppendingString:@"-700"];
48
+            if (screenHeight == 568)
49
+                imageName = [imageName stringByAppendingString:@"-700-568h"];
50
+            else if (screenHeight == 667)
51
+                imageName = [imageName stringByAppendingString:@"-800-667h"];
52
+            else if (screenHeight == 736)
53
+                imageName = [imageName stringByAppendingString:@"-800-Portrait-736h"];
54
+            
55
+            image = [UIImage imageNamed:imageName];
56
+        }
57
+        
58
+        if (image != nil)
59
+        {
60
+            splashView = [[UIImageView alloc] initWithImage:image];
61
+        }
62
+    }
63
+    
64
+    if (splashView != nil)
65
+    {
66
+        UIViewController *splashVC = [[UIViewController alloc] init];
67
+        splashVC.view = splashView;
68
+        
69
+        id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
70
+        appDelegate.window.rootViewController = splashVC;
71
+        [appDelegate.window makeKeyAndVisible];
72
+    }
73
+    
74
+}
75
+
76
+@end

+ 14
- 0
ios/RNNStore.h Bestand weergeven

@@ -0,0 +1,14 @@
1
+
2
+#import <Foundation/Foundation.h>
3
+#import <UIKit/UIKit.h>
4
+#import "RCTBridgeModule.h"
5
+
6
+@interface RNNStore : NSObject
7
+
8
+@property (atomic, strong) RCTBridge* bridge;
9
+
10
++(instancetype)sharedInstance;
11
+
12
++(id<UIApplicationDelegate>)appDelegate;
13
+
14
+@end

+ 28
- 0
ios/RNNStore.m Bestand weergeven

@@ -0,0 +1,28 @@
1
+
2
+#import "RNNStore.h"
3
+
4
+@interface RNNStore()
5
+
6
+@end
7
+
8
+@implementation RNNStore
9
+
10
++(instancetype)sharedInstance
11
+{
12
+    static RNNStore *sharedInstance = nil;
13
+    static dispatch_once_t onceToken = 0;
14
+    dispatch_once(&onceToken,^{
15
+        if (sharedInstance == nil)
16
+        {
17
+            sharedInstance = [[RNNStore alloc] init];
18
+        }
19
+    });
20
+    
21
+    return sharedInstance;
22
+}
23
+
24
++(id<UIApplicationDelegate>)appDelegate {
25
+    return UIApplication.sharedApplication.delegate;
26
+}
27
+
28
+@end

+ 12
- 0
ios/ReactNativeNavigation.h Bestand weergeven

@@ -0,0 +1,12 @@
1
+
2
+#import <Foundation/Foundation.h>
3
+#import <UIKit/UIKit.h>
4
+
5
+@interface ReactNativeNavigation : NSObject
6
+
7
++(void)bootstrap:(NSURL*)jsCodeLocation;
8
+
9
++(void)bootstrap:(NSURL*)jsCodeLocation
10
+   launchOptions:(NSDictionary *)launchOptions;
11
+
12
+@end

+ 22
- 0
ios/ReactNativeNavigation.m Bestand weergeven

@@ -0,0 +1,22 @@
1
+
2
+#import "ReactNativeNavigation.h"
3
+#import "RNNStore.h"
4
+#import "RCTBridge.h"
5
+
6
+@implementation ReactNativeNavigation
7
+
8
++(void)bootstrap:(NSURL *)jsCodeLocation
9
+{
10
+    [ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:nil];
11
+}
12
+
13
++(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions
14
+{
15
+    RNNStore.appDelegate.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
16
+    RNNStore.appDelegate.window.backgroundColor = [UIColor whiteColor];
17
+    
18
+    RCTBridge* bridge = [[RCTBridge alloc] initWithBundleURL:jsCodeLocation moduleProvider:nil launchOptions:launchOptions];
19
+    RNNStore.sharedInstance.bridge = bridge;
20
+}
21
+
22
+@end

+ 18
- 0
ios/ReactNativeNavigation.xcodeproj/project.pbxproj Bestand weergeven

@@ -13,7 +13,10 @@
13 13
 		2636176F1E12722900D88A13 /* RNNTabBarController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2636176E1E12722900D88A13 /* RNNTabBarController.m */; };
14 14
 		2636F1611E0EC9E7007ABB09 /* RNNStyler.m in Sources */ = {isa = PBXBuildFile; fileRef = 2636F1601E0EC9E7007ABB09 /* RNNStyler.m */; };
15 15
 		26AFF3F51D7EEE2400CBA211 /* RCCTitleViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 26AFF3F41D7EEE2400CBA211 /* RCCTitleViewHelper.m */; };
16
+		7BA500751E2544B9001B9E1B /* ReactNativeNavigation.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BA500741E2544B9001B9E1B /* ReactNativeNavigation.m */; };
17
+		7BA500781E254908001B9E1B /* RNNSplashScreen.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BA500771E254908001B9E1B /* RNNSplashScreen.m */; };
16 18
 		7BBFE5441E25330E002A6182 /* RNNBridgeModule.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BBFE5431E25330E002A6182 /* RNNBridgeModule.m */; };
19
+		7BBFE5611E253F97002A6182 /* RNNStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BBFE5601E253F97002A6182 /* RNNStore.m */; };
17 20
 		CC84A19E1C1A0C4E00B3A6A2 /* RCCManager.m in Sources */ = {isa = PBXBuildFile; fileRef = CC84A1941C1A0C4E00B3A6A2 /* RCCManager.m */; };
18 21
 		CC84A19F1C1A0C4E00B3A6A2 /* RCCManagerModule.m in Sources */ = {isa = PBXBuildFile; fileRef = CC84A1961C1A0C4E00B3A6A2 /* RCCManagerModule.m */; };
19 22
 		CC84A1A01C1A0C4E00B3A6A2 /* RCCNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = CC84A1981C1A0C4E00B3A6A2 /* RCCNavigationController.m */; };
@@ -65,8 +68,14 @@
65 68
 		2636F1601E0EC9E7007ABB09 /* RNNStyler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNStyler.m; sourceTree = "<group>"; };
66 69
 		26AFF3F31D7EEE2400CBA211 /* RCCTitleViewHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCTitleViewHelper.h; sourceTree = "<group>"; };
67 70
 		26AFF3F41D7EEE2400CBA211 /* RCCTitleViewHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCCTitleViewHelper.m; sourceTree = "<group>"; };
71
+		7BA500731E2544B9001B9E1B /* ReactNativeNavigation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReactNativeNavigation.h; sourceTree = "<group>"; };
72
+		7BA500741E2544B9001B9E1B /* ReactNativeNavigation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReactNativeNavigation.m; sourceTree = "<group>"; };
73
+		7BA500761E254908001B9E1B /* RNNSplashScreen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNSplashScreen.h; sourceTree = "<group>"; };
74
+		7BA500771E254908001B9E1B /* RNNSplashScreen.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNSplashScreen.m; sourceTree = "<group>"; };
68 75
 		7BBFE5421E25330E002A6182 /* RNNBridgeModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNBridgeModule.h; sourceTree = "<group>"; };
69 76
 		7BBFE5431E25330E002A6182 /* RNNBridgeModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNBridgeModule.m; sourceTree = "<group>"; };
77
+		7BBFE55F1E253F97002A6182 /* RNNStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNStore.h; sourceTree = "<group>"; };
78
+		7BBFE5601E253F97002A6182 /* RNNStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNStore.m; sourceTree = "<group>"; };
70 79
 		CC84A1931C1A0C4E00B3A6A2 /* RCCManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCManager.h; sourceTree = "<group>"; };
71 80
 		CC84A1941C1A0C4E00B3A6A2 /* RCCManager.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.objc; path = RCCManager.m; sourceTree = "<group>"; tabWidth = 2; };
72 81
 		CC84A1951C1A0C4E00B3A6A2 /* RCCManagerModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCManagerModule.h; sourceTree = "<group>"; };
@@ -242,6 +251,12 @@
242 251
 		D8AFADB41BEE6F3F00A4592D = {
243 252
 			isa = PBXGroup;
244 253
 			children = (
254
+				7BA500731E2544B9001B9E1B /* ReactNativeNavigation.h */,
255
+				7BA500741E2544B9001B9E1B /* ReactNativeNavigation.m */,
256
+				7BA500761E254908001B9E1B /* RNNSplashScreen.h */,
257
+				7BA500771E254908001B9E1B /* RNNSplashScreen.m */,
258
+				7BBFE55F1E253F97002A6182 /* RNNStore.h */,
259
+				7BBFE5601E253F97002A6182 /* RNNStore.m */,
245 260
 				7BBFE5421E25330E002A6182 /* RNNBridgeModule.h */,
246 261
 				7BBFE5431E25330E002A6182 /* RNNBridgeModule.m */,
247 262
 				7BBFE53F1E253144002A6182 /* old */,
@@ -324,6 +339,7 @@
324 339
 			isa = PBXSourcesBuildPhase;
325 340
 			buildActionMask = 2147483647;
326 341
 			files = (
342
+				7BA500751E2544B9001B9E1B /* ReactNativeNavigation.m in Sources */,
327 343
 				D85082EA1CBCF54200FDB961 /* TheSidebarController.m in Sources */,
328 344
 				CC84A1A01C1A0C4E00B3A6A2 /* RCCNavigationController.m in Sources */,
329 345
 				D83514F61D29719A00D53758 /* RCCNotification.m in Sources */,
@@ -346,10 +362,12 @@
346 362
 				CC84A1A21C1A0C4E00B3A6A2 /* RCCViewController.m in Sources */,
347 363
 				2636F1611E0EC9E7007ABB09 /* RNNStyler.m in Sources */,
348 364
 				263617541E124FA100D88A13 /* RNNNavigationController.m in Sources */,
365
+				7BA500781E254908001B9E1B /* RNNSplashScreen.m in Sources */,
349 366
 				2606F7DA1E0BC3FC00CC69CC /* RNNViewController.m in Sources */,
350 367
 				D85082E91CBCF54200FDB961 /* SidebarWunderlistAnimation.m in Sources */,
351 368
 				D85082E11CBCF54200FDB961 /* RCCDrawerHelper.m in Sources */,
352 369
 				D85082FE1CBCF8A800FDB961 /* MMDrawerVisualState.m in Sources */,
370
+				7BBFE5611E253F97002A6182 /* RNNStore.m in Sources */,
353 371
 				D85082FD1CBCF8A800FDB961 /* MMDrawerController.m in Sources */,
354 372
 				D85082E41CBCF54200FDB961 /* SidebarAnimation.m in Sources */,
355 373
 				D8E11C571CBD1F670018B644 /* RCCDrawerController.m in Sources */,

+ 2
- 4
playground/ios/playground/AppDelegate.m Bestand weergeven

@@ -3,7 +3,7 @@
3 3
 // **********************************************
4 4
 // *** DON'T MISS: THE NEXT LINE IS IMPORTANT ***
5 5
 // **********************************************
6
-#import "RCCManager.h"
6
+#import "ReactNativeNavigation.h"
7 7
 
8 8
 // IMPORTANT: if you're getting an Xcode error that RCCManager.h isn't found, you've probably ran "npm install"
9 9
 // with npm ver 2. You'll need to "npm install" with npm 3 (see https://github.com/wix/react-native-navigation/issues/1)
@@ -25,9 +25,7 @@
25 25
   // **********************************************
26 26
   // *** DON'T MISS: THIS IS HOW WE BOOTSTRAP *****
27 27
   // **********************************************
28
-  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
29
-  self.window.backgroundColor = [UIColor whiteColor];
30
-  [[RCCManager sharedInstance] initBridgeWithBundleURL:jsCodeLocation];
28
+  [ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];
31 29
 
32 30
   /*
33 31
   // original RN bootstrap - remove this part

+ 1
- 1
src/containers/ContainerRegistry.js Bestand weergeven

@@ -14,7 +14,7 @@ function wrapContainer(containerKey, OriginalContainer) {
14 14
     constructor(props) {
15 15
       super(props);
16 16
       if (!props.containerId) {
17
-        throw new Error(`Container ${containerKey} does not have a containerId!`);
17
+        //throw new Error(`Container ${containerKey} does not have a containerId!`);
18 18
       }
19 19
       this.state = {
20 20
         containerId: props.containerId,