|
@@ -6,18 +6,34 @@
|
6
|
6
|
#import "RNNRootViewController.h"
|
7
|
7
|
#import "React/RCTUIManager.h"
|
8
|
8
|
|
|
9
|
+static NSString* const setRoot = @"setRoot";
|
|
10
|
+static NSString* const setStackRoot = @"setStackRoot";
|
|
11
|
+static NSString* const push = @"push";
|
|
12
|
+static NSString* const pop = @"pop";
|
|
13
|
+static NSString* const popTo = @"popTo";
|
|
14
|
+static NSString* const popToRoot = @"popToRoot";
|
|
15
|
+static NSString* const showModal = @"showModal";
|
|
16
|
+static NSString* const dismissModal = @"dismissModal";
|
|
17
|
+static NSString* const dismissAllModals = @"dismissAllModals";
|
|
18
|
+static NSString* const showOverlay = @"showOverlay";
|
|
19
|
+static NSString* const dismissOverlay = @"dismissOverlay";
|
|
20
|
+static NSString* const mergeOptions = @"mergeOptions";
|
|
21
|
+static NSString* const setDefaultOptions = @"setDefaultOptions";
|
|
22
|
+
|
9
|
23
|
@implementation RNNCommandsHandler {
|
10
|
24
|
RNNControllerFactory *_controllerFactory;
|
11
|
25
|
RNNStore *_store;
|
12
|
26
|
RNNNavigationStackManager* _navigationStackManager;
|
13
|
27
|
RNNModalManager* _modalManager;
|
14
|
28
|
RNNOverlayManager* _overlayManager;
|
|
29
|
+ RNNEventEmitter* _eventEmitter;
|
15
|
30
|
}
|
16
|
31
|
|
17
|
|
--(instancetype) initWithStore:(RNNStore*)store controllerFactory:(RNNControllerFactory*)controllerFactory {
|
|
32
|
+-(instancetype) initWithStore:(RNNStore*)store controllerFactory:(RNNControllerFactory*)controllerFactory eventEmitter:(RNNEventEmitter *)eventEmitter {
|
18
|
33
|
self = [super init];
|
19
|
34
|
_store = store;
|
20
|
35
|
_controllerFactory = controllerFactory;
|
|
36
|
+ _eventEmitter = eventEmitter;
|
21
|
37
|
_navigationStackManager = [[RNNNavigationStackManager alloc] initWithStore:_store];
|
22
|
38
|
_modalManager = [[RNNModalManager alloc] initWithStore:_store];
|
23
|
39
|
_overlayManager = [[RNNOverlayManager alloc] initWithStore:_store];
|
|
@@ -30,7 +46,8 @@
|
30
|
46
|
[self assertReady];
|
31
|
47
|
|
32
|
48
|
[_modalManager dismissAllModals];
|
33
|
|
-
|
|
49
|
+ [_eventEmitter sendOnNavigationComment:setRoot params:@{@"layout": layout}];
|
|
50
|
+
|
34
|
51
|
UIViewController *vc = [_controllerFactory createLayoutAndSaveToStore:layout];
|
35
|
52
|
|
36
|
53
|
UIApplication.sharedApplication.delegate.window.rootViewController = vc;
|
|
@@ -40,7 +57,8 @@
|
40
|
57
|
|
41
|
58
|
-(void) mergeOptions:(NSString*)componentId options:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion {
|
42
|
59
|
[self assertReady];
|
43
|
|
-
|
|
60
|
+ [_eventEmitter sendOnNavigationComment:mergeOptions params:@{@"componentId": componentId, @"options": options}];
|
|
61
|
+
|
44
|
62
|
UIViewController* vc = [_store findComponentForId:componentId];
|
45
|
63
|
if([vc isKindOfClass:[RNNRootViewController class]]) {
|
46
|
64
|
RNNRootViewController* rootVc = (RNNRootViewController*)vc;
|
|
@@ -56,12 +74,13 @@
|
56
|
74
|
|
57
|
75
|
-(void) setDefaultOptions:(NSDictionary*)optionsDict completion:(RNNTransitionCompletionBlock)completion {
|
58
|
76
|
[self assertReady];
|
|
77
|
+ [_eventEmitter sendOnNavigationComment:setDefaultOptions params:@{@"options": optionsDict}];
|
59
|
78
|
[_controllerFactory setDefaultOptionsDict:optionsDict];
|
60
|
79
|
}
|
61
|
80
|
|
62
|
81
|
-(void)push:(NSString*)componentId layout:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion {
|
63
|
82
|
[self assertReady];
|
64
|
|
-
|
|
83
|
+ [_eventEmitter sendOnNavigationComment:push params:@{@"componentId": componentId}];
|
65
|
84
|
UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
|
66
|
85
|
[_navigationStackManager push:newVc onTop:componentId completion:^{
|
67
|
86
|
completion();
|
|
@@ -70,7 +89,8 @@
|
70
|
89
|
|
71
|
90
|
-(void)setStackRoot:(NSString*)componentId layout:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion {
|
72
|
91
|
[self assertReady];
|
73
|
|
-
|
|
92
|
+ [_eventEmitter sendOnNavigationComment:setStackRoot params:@{@"componentId": componentId}];
|
|
93
|
+
|
74
|
94
|
UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
|
75
|
95
|
[_navigationStackManager setRoot:newVc fromComponent:componentId completion:^{
|
76
|
96
|
completion();
|
|
@@ -79,6 +99,7 @@
|
79
|
99
|
|
80
|
100
|
-(void)pop:(NSString*)componentId options:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion {
|
81
|
101
|
[self assertReady];
|
|
102
|
+ [_eventEmitter sendOnNavigationComment:pop params:@{@"componentId": componentId}];
|
82
|
103
|
[CATransaction begin];
|
83
|
104
|
[CATransaction setCompletionBlock:^{
|
84
|
105
|
completion();
|
|
@@ -97,6 +118,7 @@
|
97
|
118
|
|
98
|
119
|
-(void) popTo:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion {
|
99
|
120
|
[self assertReady];
|
|
121
|
+ [_eventEmitter sendOnNavigationComment:popTo params:@{@"componentId": componentId}];
|
100
|
122
|
[CATransaction begin];
|
101
|
123
|
[CATransaction setCompletionBlock:^{
|
102
|
124
|
completion();
|
|
@@ -109,6 +131,7 @@
|
109
|
131
|
|
110
|
132
|
-(void) popToRoot:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion {
|
111
|
133
|
[self assertReady];
|
|
134
|
+ [_eventEmitter sendOnNavigationComment:popToRoot params:@{@"componentId": componentId}];
|
112
|
135
|
[CATransaction begin];
|
113
|
136
|
[CATransaction setCompletionBlock:^{
|
114
|
137
|
completion();
|
|
@@ -121,7 +144,7 @@
|
121
|
144
|
|
122
|
145
|
-(void) showModal:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion {
|
123
|
146
|
[self assertReady];
|
124
|
|
-
|
|
147
|
+ [_eventEmitter sendOnNavigationComment:showModal params:@{@"layout": layout}];
|
125
|
148
|
UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
|
126
|
149
|
[_modalManager showModal:newVc completion:^{
|
127
|
150
|
completion();
|
|
@@ -130,6 +153,7 @@
|
130
|
153
|
|
131
|
154
|
-(void) dismissModal:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion {
|
132
|
155
|
[self assertReady];
|
|
156
|
+ [_eventEmitter sendOnNavigationComment:dismissModal params:@{@"componentId": componentId}];
|
133
|
157
|
[CATransaction begin];
|
134
|
158
|
[CATransaction setCompletionBlock:^{
|
135
|
159
|
completion();
|
|
@@ -142,6 +166,7 @@
|
142
|
166
|
|
143
|
167
|
-(void) dismissAllModalsWithCompletion:(RNNTransitionCompletionBlock)completion {
|
144
|
168
|
[self assertReady];
|
|
169
|
+ [_eventEmitter sendOnNavigationComment:dismissAllModals params:nil];
|
145
|
170
|
[CATransaction begin];
|
146
|
171
|
[CATransaction setCompletionBlock:^{
|
147
|
172
|
completion();
|
|
@@ -154,6 +179,7 @@
|
154
|
179
|
|
155
|
180
|
-(void)showOverlay:(NSDictionary *)layout completion:(RNNTransitionCompletionBlock)completion {
|
156
|
181
|
[self assertReady];
|
|
182
|
+ [_eventEmitter sendOnNavigationComment:showOverlay params:@{@"layout": layout}];
|
157
|
183
|
UIViewController<RNNRootViewProtocol>* overlayVC = [_controllerFactory createOverlay:layout];
|
158
|
184
|
[_overlayManager showOverlay:overlayVC completion:^{
|
159
|
185
|
completion();
|
|
@@ -162,6 +188,7 @@
|
162
|
188
|
|
163
|
189
|
- (void)dismissOverlay:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion {
|
164
|
190
|
[self assertReady];
|
|
191
|
+ [_eventEmitter sendOnNavigationComment:dismissModal params:@{@"componentId": componentId}];
|
165
|
192
|
[_overlayManager dismissOverlay:componentId completion:^{
|
166
|
193
|
completion();
|
167
|
194
|
}];
|