From 1b6874034aec21ada0a5ddba46ac3c03c4ad0fcb Mon Sep 17 00:00:00 2001 From: Doris Verria Date: Thu, 24 Mar 2022 16:21:49 +0100 Subject: [PATCH] Implement QPlatformTheme::appearance() for iOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement support for detecting Light/Dark mode on iOS. This is needed by the QQuickIOSStyle in order to display the proper image assets according to the theme. A further improvement would be to react to theme changes dynamically. Change-Id: I95e11c4a4b647614bdd78d734941d2b11546687a Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qiostheme.h | 2 ++ src/plugins/platforms/ios/qiostheme.mm | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/plugins/platforms/ios/qiostheme.h b/src/plugins/platforms/ios/qiostheme.h index 594031599a..400637eca1 100644 --- a/src/plugins/platforms/ios/qiostheme.h +++ b/src/plugins/platforms/ios/qiostheme.h @@ -55,6 +55,8 @@ public: const QPalette *palette(Palette type = SystemPalette) const override; QVariant themeHint(ThemeHint hint) const override; + Appearance appearance() const override; + QPlatformMenuItem* createPlatformMenuItem() const override; QPlatformMenu* createPlatformMenu() const override; diff --git a/src/plugins/platforms/ios/qiostheme.mm b/src/plugins/platforms/ios/qiostheme.mm index 9131963818..045b4d45c9 100644 --- a/src/plugins/platforms/ios/qiostheme.mm +++ b/src/plugins/platforms/ios/qiostheme.mm @@ -167,6 +167,19 @@ QVariant QIOSTheme::themeHint(ThemeHint hint) const } } +QPlatformTheme::Appearance QIOSTheme::appearance() const +{ + if (@available(ios 12, *)) { + if (UIWindow *window = qt_apple_sharedApplication().keyWindow) { + return window.rootViewController.traitCollection.userInterfaceStyle + == UIUserInterfaceStyleDark + ? QPlatformTheme::Appearance::Dark + : QPlatformTheme::Appearance::Light; + } + } + return QPlatformTheme::Appearance::Unknown; +} + const QFont *QIOSTheme::font(Font type) const { const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();