Skip to content

Commit

Permalink
Reject pop command when viewController not found in the hierarchy (#6048
Browse files Browse the repository at this point in the history
)

Until now the promise was rejected only on Android.
  • Loading branch information
yogevbd authored Mar 16, 2020
1 parent 3c38c50 commit 4413aa4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/ios/RNNCommandsHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,17 @@ - (void)pop:(NSString*)componentId commandId:(NSString*)commandId mergeOptions:(
RNNAssertMainQueue();

RNNComponentViewController *vc = (RNNComponentViewController*)[RNNLayoutManager findComponentForId:componentId];
RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initWithDict:mergeOptions];
[vc overrideOptions:options];

[vc.stack pop:vc animated:[vc.resolveOptionsWithDefault.animations.pop.enable getWithDefaultValue:YES] completion:^{
[_eventEmitter sendOnNavigationCommandCompletion:pop commandId:commandId params:@{@"componentId": componentId}];
completion();
} rejection:rejection];
if (vc) {
RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initWithDict:mergeOptions];
[vc overrideOptions:options];

[vc.stack pop:vc animated:[vc.resolveOptionsWithDefault.animations.pop.enable getWithDefaultValue:YES] completion:^{
[self->_eventEmitter sendOnNavigationCommandCompletion:pop commandId:commandId params:@{@"componentId": componentId}];
completion();
} rejection:rejection];
} else {
[RNNErrorHandler reject:rejection withErrorCode:1012 errorDescription:[NSString stringWithFormat:@"Popping component failed - componentId '%@' not found", componentId]];
}
}

- (void)popTo:(NSString*)componentId commandId:(NSString*)commandId mergeOptions:(NSDictionary *)mergeOptions completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
Expand Down
15 changes: 15 additions & 0 deletions playground/ios/NavigationTests/RNNCommandsHandlerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -454,5 +454,20 @@ - (void)testShowModal_shouldShowAnimated {
[self.modalManager verify];
}

- (void)testPop_shouldRejectPromiseForInvalidComponentId {
[self.uut setReadyToReceiveCommands:true];

XCTestExpectation *expectation = [self expectationWithDescription:@"Should invoke reject block"];

[self.uut pop:@"invalidComponentId" commandId:@"pop" mergeOptions:nil completion:^{
[expectation fulfill];
} rejection:^(NSString *code, NSString *message, NSError *error) {
XCTAssert([code isEqualToString:@"1012"]);
XCTAssert([message isEqualToString:@"Popping component failed - componentId 'invalidComponentId' not found"]);
[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:5 handler:nil];
}

@end

0 comments on commit 4413aa4

Please sign in to comment.