Browse Source

Adresses #1078 - static events

yogevbd 6 years ago
parent
commit
8f4838e1ec

+ 12
- 0
lib/ios/RNNCommandsHandler.m View File

56
 	
56
 	
57
 	UIApplication.sharedApplication.delegate.window.rootViewController = vc;
57
 	UIApplication.sharedApplication.delegate.window.rootViewController = vc;
58
 	[UIApplication.sharedApplication.delegate.window makeKeyAndVisible];
58
 	[UIApplication.sharedApplication.delegate.window makeKeyAndVisible];
59
+	[_eventEmitter sendOnNavigationCommandCompletion:setRoot params:@{@"layout": layout}];
59
 	completion();
60
 	completion();
60
 }
61
 }
61
 
62
 
128
 	} else {
129
 	} else {
129
 		[_eventEmitter sendOnNavigationCommand:push params:@{@"componentId": componentId}];
130
 		[_eventEmitter sendOnNavigationCommand:push params:@{@"componentId": componentId}];
130
 		[_navigationStackManager push:newVc onTop:componentId completion:^{
131
 		[_navigationStackManager push:newVc onTop:componentId completion:^{
132
+			[_eventEmitter sendOnNavigationCommandCompletion:push params:@{@"componentId": componentId}];
131
 			completion();
133
 			completion();
132
 		} rejection:rejection];
134
 		} rejection:rejection];
133
 	}
135
 	}
138
 	[_eventEmitter sendOnNavigationCommand:setStackRoot params:@{@"componentId": componentId}];
140
 	[_eventEmitter sendOnNavigationCommand:setStackRoot params:@{@"componentId": componentId}];
139
 	
141
 	
140
 	UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
142
 	UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
143
+	__weak typeof(RNNEventEmitter*) weakEventEmitter = _eventEmitter;
141
 	[_navigationStackManager setStackRoot:newVc fromComponent:componentId completion:^{
144
 	[_navigationStackManager setStackRoot:newVc fromComponent:componentId completion:^{
145
+		[weakEventEmitter sendOnNavigationCommandCompletion:setStackRoot params:@{@"componentId": componentId}];
142
 		completion();
146
 		completion();
143
 	} rejection:rejection];
147
 	} rejection:rejection];
144
 }
148
 }
148
 	[_eventEmitter sendOnNavigationCommand:pop params:@{@"componentId": componentId}];
152
 	[_eventEmitter sendOnNavigationCommand:pop params:@{@"componentId": componentId}];
149
 	[CATransaction begin];
153
 	[CATransaction begin];
150
 	[CATransaction setCompletionBlock:^{
154
 	[CATransaction setCompletionBlock:^{
155
+		[_eventEmitter sendOnNavigationCommandCompletion:pop params:@{@"componentId": componentId}];
151
 		completion();
156
 		completion();
152
 	}];
157
 	}];
153
 	
158
 	
167
 	[_eventEmitter sendOnNavigationCommand:popTo params:@{@"componentId": componentId}];
172
 	[_eventEmitter sendOnNavigationCommand:popTo params:@{@"componentId": componentId}];
168
 	[CATransaction begin];
173
 	[CATransaction begin];
169
 	[CATransaction setCompletionBlock:^{
174
 	[CATransaction setCompletionBlock:^{
175
+		[_eventEmitter sendOnNavigationCommandCompletion:popTo params:@{@"componentId": componentId}];
170
 		completion();
176
 		completion();
171
 	}];
177
 	}];
172
 	
178
 	
180
 	[_eventEmitter sendOnNavigationCommand:popToRoot params:@{@"componentId": componentId}];
186
 	[_eventEmitter sendOnNavigationCommand:popToRoot params:@{@"componentId": componentId}];
181
 	[CATransaction begin];
187
 	[CATransaction begin];
182
 	[CATransaction setCompletionBlock:^{
188
 	[CATransaction setCompletionBlock:^{
189
+		[_eventEmitter sendOnNavigationCommandCompletion:popToRoot params:@{@"componentId": componentId}];
183
 		completion();
190
 		completion();
184
 	}];
191
 	}];
185
 	
192
 	
193
 	[_eventEmitter sendOnNavigationCommand:showModal params:@{@"layout": layout}];
200
 	[_eventEmitter sendOnNavigationCommand:showModal params:@{@"layout": layout}];
194
 	UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
201
 	UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
195
 	[_modalManager showModal:newVc completion:^{
202
 	[_modalManager showModal:newVc completion:^{
203
+		[_eventEmitter sendOnNavigationCommandCompletion:showModal params:@{@"layout": layout}];
196
 		completion();
204
 		completion();
197
 	}];
205
 	}];
198
 }
206
 }
202
 	[_eventEmitter sendOnNavigationCommand:dismissModal params:@{@"componentId": componentId}];
210
 	[_eventEmitter sendOnNavigationCommand:dismissModal params:@{@"componentId": componentId}];
203
 	[CATransaction begin];
211
 	[CATransaction begin];
204
 	[CATransaction setCompletionBlock:^{
212
 	[CATransaction setCompletionBlock:^{
213
+		[_eventEmitter sendOnNavigationCommandCompletion:dismissModal params:@{@"componentId": componentId}];
205
 		completion();
214
 		completion();
206
 	}];
215
 	}];
207
 	
216
 	
215
 	[_eventEmitter sendOnNavigationCommand:dismissAllModals params:@{}];
224
 	[_eventEmitter sendOnNavigationCommand:dismissAllModals params:@{}];
216
 	[CATransaction begin];
225
 	[CATransaction begin];
217
 	[CATransaction setCompletionBlock:^{
226
 	[CATransaction setCompletionBlock:^{
227
+		[_eventEmitter sendOnNavigationCommandCompletion:dismissAllModals params:@{}];
218
 		completion();
228
 		completion();
219
 	}];
229
 	}];
220
 	
230
 	
228
 	[_eventEmitter sendOnNavigationCommand:showOverlay params:@{@"layout": layout}];
238
 	[_eventEmitter sendOnNavigationCommand:showOverlay params:@{@"layout": layout}];
229
 	UIViewController<RNNRootViewProtocol>* overlayVC = [_controllerFactory createOverlay:layout];
239
 	UIViewController<RNNRootViewProtocol>* overlayVC = [_controllerFactory createOverlay:layout];
230
 	[_overlayManager showOverlay:overlayVC completion:^{
240
 	[_overlayManager showOverlay:overlayVC completion:^{
241
+		[_eventEmitter sendOnNavigationCommandCompletion:showOverlay params:@{@"layout": layout}];
231
 		completion();
242
 		completion();
232
 	}];
243
 	}];
233
 }
244
 }
236
 	[self assertReady];
247
 	[self assertReady];
237
 	[_eventEmitter sendOnNavigationCommand:dismissModal params:@{@"componentId": componentId}];
248
 	[_eventEmitter sendOnNavigationCommand:dismissModal params:@{@"componentId": componentId}];
238
 	[_overlayManager dismissOverlay:componentId completion:^{
249
 	[_overlayManager dismissOverlay:componentId completion:^{
250
+		[_eventEmitter sendOnNavigationCommandCompletion:dismissModal params:@{@"componentId": componentId}];
239
 		completion();
251
 		completion();
240
 	}];
252
 	}];
241
 }
253
 }

+ 2
- 0
lib/ios/RNNEventEmitter.h View File

18
 
18
 
19
 -(void)sendOnNavigationCommand:(NSString *)commandName params:(NSDictionary*)params;
19
 -(void)sendOnNavigationCommand:(NSString *)commandName params:(NSDictionary*)params;
20
 
20
 
21
+-(void)sendOnNavigationCommandCompletion:(NSString *)commandName params:(NSDictionary*)params;
22
+
21
 -(void)sendOnSearchBarUpdated:(NSString *)componentId text:(NSString*)text isFocused:(BOOL)isFocused;
23
 -(void)sendOnSearchBarUpdated:(NSString *)componentId text:(NSString*)text isFocused:(BOOL)isFocused;
22
 
24
 
23
 @end
25
 @end

+ 7
- 0
lib/ios/RNNEventEmitter.m View File

1
 #import "RNNEventEmitter.h"
1
 #import "RNNEventEmitter.h"
2
+#import "RNNUtils.h"
2
 
3
 
3
 @implementation RNNEventEmitter {
4
 @implementation RNNEventEmitter {
4
   NSInteger _appLaunchedListenerCount;
5
   NSInteger _appLaunchedListenerCount;
43
 	[self send:navigationEvent body:@{@"name":commandName , @"params": params}];
44
 	[self send:navigationEvent body:@{@"name":commandName , @"params": params}];
44
 }
45
 }
45
 
46
 
47
+-(void)sendOnNavigationCommandCompletion:(NSString *)commandName params:(NSDictionary*)params {
48
+	NSMutableDictionary* mutableParams = [NSMutableDictionary dictionaryWithDictionary:params];
49
+	[mutableParams setObject:[RNNUtils getCurrentTimestamp] forKey:@"timestamp"];
50
+	[self send:commandComplete body:@{@"name":commandName , @"params": mutableParams}];
51
+}
52
+
46
 -(void)sendOnNavigationEvent:(NSString *)commandName params:(NSDictionary*)params {
53
 -(void)sendOnNavigationEvent:(NSString *)commandName params:(NSDictionary*)params {
47
 	[self send:navigationEvent body:@{@"name":commandName , @"params": params}];
54
 	[self send:navigationEvent body:@{@"name":commandName , @"params": params}];
48
 }
55
 }

+ 1
- 5
lib/ios/RNNTabBarController.m View File

64
 #pragma mark UITabBarControllerDelegate
64
 #pragma mark UITabBarControllerDelegate
65
 
65
 
66
 - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
66
 - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
67
-	if (tabBarController.selectedIndex == _currentTabIndex) {
68
-		[_eventEmitter sendOnNavigationEvent:@"bottomTabReselected" params:@{@"index": @(tabBarController.selectedIndex)}];
69
-	} else {
70
-		[_eventEmitter sendOnNavigationEvent:@"bottomTabSelected" params:@{@"index": @(tabBarController.selectedIndex)}];
71
-	}
67
+	[_eventEmitter sendOnNavigationEvent:@"bottomTabSelected" params:@{@"selectedTabIndex": @(tabBarController.selectedIndex), @"unselectedTabIndex": @(_currentTabIndex)}];
72
 	
68
 	
73
 	_currentTabIndex = tabBarController.selectedIndex;
69
 	_currentTabIndex = tabBarController.selectedIndex;
74
 }
70
 }

+ 2
- 0
lib/ios/RNNUtils.h View File

5
 +(double)getDoubleOrKey:(NSDictionary*)dict withKey:(NSString*)key withDefault:(double)defaultResult;
5
 +(double)getDoubleOrKey:(NSDictionary*)dict withKey:(NSString*)key withDefault:(double)defaultResult;
6
 +(BOOL)getBoolOrKey:(NSDictionary*)dict withKey:(NSString*)key withDefault:(BOOL)defaultResult;
6
 +(BOOL)getBoolOrKey:(NSDictionary*)dict withKey:(NSString*)key withDefault:(BOOL)defaultResult;
7
 +(id)getObjectOrKey:(NSDictionary*)dict withKey:(NSString*)key withDefault:(id)defaultResult;
7
 +(id)getObjectOrKey:(NSDictionary*)dict withKey:(NSString*)key withDefault:(id)defaultResult;
8
++(NSNumber*)getCurrentTimestamp;
9
+
8
 @end
10
 @end

+ 4
- 0
lib/ios/RNNUtils.m View File

25
 	}
25
 	}
26
 }
26
 }
27
 
27
 
28
++ (NSNumber *)getCurrentTimestamp {
29
+	return [NSNumber numberWithLong:[[NSDate date] timeIntervalSince1970] * 1000];
30
+}
31
+
28
 @end
32
 @end