Skip to content

Commit 8933724

Browse files
Mi-ZAZfacebook-github-bot
authored andcommitted
Update RCTModalHostViewManager.m (#29745)
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
1 parent 7e89934 commit 8933724

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

React/Views/RCTModalHostViewManager.m

+17-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ - (void)insertReactSubview:(id<RCTComponent>)subview atIndex:(NSInteger)atIndex
4848

4949
@interface RCTModalHostViewManager () <RCTModalHostViewInteractor>
5050

51+
@property (nonatomic, copy) dispatch_block_t dismissWaitingBlock;
52+
5153
@end
5254

5355
@implementation RCTModalHostViewManager {
@@ -79,9 +81,16 @@ - (void)presentModalHostView:(RCTModalHostView *)modalHostView
7981
if (_presentationBlock) {
8082
_presentationBlock([modalHostView reactViewController], viewController, animated, completionBlock);
8183
} else {
84+
__weak typeof(self) weakself = self;
8285
[[modalHostView reactViewController] presentViewController:viewController
8386
animated:animated
84-
completion:completionBlock];
87+
completion:^{
88+
!completionBlock ?: completionBlock();
89+
__strong typeof(weakself) strongself = weakself;
90+
!strongself.dismissWaitingBlock
91+
?: strongself.dismissWaitingBlock();
92+
strongself.dismissWaitingBlock = nil;
93+
}];
8594
}
8695
}
8796

@@ -92,7 +101,13 @@ - (void)dismissModalHostView:(RCTModalHostView *)modalHostView
92101
if (_dismissalBlock) {
93102
_dismissalBlock([modalHostView reactViewController], viewController, animated, nil);
94103
} else {
95-
[viewController.presentingViewController dismissViewControllerAnimated:animated completion:nil];
104+
self.dismissWaitingBlock = ^{
105+
[viewController.presentingViewController dismissViewControllerAnimated:animated completion:nil];
106+
};
107+
if (viewController.presentingViewController) {
108+
self.dismissWaitingBlock();
109+
self.dismissWaitingBlock = nil;
110+
}
96111
}
97112
}
98113

0 commit comments

Comments
 (0)