Skip to content

Commit 5c368a5

Browse files
authored
Fix commands resolving (#6448)
* Resolve `setRoot` with root `componentId` * Resolve `push` with pushed screen `componentId` * Remove `params` from commandCompletion events
1 parent 402657f commit 5c368a5

File tree

14 files changed

+167
-66
lines changed

14 files changed

+167
-66
lines changed

e2e/Stack.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,16 @@ describe('Stack', () => {
110110
await elementByLabel('Start Typing').typeText(query);
111111
await expect(elementById(TestIDs.SEARCH_RESULT_ITEM)).toHaveText(`Item ${query}`);
112112
});
113+
114+
it('push promise is resolved with pushed ViewController id', async () => {
115+
await elementById(TestIDs.STACK_COMMANDS_BTN).tap();
116+
await elementById(TestIDs.PUSH_BTN).tap();
117+
118+
await expect(element(by.id(TestIDs.PUSH_PROMISE_RESULT))).toHaveText(
119+
'push promise resolved with: ChildId'
120+
);
121+
await expect(element(by.id(TestIDs.POP_PROMISE_RESULT))).toHaveText(
122+
'pop promise resolved with: ChildId'
123+
);
124+
});
113125
});

lib/ios/RNNBridgeModule.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ -(instancetype)initWithCommandsHandler:(RNNCommandsHandler *)commandsHandler {
2121

2222
RCT_EXPORT_METHOD(setRoot:(NSString*)commandId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
2323
RCTExecuteOnMainQueue(^{
24-
[self->_commandsHandler setRoot:layout commandId:commandId completion:^{
25-
resolve(layout);
24+
[self->_commandsHandler setRoot:layout commandId:commandId completion:^(NSString* componentId) {
25+
resolve(componentId);
2626
}];
2727
});
2828
}
@@ -45,8 +45,8 @@ -(instancetype)initWithCommandsHandler:(RNNCommandsHandler *)commandsHandler {
4545

4646
RCT_EXPORT_METHOD(push:(NSString*)commandId componentId:(NSString*)componentId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
4747
RCTExecuteOnMainQueue(^{
48-
[self->_commandsHandler push:componentId commandId:commandId layout:layout completion:^{
49-
resolve(componentId);
48+
[self->_commandsHandler push:componentId commandId:commandId layout:layout completion:^(NSString* pushedComponentId) {
49+
resolve(pushedComponentId);
5050
} rejection:reject];
5151
});
5252
}
@@ -109,8 +109,8 @@ -(instancetype)initWithCommandsHandler:(RNNCommandsHandler *)commandsHandler {
109109

110110
RCT_EXPORT_METHOD(showOverlay:(NSString*)commandId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
111111
RCTExecuteOnMainQueue(^{
112-
[self->_commandsHandler showOverlay:layout commandId:commandId completion:^{
113-
resolve(layout[@"id"]);
112+
[self->_commandsHandler showOverlay:layout commandId:commandId completion:^(NSString * _Nonnull componentId) {
113+
resolve(componentId);
114114
}];
115115
});
116116
}

lib/ios/RNNCommandsHandler.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
@property (nonatomic) BOOL readyToReceiveCommands;
1212

13-
- (void)setRoot:(NSDictionary*)layout commandId:(NSString*)commandId completion:(RNNTransitionCompletionBlock)completion;
13+
- (void)setRoot:(NSDictionary*)layout commandId:(NSString*)commandId completion:(RNNTransitionWithComponentIdCompletionBlock)completion;
1414

1515
- (void)mergeOptions:(NSString*)componentId options:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion;
1616

1717
- (void)setDefaultOptions:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion;
1818

19-
- (void)push:(NSString*)componentId commandId:(NSString*)commandId layout:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection;
19+
- (void)push:(NSString*)componentId commandId:(NSString*)commandId layout:(NSDictionary*)layout completion:(RNNTransitionWithComponentIdCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection;
2020

2121
- (void)pop:(NSString*)componentId commandId:(NSString*)commandId mergeOptions:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection;
2222

@@ -32,7 +32,7 @@
3232

3333
- (void)dismissAllModals:(NSDictionary *)options commandId:(NSString*)commandId completion:(RNNTransitionCompletionBlock)completion;
3434

35-
- (void)showOverlay:(NSDictionary *)layout commandId:(NSString*)commandId completion:(RNNTransitionCompletionBlock)completion;
35+
- (void)showOverlay:(NSDictionary *)layout commandId:(NSString*)commandId completion:(RNNTransitionWithComponentIdCompletionBlock)completion;
3636

3737
- (void)dismissOverlay:(NSString*)componentId commandId:(NSString*)commandId completion:(RNNTransitionCompletionBlock)completion rejection:(RNNTransitionRejectionBlock)reject;
3838

lib/ios/RNNCommandsHandler.m

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ - (instancetype)initWithControllerFactory:(RNNControllerFactory*)controllerFacto
4949

5050
#pragma mark - public
5151

52-
- (void)setRoot:(NSDictionary*)layout commandId:(NSString*)commandId completion:(RNNTransitionCompletionBlock)completion {
52+
- (void)setRoot:(NSDictionary*)layout commandId:(NSString*)commandId completion:(RNNTransitionWithComponentIdCompletionBlock)completion {
5353
[self assertReady];
5454
RNNAssertMainQueue();
5555

@@ -77,8 +77,8 @@ - (void)setRoot:(NSDictionary*)layout commandId:(NSString*)commandId completion:
7777
[vc setReactViewReadyCallback:^{
7878
[self->_mainWindow.rootViewController destroy];
7979
self->_mainWindow.rootViewController = weakVC;
80-
[self->_eventEmitter sendOnNavigationCommandCompletion:setRoot commandId:commandId params:@{@"layout": layout}];
81-
completion();
80+
[self->_eventEmitter sendOnNavigationCommandCompletion:setRoot commandId:commandId];
81+
completion(weakVC.layoutInfo.componentId);
8282
}];
8383

8484
[vc render];
@@ -112,7 +112,7 @@ - (void)setDefaultOptions:(NSDictionary*)optionsDict completion:(RNNTransitionCo
112112
completion();
113113
}
114114

115-
- (void)push:(NSString*)componentId commandId:(NSString*)commandId layout:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
115+
- (void)push:(NSString*)componentId commandId:(NSString*)commandId layout:(NSDictionary*)layout completion:(RNNTransitionWithComponentIdCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
116116
[self assertReady];
117117
RNNAssertMainQueue();
118118

@@ -131,8 +131,8 @@ - (void)push:(NSString*)componentId commandId:(NSString*)commandId layout:(NSDic
131131
if ([newVc.resolveOptionsWithDefault.preview.commit getWithDefaultValue:NO]) {
132132
[CATransaction begin];
133133
[CATransaction setCompletionBlock:^{
134-
[self->_eventEmitter sendOnNavigationCommandCompletion:push commandId:commandId params:@{@"componentId": componentId}];
135-
completion();
134+
[self->_eventEmitter sendOnNavigationCommandCompletion:push commandId:commandId ];
135+
completion(newVc.layoutInfo.componentId);
136136
}];
137137
[rvc.navigationController pushViewController:newVc animated:YES];
138138
[CATransaction commit];
@@ -162,8 +162,8 @@ - (void)push:(NSString*)componentId commandId:(NSString*)commandId layout:(NSDic
162162
__weak UIViewController* weakNewVC = newVc;
163163
[newVc setReactViewReadyCallback:^{
164164
[fromVC.stack push:weakNewVC onTop:fromVC animated:[weakNewVC.resolveOptionsWithDefault.animations.push.enable getWithDefaultValue:YES] completion:^{
165-
[self->_eventEmitter sendOnNavigationCommandCompletion:push commandId:commandId params:@{@"componentId": componentId}];
166-
completion();
165+
[self->_eventEmitter sendOnNavigationCommandCompletion:push commandId:commandId];
166+
completion(weakNewVC.layoutInfo.componentId);
167167
} rejection:rejection];
168168
}];
169169

@@ -189,7 +189,7 @@ - (void)setStackRoot:(NSString*)componentId commandId:(NSString*)commandId child
189189
newVC.waitForRender = ([options.animations.setStackRoot.waitForRender getWithDefaultValue:NO]);
190190
[newVC setReactViewReadyCallback:^{
191191
[fromVC.stack setStackChildren:childViewControllers fromViewController:fromVC animated:[options.animations.setStackRoot.enable getWithDefaultValue:YES] completion:^{
192-
[weakEventEmitter sendOnNavigationCommandCompletion:setStackRoot commandId:commandId params:@{@"componentId": componentId}];
192+
[weakEventEmitter sendOnNavigationCommandCompletion:setStackRoot commandId:commandId];
193193
completion();
194194
} rejection:rejection];
195195
}];
@@ -207,7 +207,7 @@ - (void)pop:(NSString*)componentId commandId:(NSString*)commandId mergeOptions:(
207207
[vc overrideOptions:options];
208208

209209
[vc.stack pop:vc animated:[vc.resolveOptionsWithDefault.animations.pop.enable getWithDefaultValue:YES] completion:^{
210-
[self->_eventEmitter sendOnNavigationCommandCompletion:pop commandId:commandId params:@{@"componentId": componentId}];
210+
[self->_eventEmitter sendOnNavigationCommandCompletion:pop commandId:commandId];
211211
completion();
212212
} rejection:rejection];
213213
} else {
@@ -224,7 +224,7 @@ - (void)popTo:(NSString*)componentId commandId:(NSString*)commandId mergeOptions
224224
[vc overrideOptions:options];
225225

226226
[vc.stack popTo:vc animated:[vc.resolveOptionsWithDefault.animations.pop.enable getWithDefaultValue:YES] completion:^(NSArray *poppedViewControllers) {
227-
[self->_eventEmitter sendOnNavigationCommandCompletion:popTo commandId:commandId params:@{@"componentId": componentId}];
227+
[self->_eventEmitter sendOnNavigationCommandCompletion:popTo commandId:commandId];
228228
completion();
229229
} rejection:rejection];
230230
}
@@ -239,7 +239,7 @@ - (void)popToRoot:(NSString*)componentId commandId:(NSString*)commandId mergeOpt
239239

240240
[CATransaction begin];
241241
[CATransaction setCompletionBlock:^{
242-
[self->_eventEmitter sendOnNavigationCommandCompletion:popToRoot commandId:commandId params:@{@"componentId": componentId}];
242+
[self->_eventEmitter sendOnNavigationCommandCompletion:popToRoot commandId:commandId];
243243
completion();
244244
}];
245245

@@ -261,7 +261,7 @@ - (void)showModal:(NSDictionary*)layout commandId:(NSString *)commandId completi
261261
newVc.waitForRender = [newVc.resolveOptionsWithDefault.animations.showModal.waitForRender getWithDefaultValue:NO];
262262
[newVc setReactViewReadyCallback:^{
263263
[self->_modalManager showModal:weakNewVC animated:[weakNewVC.resolveOptionsWithDefault.animations.showModal.enable getWithDefaultValue:YES] completion:^(NSString *componentId) {
264-
[self->_eventEmitter sendOnNavigationCommandCompletion:showModal commandId:commandId params:@{@"layout": layout}];
264+
[self->_eventEmitter sendOnNavigationCommandCompletion:showModal commandId:commandId];
265265
completion(weakNewVC.layoutInfo.componentId);
266266
}];
267267
}];
@@ -284,7 +284,7 @@ - (void)dismissModal:(NSString*)componentId commandId:(NSString*)commandId merge
284284

285285
[CATransaction begin];
286286
[CATransaction setCompletionBlock:^{
287-
[self->_eventEmitter sendOnNavigationCommandCompletion:dismissModal commandId:commandId params:@{@"componentId": componentId}];
287+
[self->_eventEmitter sendOnNavigationCommandCompletion:dismissModal commandId:commandId];
288288
}];
289289

290290
[_modalManager dismissModal:modalToDismiss completion:^{
@@ -300,7 +300,7 @@ - (void)dismissAllModals:(NSDictionary *)mergeOptions commandId:(NSString*)comma
300300

301301
[CATransaction begin];
302302
[CATransaction setCompletionBlock:^{
303-
[self->_eventEmitter sendOnNavigationCommandCompletion:dismissAllModals commandId:commandId params:@{}];
303+
[self->_eventEmitter sendOnNavigationCommandCompletion:dismissAllModals commandId:commandId];
304304
completion();
305305
}];
306306
RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:mergeOptions];
@@ -309,7 +309,7 @@ - (void)dismissAllModals:(NSDictionary *)mergeOptions commandId:(NSString*)comma
309309
[CATransaction commit];
310310
}
311311

312-
- (void)showOverlay:(NSDictionary *)layout commandId:(NSString*)commandId completion:(RNNTransitionCompletionBlock)completion {
312+
- (void)showOverlay:(NSDictionary *)layout commandId:(NSString*)commandId completion:(RNNTransitionWithComponentIdCompletionBlock)completion {
313313
[self assertReady];
314314
RNNAssertMainQueue();
315315

@@ -323,8 +323,8 @@ - (void)showOverlay:(NSDictionary *)layout commandId:(NSString*)commandId comple
323323
[self->_overlayManager showOverlayWindow:overlayWindow];
324324
}
325325

326-
[self->_eventEmitter sendOnNavigationCommandCompletion:showOverlay commandId:commandId params:@{@"layout": layout}];
327-
completion();
326+
[self->_eventEmitter sendOnNavigationCommandCompletion:showOverlay commandId:commandId];
327+
completion(weakOverlayVC.layoutInfo.componentId);
328328

329329
}];
330330

@@ -338,7 +338,7 @@ - (void)dismissOverlay:(NSString*)componentId commandId:(NSString*)commandId com
338338
UIViewController* viewController = [RNNLayoutManager findComponentForId:componentId];
339339
if (viewController) {
340340
[_overlayManager dismissOverlay:viewController];
341-
[_eventEmitter sendOnNavigationCommandCompletion:dismissOverlay commandId:commandId params:@{@"componentId": componentId}];
341+
[_eventEmitter sendOnNavigationCommandCompletion:dismissOverlay commandId:commandId];
342342
completion();
343343
} else {
344344
[RNNErrorHandler reject:reject withErrorCode:1010 errorDescription:@"ComponentId not found"];

lib/ios/RNNEventEmitter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
- (void)sendBottomTabLongPressed:(NSNumber *)selectedTabIndex;
1818

19-
- (void)sendOnNavigationCommandCompletion:(NSString *)commandName commandId:(NSString *)commandId params:(NSDictionary*)params;
19+
- (void)sendOnNavigationCommandCompletion:(NSString *)commandName commandId:(NSString *)commandId;
2020

2121
- (void)sendOnSearchBarUpdated:(NSString *)componentId text:(NSString*)text isFocused:(BOOL)isFocused;
2222

lib/ios/RNNEventEmitter.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,10 @@ -(void)sendBottomTabPressed:(NSNumber *)tabIndex {
9292
}];
9393
}
9494

95-
-(void)sendOnNavigationCommandCompletion:(NSString *)commandName commandId:(NSString *)commandId params:(NSDictionary*)params {
95+
- (void)sendOnNavigationCommandCompletion:(NSString *)commandName commandId:(NSString *)commandId {
9696
[self send:CommandCompleted body:@{
9797
@"commandId":commandId,
9898
@"commandName":commandName,
99-
@"params": params,
10099
@"completionTime": [RNNUtils getCurrentTimestamp]
101100
}];
102101
}

lib/src/interfaces/Events.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ export interface CommandCompletedEvent {
22
commandName: string;
33
commandId: string;
44
completionTime: number;
5-
params: any;
65
}
76

87
export interface BottomTabSelectedEvent {

0 commit comments

Comments
 (0)