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 Change-Id: Ic0b29c02c8e8100996d5cd31b37e6a5b839f5fb1 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit 551cbc5b15b46ca4b298a9dfe946f834e0cd2fed) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
18f8aae1f5
commit
7c32220284
@ -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…
x
Reference in New Issue
Block a user