iOS: Defer restoring screen mirroring until next runloop pass

Associating the UIWindow with a different screen will trigger layout
of the child views of the window, including the view that we're in
the process of removing, which doesn't have a platform window anymore.

Instead of protecting every possible code path in the view code
with checks for a platform window we defer the restoring of
mirror mode until after the view has been removed.

Pick-to: 6.2 5.15
Task-number: QTBUG-94530
Change-Id: I8c66106cafa67e06721e621c019b2d10acf02326
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Tor Arne Vestbø 2021-11-03 17:14:34 +01:00
parent f2d1502429
commit 36852d78bf

View File

@ -147,9 +147,13 @@
UIWindow *uiWindow = self.window;
if (uiWindow.screen != [UIScreen mainScreen] && self.subviews.count == 1) {
// Removing the last view of an external screen, go back to mirror mode
uiWindow.screen = [UIScreen mainScreen];
uiWindow.hidden = YES;
// We're about to remove the last view of an external screen, so go back
// to mirror mode, but defer it until after the view has been removed,
// to ensure that we don't try to layout the view that's being removed.
dispatch_async(dispatch_get_main_queue(), ^{
uiWindow.screen = [UIScreen mainScreen];
uiWindow.hidden = YES;
});
}
}