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 disappearing alert bug on iOS #26839

Closed
wants to merge 3 commits into from
Closed
Changes from 2 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
11 changes: 6 additions & 5 deletions React/Modules/RCTAlertManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ @interface RCTAlertManager()
@implementation RCTAlertManager
{
NSHashTable *_alertControllers;
UIWindow *_window;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not store UIWindow as an ivar (because it's not shared among instances of view controllers), right?
Instead, we should just remove a window instance from Screen instance on alert being dismissed. We can geet a particular window instance from presented view controller (or any mounted view) instance.

Copy link
Contributor Author

@sryze sryze May 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shergin You are right, it doesn't need to be an ivar, it can be a local variable here. In that case it also must be strongly captured by the action handler block of UIAlertController, otherwise the window gets destroyed while we are showing the alert controller. It looks like UIAlertController (or UIViewController in general) doesn't keep a strong reference to its window.

}

RCT_EXPORT_MODULE()
Expand Down Expand Up @@ -90,11 +91,10 @@ - (void)invalidate
}
}

UIViewController *presentingController = RCTPresentedViewController();
if (presentingController == nil) {
RCTLogError(@"Tried to display alert view but there is no application window. args: %@", args);
return;
}
_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
_window.windowLevel = UIWindowLevelStatusBar + 1;
UIViewController *presentingController = [UIViewController new];
_window.rootViewController = presentingController;

UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:title
Expand Down Expand Up @@ -152,6 +152,7 @@ - (void)invalidate
[alertController addAction:[UIAlertAction actionWithTitle:buttonTitle
style:buttonStyle
handler:^(__unused UIAlertAction *action) {
self->_window = nil;
switch (type) {
case RCTAlertViewStylePlainTextInput:
case RCTAlertViewStyleSecureTextInput:
Expand Down