|
@@ -9,14 +9,16 @@
|
9
|
9
|
|
10
|
10
|
@interface RNN() <RCTBridgeDelegate>
|
11
|
11
|
|
12
|
|
-@property NSURL* jsCodeLocation;
|
13
|
|
-@property RCTBridge* bridge;
|
14
|
|
-@property RNNEventEmitter* eventEmitter;
|
15
|
|
-@property RNNStore *store;
|
|
12
|
+
|
16
|
13
|
|
17
|
14
|
@end
|
18
|
15
|
|
19
|
|
-@implementation RNN
|
|
16
|
+@implementation RNN {
|
|
17
|
+ NSURL *_jsCodeLocation;
|
|
18
|
+ RCTBridge *_bridge;
|
|
19
|
+ RNNEventEmitter *_eventEmitter;
|
|
20
|
+ RNNStore *_store;
|
|
21
|
+}
|
20
|
22
|
|
21
|
23
|
+(instancetype) sharedInstance {
|
22
|
24
|
static RNN *instance = nil;
|
|
@@ -34,8 +36,8 @@
|
34
|
36
|
# pragma mark public
|
35
|
37
|
|
36
|
38
|
-(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions {
|
37
|
|
- self.jsCodeLocation = jsCodeLocation;
|
38
|
|
- self.eventEmitter = [RNNEventEmitter new];
|
|
39
|
+ _jsCodeLocation = jsCodeLocation;
|
|
40
|
+ _eventEmitter = [RNNEventEmitter new];
|
39
|
41
|
|
40
|
42
|
UIApplication.sharedApplication.delegate.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
41
|
43
|
UIApplication.sharedApplication.delegate.window.backgroundColor = [UIColor whiteColor];
|
|
@@ -45,40 +47,42 @@
|
45
|
47
|
[self registerForJsEvents];
|
46
|
48
|
|
47
|
49
|
// this will load the JS bundle
|
48
|
|
- self.bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
|
|
50
|
+ _bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
|
49
|
51
|
}
|
50
|
52
|
|
51
|
53
|
# pragma mark - RCTBridgeDelegate
|
52
|
54
|
|
53
|
55
|
-(NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
|
54
|
|
- return self.jsCodeLocation;
|
|
56
|
+ return _jsCodeLocation;
|
55
|
57
|
}
|
56
|
58
|
|
57
|
59
|
-(NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge {
|
58
|
60
|
|
59
|
|
- RNNControllerFactory *controllerFactory = [[RNNControllerFactory alloc] initWithRootViewCreator:[RNNReactRootViewCreator new] store:self.store];
|
60
|
|
- RNNCommandsHandler* commandsHandler = [[RNNCommandsHandler alloc]initWithStore:self.store controllerFactory:controllerFactory];
|
|
61
|
+ RNNControllerFactory *controllerFactory = [[RNNControllerFactory alloc] initWithRootViewCreator:[RNNReactRootViewCreator new] store:_store];
|
|
62
|
+ RNNCommandsHandler *commandsHandler = [[RNNCommandsHandler alloc]initWithStore:_store controllerFactory:controllerFactory];
|
|
63
|
+
|
|
64
|
+ RNNBridgeModule *bridgeModule = [[RNNBridgeModule alloc] initWithCommandsHandler:commandsHandler];
|
|
65
|
+ RNNEventEmitter *eventEmitter = [[RNNEventEmitter alloc] initWithBridge:bridge];
|
61
|
66
|
|
62
|
|
- RNNBridgeModule* bridgeModule = [[RNNBridgeModule alloc] initWithCommandsHandler:commandsHandler];
|
63
|
|
- return @[bridgeModule];
|
|
67
|
+ return @[bridgeModule,eventEmitter];
|
64
|
68
|
}
|
65
|
69
|
|
66
|
70
|
# pragma mark - private
|
67
|
71
|
|
68
|
72
|
-(void)registerForJsEvents {
|
69
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onJavaScriptLoaded) name:RCTJavaScriptDidLoadNotification object:self.bridge];
|
70
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onJavaScriptWillLoad) name:RCTJavaScriptWillStartLoadingNotification object:self.bridge];
|
|
73
|
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onJavaScriptLoaded) name:RCTJavaScriptDidLoadNotification object:_bridge];
|
|
74
|
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onJavaScriptWillLoad) name:RCTJavaScriptWillStartLoadingNotification object:_bridge];
|
71
|
75
|
}
|
72
|
76
|
|
73
|
77
|
|
74
|
78
|
-(void)onJavaScriptWillLoad {
|
75
|
|
- self.store = [RNNStore new];
|
|
79
|
+ _store = [RNNStore new];
|
76
|
80
|
[self resetRootViewControllerOnlyOnJSDevReload];
|
77
|
81
|
}
|
78
|
82
|
|
79
|
83
|
-(void)onJavaScriptLoaded {
|
80
|
|
- self.store.isReadyToReceiveCommands = true;
|
81
|
|
- [self.eventEmitter sendOnAppLaunched];
|
|
84
|
+ _store.isReadyToReceiveCommands = true;
|
|
85
|
+ [_eventEmitter sendOnAppLaunched];
|
82
|
86
|
}
|
83
|
87
|
|
84
|
88
|
-(void)resetRootViewControllerOnlyOnJSDevReload {
|