Browse Source

Added static events e2e

yogevbd 6 years ago
parent
commit
92cbc08e25

+ 20
- 0
e2e/StaticLifecycleEvents.test.js View File

@@ -16,6 +16,26 @@ describe('static lifecycle events', () => {
16 16
     await expect(elementByLabel('componentDidDisappear | navigation.playground.WelcomeScreen')).toBeVisible();
17 17
   });
18 18
 
19
+  it('pushing and poping screen dispatch static event', async () => {
20
+    await elementById(testIDs.PUSH_STATIC_LIFECYCLE_BUTTON).tap();
21
+    await expect(elementByLabel('Static Lifecycle Events Overlay')).toBeVisible();
22
+    await expect(elementByLabel('componentDidAppear | navigation.playground.StaticLifecycleOverlay')).toBeVisible();
23
+    await elementById(testIDs.PUSH_BUTTON).tap();
24
+    await expect(elementByLabel('push')).toBeVisible();
25
+    await elementById(testIDs.POP_BUTTON).tap();
26
+    await expect(elementByLabel('pop')).toBeVisible();
27
+  });
28
+
29
+  it('showModal and dismissModal dispatch static event', async () => {
30
+    await elementById(testIDs.PUSH_STATIC_LIFECYCLE_BUTTON).tap();
31
+    await expect(elementByLabel('Static Lifecycle Events Overlay')).toBeVisible();
32
+    await expect(elementByLabel('componentDidAppear | navigation.playground.StaticLifecycleOverlay')).toBeVisible();
33
+    await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
34
+    await expect(elementByLabel('showModal')).toBeVisible();
35
+    await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
36
+    await expect(elementByLabel('dismissModal')).toBeVisible();
37
+  });
38
+
19 39
   it(':ios: unmounts when dismissed', async () => {
20 40
     await elementById(testIDs.PUSH_STATIC_LIFECYCLE_BUTTON).tap();
21 41
     await expect(elementByLabel('Static Lifecycle Events Overlay')).toBeVisible();

+ 7
- 10
lib/ios/RNNCommandsHandler.m View File

@@ -127,7 +127,6 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
127 127
 			[rootVc registerForPreviewingWithDelegate:(id)rootVc sourceView:elementView];
128 128
 		}
129 129
 	} else {
130
-		[_eventEmitter sendOnNavigationCommand:push params:@{@"componentId": componentId}];
131 130
 		[_navigationStackManager push:newVc onTop:componentId completion:^{
132 131
 			[_eventEmitter sendOnNavigationCommandCompletion:push params:@{@"componentId": componentId}];
133 132
 			completion();
@@ -137,7 +136,6 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
137 136
 
138 137
 -(void)setStackRoot:(NSString*)componentId layout:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
139 138
 	[self assertReady];
140
-	[_eventEmitter sendOnNavigationCommand:setStackRoot params:@{@"componentId": componentId}];
141 139
 	
142 140
 	UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
143 141
 	__weak typeof(RNNEventEmitter*) weakEventEmitter = _eventEmitter;
@@ -149,7 +147,7 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
149 147
 
150 148
 -(void)pop:(NSString*)componentId options:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
151 149
 	[self assertReady];
152
-	[_eventEmitter sendOnNavigationCommand:pop params:@{@"componentId": componentId}];
150
+
153 151
 	[CATransaction begin];
154 152
 	[CATransaction setCompletionBlock:^{
155 153
 		[_eventEmitter sendOnNavigationCommandCompletion:pop params:@{@"componentId": componentId}];
@@ -169,7 +167,6 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
169 167
 
170 168
 -(void) popTo:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
171 169
 	[self assertReady];
172
-	[_eventEmitter sendOnNavigationCommand:popTo params:@{@"componentId": componentId}];
173 170
 	[CATransaction begin];
174 171
 	[CATransaction setCompletionBlock:^{
175 172
 		[_eventEmitter sendOnNavigationCommandCompletion:popTo params:@{@"componentId": componentId}];
@@ -183,7 +180,7 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
183 180
 
184 181
 -(void) popToRoot:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
185 182
 	[self assertReady];
186
-	[_eventEmitter sendOnNavigationCommand:popToRoot params:@{@"componentId": componentId}];
183
+
187 184
 	[CATransaction begin];
188 185
 	[CATransaction setCompletionBlock:^{
189 186
 		[_eventEmitter sendOnNavigationCommandCompletion:popToRoot params:@{@"componentId": componentId}];
@@ -197,7 +194,7 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
197 194
 
198 195
 -(void) showModal:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion {
199 196
 	[self assertReady];
200
-	[_eventEmitter sendOnNavigationCommand:showModal params:@{@"layout": layout}];
197
+
201 198
 	UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
202 199
 	[_modalManager showModal:newVc completion:^{
203 200
 		[_eventEmitter sendOnNavigationCommandCompletion:showModal params:@{@"layout": layout}];
@@ -207,7 +204,7 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
207 204
 
208 205
 -(void) dismissModal:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion {
209 206
 	[self assertReady];
210
-	[_eventEmitter sendOnNavigationCommand:dismissModal params:@{@"componentId": componentId}];
207
+
211 208
 	[CATransaction begin];
212 209
 	[CATransaction setCompletionBlock:^{
213 210
 		[_eventEmitter sendOnNavigationCommandCompletion:dismissModal params:@{@"componentId": componentId}];
@@ -221,7 +218,7 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
221 218
 
222 219
 -(void) dismissAllModalsWithCompletion:(RNNTransitionCompletionBlock)completion {
223 220
 	[self assertReady];
224
-	[_eventEmitter sendOnNavigationCommand:dismissAllModals params:@{}];
221
+
225 222
 	[CATransaction begin];
226 223
 	[CATransaction setCompletionBlock:^{
227 224
 		[_eventEmitter sendOnNavigationCommandCompletion:dismissAllModals params:@{}];
@@ -235,7 +232,7 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
235 232
 
236 233
 -(void)showOverlay:(NSDictionary *)layout completion:(RNNTransitionCompletionBlock)completion {
237 234
 	[self assertReady];
238
-	[_eventEmitter sendOnNavigationCommand:showOverlay params:@{@"layout": layout}];
235
+
239 236
 	UIViewController<RNNRootViewProtocol>* overlayVC = [_controllerFactory createOverlay:layout];
240 237
 	[_overlayManager showOverlay:overlayVC completion:^{
241 238
 		[_eventEmitter sendOnNavigationCommandCompletion:showOverlay params:@{@"layout": layout}];
@@ -245,7 +242,7 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
245 242
 
246 243
 - (void)dismissOverlay:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion {
247 244
 	[self assertReady];
248
-	[_eventEmitter sendOnNavigationCommand:dismissModal params:@{@"componentId": componentId}];
245
+
249 246
 	[_overlayManager dismissOverlay:componentId completion:^{
250 247
 		[_eventEmitter sendOnNavigationCommandCompletion:dismissModal params:@{@"componentId": componentId}];
251 248
 		completion();

+ 1
- 3
lib/ios/RNNEventEmitter.m View File

@@ -45,9 +45,7 @@ static NSString* const navigationEvent	= @"RNN.nativeEvent";
45 45
 }
46 46
 
47 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}];
48
+	[self send:commandComplete body:@{@"commandId":commandName , @"params": params, @"completionTime": [RNNUtils getCurrentTimestamp] }];
51 49
 }
52 50
 
53 51
 -(void)sendOnNavigationEvent:(NSString *)commandName params:(NSDictionary*)params {

+ 13
- 4
playground/src/screens/StaticLifecycleOverlay.js View File

@@ -22,9 +22,10 @@ class StaticLifecycleOverlay extends Component {
22 22
         events: [...this.state.events, { event: 'componentDidDisappear', componentId, componentName }]
23 23
       });
24 24
     }));
25
-    this.listeners.push(Navigation.events().registerCommandListener((name, params) => {
26
-      // console.log('RNN', `name: ${JSON.stringify(name)}`);
27
-      // console.log('RNN', `params: ${JSON.stringify(params)}`);
25
+    this.listeners.push(Navigation.events().registerCommandCompletedListener((commandId, completionTime, params) => {
26
+      this.setState({
27
+        events: [...this.state.events, { event: 'commandCompleted', commandId }]
28
+      });
28 29
     }));
29 30
   }
30 31
 
@@ -34,11 +35,19 @@ class StaticLifecycleOverlay extends Component {
34 35
     alert('Overlay Unmounted');
35 36
   }
36 37
 
38
+  renderEvent(event) {
39
+    if (event.commandId) {
40
+      return <Text style={styles.h2}>{`${event.commandId}`}</Text>;
41
+    } else {
42
+      return <Text style={styles.h2}>{`${event.event} | ${event.componentName}`}</Text>;
43
+    }
44
+  }
45
+
37 46
   render() {
38 47
     const events = this.state.events.map((event, idx) =>
39 48
       (
40 49
         <View key={`${event.componentId}${idx}`}>
41
-          <Text style={styles.h2}>{`${event.event} | ${event.componentName}`}</Text>
50
+          {this.renderEvent(event)}
42 51
         </View>
43 52
       ));
44 53
     return (