Skip to content

Commit

Permalink
Update RCTModalHostViewManager.m (#29745)
Browse files Browse the repository at this point in the history
Summary:
Fix a issue that RCTModalHostView can't be dismissed while being presented

Steps To Reproduce
A native modal presented view controller is being dismissed before the first screen shows.
A RCTModalHostView is presented when the first screen shows.
The RCTModalHostView will be dismissed after an asynchronous callback.
If the callback was called before the completion of the presenting animation, the RCTModalHostView will not be dismissed.

## Changelog

[iOS] [Fixed] - Fix that RCTModalHostView can't be dismissed while being presented

Pull Request resolved: #29745

Reviewed By: shergin

Differential Revision: D23566487

Pulled By: sammy-SC

fbshipit-source-id: bd95f200b79fa75e2387e402091d58c0f538759c
  • Loading branch information
Mi-ZAZ authored and facebook-github-bot committed Sep 9, 2020
1 parent 7e89934 commit 8933724
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions React/Views/RCTModalHostViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ - (void)insertReactSubview:(id<RCTComponent>)subview atIndex:(NSInteger)atIndex

@interface RCTModalHostViewManager () <RCTModalHostViewInteractor>

@property (nonatomic, copy) dispatch_block_t dismissWaitingBlock;

@end

@implementation RCTModalHostViewManager {
Expand Down Expand Up @@ -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;
}];
}
}

Expand All @@ -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;
}
}
}

Expand Down

0 comments on commit 8933724

Please sign in to comment.