|
@@ -5,6 +5,7 @@
|
5
|
5
|
#import "RNNEventEmitter.h"
|
6
|
6
|
#import "RNNSplashScreen.h"
|
7
|
7
|
#import "RNNBridgeModule.h"
|
|
8
|
+#import "RNNRootViewCreator.h"
|
8
|
9
|
#import "RNNReactRootViewCreator.h"
|
9
|
10
|
|
10
|
11
|
@interface RNN() <RCTBridgeDelegate>
|
|
@@ -12,9 +13,10 @@
|
12
|
13
|
@end
|
13
|
14
|
|
14
|
15
|
@implementation RNN {
|
15
|
|
- NSURL *_jsCodeLocation;
|
16
|
|
- RCTBridge *_bridge;
|
17
|
|
- RNNStore *_store;
|
|
16
|
+ NSURL* _jsCodeLocation;
|
|
17
|
+ NSDictionary* _launchOptions;
|
|
18
|
+ RNNStore* _store;
|
|
19
|
+ RCTBridge* _bridge;
|
18
|
20
|
}
|
19
|
21
|
|
20
|
22
|
+(instancetype) sharedInstance {
|
|
@@ -34,16 +36,14 @@
|
34
|
36
|
|
35
|
37
|
-(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions {
|
36
|
38
|
_jsCodeLocation = jsCodeLocation;
|
37
|
|
-
|
38
|
|
- UIApplication.sharedApplication.delegate.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
39
|
|
- UIApplication.sharedApplication.delegate.window.backgroundColor = [UIColor whiteColor];
|
40
|
|
-
|
|
39
|
+ _launchOptions = launchOptions;
|
|
40
|
+ _store = [RNNStore new];
|
|
41
|
+
|
41
|
42
|
[RNNSplashScreen show];
|
42
|
43
|
|
43
|
44
|
[self registerForJsEvents];
|
44
|
45
|
|
45
|
|
- // this will load the JS bundle
|
46
|
|
- _bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
|
|
46
|
+ [self createBridgeLoadJsThenInitDependencyGraph];
|
47
|
47
|
}
|
48
|
48
|
|
49
|
49
|
# pragma mark - RCTBridgeDelegate
|
|
@@ -52,29 +52,35 @@
|
52
|
52
|
return _jsCodeLocation;
|
53
|
53
|
}
|
54
|
54
|
|
55
|
|
--(void)onJavaScriptWillLoad {
|
56
|
|
- _store = [RNNStore new];
|
57
|
|
- [self resetRootViewControllerOnlyOnJSDevReload];
|
58
|
|
-}
|
59
|
|
-
|
60
|
55
|
-(NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge {
|
61
|
56
|
RNNEventEmitter *eventEmitter = [[RNNEventEmitter alloc] init];
|
62
|
57
|
|
63
|
|
- RNNControllerFactory *controllerFactory = [[RNNControllerFactory alloc] initWithRootViewCreator:[[RNNReactRootViewCreator alloc]initWithBridge:bridge] store:_store eventEmitter:eventEmitter];
|
64
|
|
- RNNCommandsHandler *commandsHandler = [[RNNCommandsHandler alloc]initWithStore:_store controllerFactory:controllerFactory];
|
65
|
|
-
|
|
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];
|
66
|
61
|
RNNBridgeModule *bridgeModule = [[RNNBridgeModule alloc] initWithCommandsHandler:commandsHandler];
|
67
|
62
|
|
68
|
63
|
return @[bridgeModule,eventEmitter];
|
69
|
64
|
}
|
70
|
65
|
|
|
66
|
+# pragma mark - js events
|
|
67
|
+
|
|
68
|
+-(void)onJavaScriptWillLoad {
|
|
69
|
+ [_store clean];
|
|
70
|
+ [self resetRootViewControllerOnlyOnJSDevReload];
|
|
71
|
+}
|
|
72
|
+
|
71
|
73
|
-(void)onJavaScriptLoaded {
|
72
|
|
- _store.isReadyToReceiveCommands = YES;
|
|
74
|
+ [_store setReadyToReceiveCommands:true];
|
73
|
75
|
[[_bridge moduleForClass:[RNNEventEmitter class]] sendOnAppLaunched];
|
74
|
76
|
}
|
75
|
77
|
|
76
|
78
|
# pragma mark - private
|
77
|
79
|
|
|
80
|
+-(void)createBridgeLoadJsThenInitDependencyGraph {
|
|
81
|
+ _bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:_launchOptions];
|
|
82
|
+}
|
|
83
|
+
|
78
|
84
|
-(void)registerForJsEvents {
|
79
|
85
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
80
|
86
|
selector:@selector(onJavaScriptLoaded)
|
|
@@ -92,5 +98,4 @@
|
92
|
98
|
}
|
93
|
99
|
}
|
94
|
100
|
|
95
|
|
-
|
96
|
101
|
@end
|