summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios
diff options
context:
space:
mode:
authorDoris Verria <doris.verria@qt.io>2023-06-22 20:30:18 +0200
committerDoris Verria <doris.verria@qt.io>2023-06-23 00:08:54 +0000
commit551cbc5b15b46ca4b298a9dfe946f834e0cd2fed (patch)
tree78b423b7e5c572872becbf69f05341a64c43d301 /src/plugins/platforms/ios
parent9b83574e8391e3e68a1c400f09b8354e268eeb32 (diff)
iOS plugin: Make sure window is of type QUIWindow when determining the color scheme
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ø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/ios')
-rw-r--r--src/plugins/platforms/ios/qiostheme.mm16
1 files 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<UIWindow *> *windows = qt_apple_sharedApplication().windows;
+ for (UIWindow *window in windows) {
+ if ([window isKindOfClass:[QUIWindow class]]) {
+ appearance = static_cast<QUIWindow*>(window).traitCollection.userInterfaceStyle;
+ break;
+ }
}
+
return appearance == UIUserInterfaceStyleDark
? Qt::ColorScheme::Dark
: Qt::ColorScheme::Light;