diff --git a/React/Views/RCTModalHostViewManager.m b/React/Views/RCTModalHostViewManager.m index bafab9dff9f3a9..4698139f90102b 100644 --- a/React/Views/RCTModalHostViewManager.m +++ b/React/Views/RCTModalHostViewManager.m @@ -48,6 +48,8 @@ - (void)insertReactSubview:(id)subview atIndex:(NSInteger)atIndex @interface RCTModalHostViewManager () +@property (nonatomic, copy) dispatch_block_t dismissWaitingBlock; + @end @implementation RCTModalHostViewManager { @@ -79,9 +81,16 @@ - (void)presentModalHostView:(RCTModalHostView *)modalHostView if (_presentationBlock) { _presentationBlock([modalHostView reactViewController], viewController, animated, completionBlock); } else { + __weak typeof(self) weakself = self; [[modalHostView reactViewController] presentViewController:viewController animated:animated - completion:completionBlock]; + completion:^{ + !completionBlock ?: completionBlock(); + __strong typeof(weakself) strongself = weakself; + !strongself.dismissWaitingBlock + ?: strongself.dismissWaitingBlock(); + strongself.dismissWaitingBlock = nil; + }]; } } @@ -92,7 +101,13 @@ - (void)dismissModalHostView:(RCTModalHostView *)modalHostView if (_dismissalBlock) { _dismissalBlock([modalHostView reactViewController], viewController, animated, nil); } else { - [viewController.presentingViewController dismissViewControllerAnimated:animated completion:nil]; + self.dismissWaitingBlock = ^{ + [viewController.presentingViewController dismissViewControllerAnimated:animated completion:nil]; + }; + if (viewController.presentingViewController) { + self.dismissWaitingBlock(); + self.dismissWaitingBlock = nil; + } } }