From 551cbc5b15b46ca4b298a9dfe946f834e0cd2fed Mon Sep 17 00:00:00 2001 From: Doris Verria Date: Thu, 22 Jun 2023 20:30:18 +0200 Subject: iOS plugin: Make sure window is of type QUIWindow when determining the color scheme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the iOS theme, we determine the color scheme based on the the last UIWindow of the application, but listen to trait changes in the QUIWindow class. However, the last window of the application is not always a QUIWindow. Sometimes it can be a temporary UIWindow created by the system for transitioning or other effects. These kind of windows do not always follow the appearance of the app and the main window (QUIWindow), so we were sometimes ending up with the wrong color scheme being reported. This was happening when the app was put into background for example, which causes the traitCollectionDidChange method to be called and query the userInterfaceStyle of the last window to determine if the color scheme was changed. The queried window would sometimes end up being of type UITextEffectsWindow, etc. and report the wrong appearance. To fix, always make sure to get the appearance from a QUIWindow. Fixes: QTBUG-114571 Fixes: QTBUG-113169 Fixes: QTBUG-114191 Pick-to: 6.5 6.6 6.5.2 Change-Id: Ic0b29c02c8e8100996d5cd31b37e6a5b839f5fb1 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qiostheme.mm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/plugins/platforms/ios/qiostheme.mm b/src/plugins/platforms/ios/qiostheme.mm index d1356ab8f7..fad4a8d581 100644 --- a/src/plugins/platforms/ios/qiostheme.mm +++ b/src/plugins/platforms/ios/qiostheme.mm @@ -23,6 +23,7 @@ #include "qiosmessagedialog.h" #include "qioscolordialog.h" #include "qiosfontdialog.h" +#include "qiosscreen.h" #endif QT_BEGIN_NAMESPACE @@ -144,14 +145,17 @@ QVariant QIOSTheme::themeHint(ThemeHint hint) const Qt::ColorScheme QIOSTheme::colorScheme() const { - UIUserInterfaceStyle appearance = UIUserInterfaceStyleUnspecified; - // Set the appearance based on the UIWindow + // Set the appearance based on the QUIWindow // Fallback to the UIScreen if no window is created yet - if (UIWindow *window = qt_apple_sharedApplication().windows.lastObject) { - appearance = window.traitCollection.userInterfaceStyle; - } else { - appearance = UIScreen.mainScreen.traitCollection.userInterfaceStyle; + UIUserInterfaceStyle appearance = UIScreen.mainScreen.traitCollection.userInterfaceStyle; + NSArray *windows = qt_apple_sharedApplication().windows; + for (UIWindow *window in windows) { + if ([window isKindOfClass:[QUIWindow class]]) { + appearance = static_cast(window).traitCollection.userInterfaceStyle; + break; + } } + return appearance == UIUserInterfaceStyleDark ? Qt::ColorScheme::Dark : Qt::ColorScheme::Light; -- cgit v1.2.3