From a3019bfe7c7db4bf1fe23341e6859141e0714e82 Mon Sep 17 00:00:00 2001 From: Andrew Rahn Date: Thu, 30 Sep 2021 16:58:09 -0500 Subject: [PATCH 1/2] Fix Alert leaving behind a window and view controller (issue 32304) In hide, the window is explicitly removed from the screen and hidden and the root view controller is set to nil to prevent any possible retain cycle between them --- React/CoreModules/RCTAlertController.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/React/CoreModules/RCTAlertController.m b/React/CoreModules/RCTAlertController.m index 8cd0babb5595c0..ec3a959e702572 100644 --- a/React/CoreModules/RCTAlertController.m +++ b/React/CoreModules/RCTAlertController.m @@ -35,6 +35,9 @@ - (void)show:(BOOL)animated completion:(void (^)(void))completion - (void)hide { + [_alertWindow resignKeyWindow]; + [_alertWindow setHidden: YES]; + _alertWindow.rootViewController = nil; _alertWindow = nil; } From d1cd0fe1a4ddfae20be9ce93e1bed00a53a25288 Mon Sep 17 00:00:00 2001 From: Andrew Rahn Date: Fri, 1 Oct 2021 15:25:02 -0500 Subject: [PATCH 2/2] Simply hiding the window is enough to resolve the issue resignKeyWindow should not be called directly --- React/CoreModules/RCTAlertController.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/React/CoreModules/RCTAlertController.m b/React/CoreModules/RCTAlertController.m index ec3a959e702572..5e94f26580f2f8 100644 --- a/React/CoreModules/RCTAlertController.m +++ b/React/CoreModules/RCTAlertController.m @@ -35,9 +35,7 @@ - (void)show:(BOOL)animated completion:(void (^)(void))completion - (void)hide { - [_alertWindow resignKeyWindow]; [_alertWindow setHidden: YES]; - _alertWindow.rootViewController = nil; _alertWindow = nil; }