Skip to content

Commit

Permalink
fix(iOS): remove alert's window when call to hide. (#32833)
Browse files Browse the repository at this point in the history
Summary:
Resolves this issue: #32304.
**NOTE:** This PR is based on a prior PR for this fix: #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](#32305 (comment))). 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

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[iOS] [Fixed] - remove alert's window when call to `hide`.

Pull Request resolved: #32833

Test Plan: See #32305

Reviewed By: hramos

Differential Revision: D33460430

Pulled By: lunaleaps

fbshipit-source-id: b13c2c7ee6404f1e1c787265bc4af8a31005bcf1
  • Loading branch information
asafkorem authored and facebook-github-bot committed Jan 19, 2022
1 parent 43e07a4 commit a46a99e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions React/CoreModules/RCTAlertController.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ - (void)show:(BOOL)animated completion:(void (^)(void))completion

- (void)hide
{
[_alertWindow setHidden:YES];

if (@available(iOS 13, *)) {
_alertWindow.windowScene = nil;
}

_alertWindow = nil;
}

Expand Down

0 comments on commit a46a99e

Please sign in to comment.