Ver código fonte

Adresses #1078 - static events

yogevbd 6 anos atrás
pai
commit
8f4838e1ec

+ 12
- 0
lib/ios/RNNCommandsHandler.m Ver arquivo

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

+ 2
- 0
lib/ios/RNNEventEmitter.h Ver arquivo

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

+ 7
- 0
lib/ios/RNNEventEmitter.m Ver arquivo

@@ -1,4 +1,5 @@
1 1
 #import "RNNEventEmitter.h"
2
+#import "RNNUtils.h"
2 3
 
3 4
 @implementation RNNEventEmitter {
4 5
   NSInteger _appLaunchedListenerCount;
@@ -43,6 +44,12 @@ static NSString* const navigationEvent	= @"RNN.nativeEvent";
43 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 53
 -(void)sendOnNavigationEvent:(NSString *)commandName params:(NSDictionary*)params {
47 54
 	[self send:navigationEvent body:@{@"name":commandName , @"params": params}];
48 55
 }

+ 1
- 5
lib/ios/RNNTabBarController.m Ver arquivo

@@ -64,11 +64,7 @@
64 64
 #pragma mark UITabBarControllerDelegate
65 65
 
66 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 69
 	_currentTabIndex = tabBarController.selectedIndex;
74 70
 }

+ 2
- 0
lib/ios/RNNUtils.h Ver arquivo

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

+ 4
- 0
lib/ios/RNNUtils.m Ver arquivo

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