forked from organicmaps/organicmaps
[ios] fix the initial 'userInterfaceStyle' theme
Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
parent
765f6feb12
commit
bb68a66ffa
2 changed files with 20 additions and 17 deletions
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue