From 218b4c19bb25d6ae44b3c2f211bf790b56239074 Mon Sep 17 00:00:00 2001 From: Asaf Korem Date: Wed, 19 Jan 2022 01:08:07 -0800 Subject: [PATCH] fix(iOS): remove alert's window when call to `hide`. (#32833) Summary: Resolves this issue: https://github.com/facebook/react-native/issues/32304. **NOTE:** This PR is based on a prior PR for this fix: https://github.com/facebook/react-native/pull/32305, I've co-authorized its creator for this change (paddlefish). Without this change, calling to hide an alert, leaves a `UIWindow` that blocks user interactions with the screen. The correct way to remove a `UIWindow` in iOS is to set its hidden property to `YES`. Also, it is required to remove all references to the window (the associated `windowScene` for example) and ARC will automatically free this `UIWindow`. The line after this change, set the `_alertWindow` reference to `nil`, but the window is already associated with a scene (see the screenshots from [this PR](https://github.com/facebook/react-native/pull/32305#discussion_r720521707)). So we also need to remove the `windowScene` from that window, as recommended by Apple: https://developer.apple.com/documentation/uikit/uiwindowscene/3198091-windows. >To remove the window from the current scene, or move it to a different scene, change the value of the window's windowScene property. ## Changelog [iOS] [Fixed] - remove alert's window when call to `hide`. Pull Request resolved: https://github.com/facebook/react-native/pull/32833 Test Plan: See https://github.com/facebook/react-native/pull/32305 Reviewed By: hramos Differential Revision: D33460430 Pulled By: lunaleaps fbshipit-source-id: b13c2c7ee6404f1e1c787265bc4af8a31005bcf1 --- React/CoreModules/RCTAlertController.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/React/CoreModules/RCTAlertController.m b/React/CoreModules/RCTAlertController.m index 8cd0babb559..1a4ed8c4f65 100644 --- a/React/CoreModules/RCTAlertController.m +++ b/React/CoreModules/RCTAlertController.m @@ -35,6 +35,12 @@ - (void)hide { + [_alertWindow setHidden:YES]; + + if (@available(iOS 13, *)) { + _alertWindow.windowScene = nil; + } + _alertWindow = nil; }