Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix the potential race condition when dismissing and presentating modal #35705

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions React/Views/RCTModalHostViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ - (void)presentModalHostView:(RCTModalHostView *)modalHostView
modalHostView.onShow(nil);
}
};
if (_presentationBlock) {
_presentationBlock([modalHostView reactViewController], viewController, animated, completionBlock);
} else {
[[modalHostView reactViewController] presentViewController:viewController
animated:animated
completion:completionBlock];
}
dispatch_async(dispatch_get_main_queue(), ^{
if (self->_presentationBlock) {
self->_presentationBlock([modalHostView reactViewController], viewController, animated, completionBlock);
} else {
[[modalHostView reactViewController] presentViewController:viewController
animated:animated
completion:completionBlock];
}
});
}

- (void)dismissModalHostView:(RCTModalHostView *)modalHostView
Expand All @@ -93,11 +95,13 @@ - (void)dismissModalHostView:(RCTModalHostView *)modalHostView
[[self.bridge moduleForClass:[RCTModalManager class]] modalDismissed:modalHostView.identifier];
}
};
if (_dismissalBlock) {
_dismissalBlock([modalHostView reactViewController], viewController, animated, completionBlock);
} else {
[viewController.presentingViewController dismissViewControllerAnimated:animated completion:completionBlock];
}
dispatch_async(dispatch_get_main_queue(), ^{
if (self->_dismissalBlock) {
self->_dismissalBlock([modalHostView reactViewController], viewController, animated, completionBlock);
} else {
[viewController.presentingViewController dismissViewControllerAnimated:animated completion:completionBlock];
}
});
}

- (RCTShadowView *)shadowView
Expand Down