From bb68a66ffa36151b8f6660e8302030d8d6677bbe Mon Sep 17 00:00:00 2001 From: Kiryl Kaveryn Date: Wed, 28 Feb 2024 14:50:46 +0400 Subject: [PATCH] [ios] fix the initial 'userInterfaceStyle' theme Signed-off-by: Kiryl Kaveryn --- iphone/Maps/Core/Settings/MWMSettings.mm | 17 ---------------- .../Maps/Core/Theme/Core/ThemeManager.swift | 20 +++++++++++++++++++ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/iphone/Maps/Core/Settings/MWMSettings.mm b/iphone/Maps/Core/Settings/MWMSettings.mm index c33c19748f..d999bf3289 100644 --- a/iphone/Maps/Core/Settings/MWMSettings.mm +++ b/iphone/Maps/Core/Settings/MWMSettings.mm @@ -92,23 +92,6 @@ NSString * const kUDTrackWarningAlertWasShown = @"TrackWarningAlertWasShown"; { if ([self theme] == theme) return; - if (@available(iOS 13.0, *)) { - UIUserInterfaceStyle style; - switch (theme) { - case MWMThemeDay: - case MWMThemeVehicleDay: - style = UIUserInterfaceStyleLight; - break; - case MWMThemeNight: - case MWMThemeVehicleNight: - style = UIUserInterfaceStyleDark; - break; - case MWMThemeAuto: - style = UIUserInterfaceStyleUnspecified; - break; - } - UIApplication.sharedApplication.delegate.window.overrideUserInterfaceStyle = style; - } auto ud = NSUserDefaults.standardUserDefaults; [ud setInteger:theme forKey:kThemeMode]; BOOL const autoOff = theme != MWMThemeAuto; diff --git a/iphone/Maps/Core/Theme/Core/ThemeManager.swift b/iphone/Maps/Core/Theme/Core/ThemeManager.swift index 6466b1a3a6..49713432f5 100644 --- a/iphone/Maps/Core/Theme/Core/ThemeManager.swift +++ b/iphone/Maps/Core/Theme/Core/ThemeManager.swift @@ -10,6 +10,10 @@ final class ThemeManager: NSObject { } private func update(theme: MWMTheme) { + if #available(iOS 13.0, *) { + updateSystemUserInterfaceStyle(theme) + } + let actualTheme: MWMTheme = { theme in let isVehicleRouting = MWMRouter.isRoutingActive() && (MWMRouter.type() == .vehicle) switch theme { @@ -65,6 +69,22 @@ final class ThemeManager: NSObject { instance.update(theme: Settings.theme()) } + @available(iOS 13.0, *) + private func updateSystemUserInterfaceStyle(_ theme: MWMTheme) { + let userInterfaceStyle: UIUserInterfaceStyle = { theme in + switch theme { + case .day: fallthrough + case .vehicleDay: return .light + case .night: fallthrough + case .vehicleNight: return .dark + case .auto: return .unspecified + @unknown default: + fatalError() + } + }(theme) + UIApplication.shared.delegate?.window??.overrideUserInterfaceStyle = userInterfaceStyle + } + @available(iOS, deprecated:13.0) @objc static var autoUpdates: Bool { get {