Daniel Zlotin 7 лет назад
Родитель
Сommit
faabe928ac

+ 0
- 11
ios/RNN.h Просмотреть файл

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

+ 0
- 101
ios/RNN.m Просмотреть файл

@@ -1,101 +0,0 @@
1
-
2
-#import "RNN.h"
3
-#import <React/RCTBridge.h>
4
-
5
-#import "RNNEventEmitter.h"
6
-#import "RNNSplashScreen.h"
7
-#import "RNNBridgeModule.h"
8
-#import "RNNRootViewCreator.h"
9
-#import "RNNReactRootViewCreator.h"
10
-
11
-@interface RNN() <RCTBridgeDelegate>
12
-
13
-@end
14
-
15
-@implementation RNN {
16
-	NSURL* _jsCodeLocation;
17
-	NSDictionary* _launchOptions;
18
-	RNNStore* _store;
19
-	RCTBridge* _bridge;
20
-}
21
-
22
-+(instancetype) sharedInstance {
23
-	static RNN *instance = nil;
24
-	static dispatch_once_t onceToken = 0;
25
-	dispatch_once(&onceToken,^{
26
-		if (instance == nil)
27
-		{
28
-			instance = [[RNN alloc] init];
29
-		}
30
-	});
31
-	
32
-	return instance;
33
-}
34
-
35
-# pragma mark public
36
-
37
--(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions {
38
-	_jsCodeLocation = jsCodeLocation;
39
-	_launchOptions = launchOptions;
40
-	_store = [RNNStore new];
41
-
42
-	[RNNSplashScreen show];
43
-	
44
-	[self registerForJsEvents];
45
-	
46
-	[self createBridgeLoadJsThenInitDependencyGraph];
47
-}
48
-
49
-# pragma mark - RCTBridgeDelegate
50
-
51
--(NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
52
-	return _jsCodeLocation;
53
-}
54
-
55
--(NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge {
56
-	RNNEventEmitter *eventEmitter = [[RNNEventEmitter alloc] init];
57
-	
58
-	id<RNNRootViewCreator> rootViewCreator = [[RNNReactRootViewCreator alloc] initWithBridge:bridge];
59
-	RNNControllerFactory *controllerFactory = [[RNNControllerFactory alloc] initWithRootViewCreator:rootViewCreator store:_store eventEmitter:eventEmitter];
60
-	RNNCommandsHandler *commandsHandler = [[RNNCommandsHandler alloc] initWithStore:_store controllerFactory:controllerFactory];
61
-	RNNBridgeModule *bridgeModule = [[RNNBridgeModule alloc] initWithCommandsHandler:commandsHandler];
62
-	
63
-	return @[bridgeModule,eventEmitter];
64
-}
65
-
66
-# pragma mark - js events
67
-
68
--(void)onJavaScriptWillLoad {
69
-	[_store clean];
70
-	[self resetRootViewControllerOnlyOnJSDevReload];
71
-}
72
-
73
--(void)onJavaScriptLoaded {
74
-	[_store setReadyToReceiveCommands:true];
75
-	[[_bridge moduleForClass:[RNNEventEmitter class]] sendOnAppLaunched];
76
-}
77
-
78
-# pragma mark - private
79
-
80
--(void)createBridgeLoadJsThenInitDependencyGraph {
81
-	_bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:_launchOptions];
82
-}
83
-
84
--(void)registerForJsEvents {
85
-	[[NSNotificationCenter defaultCenter] addObserver:self
86
-											 selector:@selector(onJavaScriptLoaded)
87
-												 name:RCTJavaScriptDidLoadNotification
88
-											   object:nil];
89
-	[[NSNotificationCenter defaultCenter] addObserver:self
90
-											 selector:@selector(onJavaScriptWillLoad)
91
-												 name:RCTJavaScriptWillStartLoadingNotification
92
-											   object:nil];
93
-}
94
-
95
--(void)resetRootViewControllerOnlyOnJSDevReload {
96
-	if(![UIApplication.sharedApplication.delegate.window.rootViewController isKindOfClass:[RNNSplashScreen class]]) {
97
-		UIApplication.sharedApplication.delegate.window.rootViewController = nil;
98
-	}
99
-}
100
-
101
-@end

+ 0
- 1
ios/RNNReactRootViewCreator.m Просмотреть файл

@@ -1,6 +1,5 @@
1 1
 
2 2
 #import "RNNReactRootViewCreator.h"
3
-#import "RNN.h"
4 3
 #import <React/RCTRootView.h>
5 4
 
6 5
 @implementation RNNReactRootViewCreator {

+ 0
- 2
ios/RNNRootViewController.m Просмотреть файл

@@ -1,7 +1,6 @@
1 1
 
2 2
 #import "RNNRootViewController.h"
3 3
 #import <React/RCTRootView.h>
4
-#import "RNN.h"
5 4
 
6 5
 @interface RNNRootViewController()
7 6
 @property NSString* containerId;
@@ -33,5 +32,4 @@
33 32
 	[self.eventEmitter sendContainerStop:self.containerId];
34 33
 }
35 34
 
36
-
37 35
 @end

+ 0
- 2
ios/ReactNativeNavigation.h Просмотреть файл

@@ -4,8 +4,6 @@
4 4
 
5 5
 @interface ReactNativeNavigation : NSObject
6 6
 
7
-+(void)bootstrap:(NSURL*)jsCodeLocation;
8
-
9 7
 +(void)bootstrap:(NSURL*)jsCodeLocation launchOptions:(NSDictionary *)launchOptions;
10 8
 
11 9
 @end

+ 101
- 5
ios/ReactNativeNavigation.m Просмотреть файл

@@ -1,15 +1,111 @@
1 1
 
2 2
 #import "ReactNativeNavigation.h"
3
-#import "RNN.h"
3
+ 
4
+#import <React/RCTBridge.h>
4 5
 
5
-@implementation ReactNativeNavigation
6
+#import "RNNEventEmitter.h"
7
+#import "RNNSplashScreen.h"
8
+#import "RNNBridgeModule.h"
9
+#import "RNNRootViewCreator.h"
10
+#import "RNNReactRootViewCreator.h"
6 11
 
7
-+(void)bootstrap:(NSURL *)jsCodeLocation {
8
-	[ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:nil];
12
+@interface ReactNativeNavigation() <RCTBridgeDelegate>
13
+
14
+@end
15
+
16
+@implementation ReactNativeNavigation {
17
+	NSURL* _jsCodeLocation;
18
+	NSDictionary* _launchOptions;
19
+	RNNStore* _store;
20
+	RCTBridge* _bridge;
9 21
 }
10 22
 
23
+# pragma mark - public API
24
+
11 25
 +(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions {
12
-	[[RNN sharedInstance] bootstrap:jsCodeLocation launchOptions:launchOptions];
26
+	[[ReactNativeNavigation sharedInstance] bootstrap:jsCodeLocation launchOptions:launchOptions];
27
+}
28
+
29
+# pragma mark - instance
30
+
31
++(instancetype) sharedInstance {
32
+	static ReactNativeNavigation *instance = nil;
33
+	static dispatch_once_t onceToken = 0;
34
+	dispatch_once(&onceToken,^{
35
+		if (instance == nil) {
36
+			instance = [[ReactNativeNavigation alloc] init];
37
+		}
38
+	});
39
+	
40
+	return instance;
41
+}
42
+
43
+-(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions {
44
+	_jsCodeLocation = jsCodeLocation;
45
+	_launchOptions = launchOptions;
46
+	_store = [RNNStore new];
47
+	
48
+	[RNNSplashScreen show];
49
+	
50
+	[self registerForJsEvents];
51
+	
52
+	[self createBridgeLoadJsAndThenInitDependencyGraph];
53
+}
54
+
55
+# pragma mark - RCTBridgeDelegate
56
+
57
+-(NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
58
+	return _jsCodeLocation;
59
+}
60
+
61
+/**
62
+ * here we initialize all of our dependency graph
63
+ */
64
+-(NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge {
65
+	RNNEventEmitter *eventEmitter = [[RNNEventEmitter alloc] init];
66
+	
67
+	id<RNNRootViewCreator> rootViewCreator = [[RNNReactRootViewCreator alloc] initWithBridge:bridge];
68
+	RNNControllerFactory *controllerFactory = [[RNNControllerFactory alloc] initWithRootViewCreator:rootViewCreator store:_store eventEmitter:eventEmitter];
69
+	RNNCommandsHandler *commandsHandler = [[RNNCommandsHandler alloc] initWithStore:_store controllerFactory:controllerFactory];
70
+	RNNBridgeModule *bridgeModule = [[RNNBridgeModule alloc] initWithCommandsHandler:commandsHandler];
71
+	
72
+	return @[bridgeModule,eventEmitter];
13 73
 }
14 74
 
75
+# pragma mark - js events
76
+
77
+-(void)onJavaScriptWillLoad {
78
+	[_store clean];
79
+	[self resetRootViewControllerOnlyOnJSDevReload];
80
+}
81
+
82
+-(void)onJavaScriptLoaded {
83
+	[_store setReadyToReceiveCommands:true];
84
+	[[_bridge moduleForClass:[RNNEventEmitter class]] sendOnAppLaunched];
85
+}
86
+
87
+# pragma mark - private
88
+
89
+-(void)createBridgeLoadJsAndThenInitDependencyGraph {
90
+	_bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:_launchOptions];
91
+}
92
+
93
+-(void)registerForJsEvents {
94
+	[[NSNotificationCenter defaultCenter] addObserver:self
95
+											 selector:@selector(onJavaScriptLoaded)
96
+												 name:RCTJavaScriptDidLoadNotification
97
+											   object:nil];
98
+	[[NSNotificationCenter defaultCenter] addObserver:self
99
+											 selector:@selector(onJavaScriptWillLoad)
100
+												 name:RCTJavaScriptWillStartLoadingNotification
101
+											   object:nil];
102
+}
103
+
104
+-(void)resetRootViewControllerOnlyOnJSDevReload {
105
+	if(![UIApplication.sharedApplication.delegate.window.rootViewController isKindOfClass:[RNNSplashScreen class]]) {
106
+		UIApplication.sharedApplication.delegate.window.rootViewController = nil;
107
+	}
108
+}
109
+
110
+
15 111
 @end

+ 0
- 8
ios/ReactNativeNavigation.xcodeproj/project.pbxproj Просмотреть файл

@@ -56,7 +56,6 @@
56 56
 		7B1126A01E2D263F00F9B03B /* RNNEventEmitter.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B11269F1E2D263F00F9B03B /* RNNEventEmitter.m */; };
57 57
 		7B1126A31E2D2B6C00F9B03B /* RNNSplashScreen.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BA500761E254908001B9E1B /* RNNSplashScreen.h */; };
58 58
 		7B1126A41E2D2B6C00F9B03B /* ReactNativeNavigation.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BA500731E2544B9001B9E1B /* ReactNativeNavigation.h */; settings = {ATTRIBUTES = (Public, ); }; };
59
-		7B1126A51E2D2B6C00F9B03B /* RNN.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BBFE55F1E253F97002A6182 /* RNN.h */; };
60 59
 		7B1126A61E2D2B6C00F9B03B /* RNNBridgeModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BBFE5421E25330E002A6182 /* RNNBridgeModule.h */; };
61 60
 		7B1126A71E2D2B6C00F9B03B /* RNNEventEmitter.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B11269E1E2D263F00F9B03B /* RNNEventEmitter.h */; };
62 61
 		7B1126A91E2D2B6C00F9B03B /* RNNControllerFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC9346C1E26886E00EFA125 /* RNNControllerFactory.h */; };
@@ -65,7 +64,6 @@
65 64
 		7BA500751E2544B9001B9E1B /* ReactNativeNavigation.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BA500741E2544B9001B9E1B /* ReactNativeNavigation.m */; };
66 65
 		7BA500781E254908001B9E1B /* RNNSplashScreen.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BA500771E254908001B9E1B /* RNNSplashScreen.m */; };
67 66
 		7BBFE5441E25330E002A6182 /* RNNBridgeModule.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BBFE5431E25330E002A6182 /* RNNBridgeModule.m */; };
68
-		7BBFE5611E253F97002A6182 /* RNN.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BBFE5601E253F97002A6182 /* RNN.m */; };
69 67
 		7BC9346E1E26886E00EFA125 /* RNNControllerFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC9346D1E26886E00EFA125 /* RNNControllerFactory.m */; };
70 68
 		7BEF0D181E437684003E96B0 /* RNNRootViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BEF0D161E437684003E96B0 /* RNNRootViewController.h */; };
71 69
 		7BEF0D191E437684003E96B0 /* RNNRootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BEF0D171E437684003E96B0 /* RNNRootViewController.m */; };
@@ -143,8 +141,6 @@
143 141
 		7BA500771E254908001B9E1B /* RNNSplashScreen.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNSplashScreen.m; sourceTree = "<group>"; };
144 142
 		7BBFE5421E25330E002A6182 /* RNNBridgeModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNBridgeModule.h; sourceTree = "<group>"; };
145 143
 		7BBFE5431E25330E002A6182 /* RNNBridgeModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNBridgeModule.m; sourceTree = "<group>"; };
146
-		7BBFE55F1E253F97002A6182 /* RNN.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNN.h; sourceTree = "<group>"; };
147
-		7BBFE5601E253F97002A6182 /* RNN.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNN.m; sourceTree = "<group>"; };
148 144
 		7BC9346C1E26886E00EFA125 /* RNNControllerFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNControllerFactory.h; sourceTree = "<group>"; };
149 145
 		7BC9346D1E26886E00EFA125 /* RNNControllerFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNControllerFactory.m; sourceTree = "<group>"; };
150 146
 		7BEF0D161E437684003E96B0 /* RNNRootViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNRootViewController.h; sourceTree = "<group>"; };
@@ -272,8 +268,6 @@
272 268
 			children = (
273 269
 				7BA500731E2544B9001B9E1B /* ReactNativeNavigation.h */,
274 270
 				7BA500741E2544B9001B9E1B /* ReactNativeNavigation.m */,
275
-				7BBFE55F1E253F97002A6182 /* RNN.h */,
276
-				7BBFE5601E253F97002A6182 /* RNN.m */,
277 271
 				268692801E5054F800E2C612 /* RNNStore.h */,
278 272
 				268692811E5054F800E2C612 /* RNNStore.m */,
279 273
 				7B4928061E70415400555040 /* RNNCommandsHandler.h */,
@@ -318,7 +312,6 @@
318 312
 				263905C61E4C6F440023D7D3 /* SidebarFeedlyAnimation.h in Headers */,
319 313
 				7B1126A31E2D2B6C00F9B03B /* RNNSplashScreen.h in Headers */,
320 314
 				261F0E641E6EC94900989DE2 /* RNNModalManager.h in Headers */,
321
-				7B1126A51E2D2B6C00F9B03B /* RNN.h in Headers */,
322 315
 				263905C01E4C6F440023D7D3 /* SidebarAirbnbAnimation.h in Headers */,
323 316
 				263905E61E4CAC950023D7D3 /* RNNSideMenuChildVC.h in Headers */,
324 317
 				263905C41E4C6F440023D7D3 /* SidebarFacebookAnimation.h in Headers */,
@@ -422,7 +415,6 @@
422 415
 				263905CF1E4C6F440023D7D3 /* TheSidebarController.m in Sources */,
423 416
 				263905AF1E4C6F440023D7D3 /* MMDrawerBarButtonItem.m in Sources */,
424 417
 				7B4928091E70415400555040 /* RNNCommandsHandler.m in Sources */,
425
-				7BBFE5611E253F97002A6182 /* RNN.m in Sources */,
426 418
 				268692831E5054F800E2C612 /* RNNStore.m in Sources */,
427 419
 				7BC9346E1E26886E00EFA125 /* RNNControllerFactory.m in Sources */,
428 420
 				263905B61E4C6F440023D7D3 /* MMExampleDrawerVisualStateManager.m in Sources */,

+ 0
- 1
playground/ios/playgroundTests/RNNModalManagerTest.m Просмотреть файл

@@ -17,7 +17,6 @@
17 17
 	[modalManager dismissAllModals];
18 18
 	
19 19
 	XCTAssertTrue([[store pendingModalIdsToDismiss] count] == 0);
20
-	
21 20
 }
22 21
 
23 22
 @end