mirror of https://github.com/qt/qtbase.git
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>
This commit is contained in:
parent
9b83574e83
commit
551cbc5b15
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue