forked from organicmaps/organicmaps
[ios] enable Dark/Light theme switching
Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
parent
2f620c355c
commit
5f04705c2d
6 changed files with 42 additions and 42 deletions
|
@ -22,9 +22,7 @@
|
|||
self.navigationItem.leftBarButtonItem.tintColor = [UIColor whitePrimaryText];
|
||||
self.navigationItem.rightBarButtonItem.tintColor = [UIColor whitePrimaryText];
|
||||
|
||||
if (@available(iOS 13.0, *)) {
|
||||
[MWMThemeManager setDarkModeEnabled: self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark];
|
||||
}
|
||||
[MWMThemeManager invalidate];
|
||||
}
|
||||
|
||||
- (void)navigationController:(UINavigationController *)navigationController
|
||||
|
@ -68,11 +66,8 @@
|
|||
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
|
||||
{
|
||||
[super traitCollectionDidChange: previousTraitCollection];
|
||||
if (@available(iOS 13.0, *)) {
|
||||
if (self.traitCollection.userInterfaceStyle != previousTraitCollection.userInterfaceStyle) {
|
||||
[MWMThemeManager setDarkModeEnabled: self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark];
|
||||
}
|
||||
}
|
||||
// Update the app theme when the device appearance is changing.
|
||||
[MWMThemeManager invalidate];
|
||||
}
|
||||
|
||||
- (BOOL)shouldAutorotate
|
||||
|
|
|
@ -410,9 +410,6 @@ using namespace osm_auth_ios;
|
|||
- (void)application:(UIApplication *)application
|
||||
didConnectCarInterfaceController:(CPInterfaceController *)interfaceController
|
||||
toWindow:(CPWindow *)window API_AVAILABLE(ios(12.0)) {
|
||||
if (@available(iOS 13.0, *)) {
|
||||
window.overrideUserInterfaceStyle = UIUserInterfaceStyleUnspecified;
|
||||
}
|
||||
[self.carplayService setupWithWindow:window interfaceController:interfaceController];
|
||||
[self updateAppearanceFromWindow:self.window toWindow:window isCarplayActivated:YES];
|
||||
}
|
||||
|
|
|
@ -92,6 +92,23 @@ 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;
|
||||
|
|
|
@ -4,19 +4,9 @@ final class ThemeManager: NSObject {
|
|||
|
||||
private static let instance = ThemeManager()
|
||||
private weak var timer: Timer?
|
||||
private var isDarkModeEnabled: Bool = false
|
||||
private static let enableDarkModeBySystem = false
|
||||
|
||||
private override init() {
|
||||
super.init()
|
||||
if #available(iOS 13.0, *) {
|
||||
MapsAppDelegate.theApp().window.overrideUserInterfaceStyle = .light
|
||||
}
|
||||
}
|
||||
|
||||
@objc static func setDarkModeEnabled(_ val: Bool) {
|
||||
instance.isDarkModeEnabled = val
|
||||
instance.update(theme: Settings.theme())
|
||||
}
|
||||
|
||||
private func update(theme: MWMTheme) {
|
||||
|
@ -28,7 +18,8 @@ final class ThemeManager: NSObject {
|
|||
case .night: fallthrough
|
||||
case .vehicleNight: return isVehicleRouting ? .vehicleNight : .night
|
||||
case .auto:
|
||||
if #available(iOS 13.0, *), ThemeManager.enableDarkModeBySystem {
|
||||
if #available(iOS 13.0, *) {
|
||||
let isDarkModeEnabled = UIScreen.main.traitCollection.userInterfaceStyle == .dark
|
||||
guard isVehicleRouting else { return isDarkModeEnabled ? .night : .day }
|
||||
return isDarkModeEnabled ? .vehicleNight : .vehicleDay
|
||||
} else {
|
||||
|
|
|
@ -162,23 +162,7 @@ using namespace power_management;
|
|||
[self.compassCalibrationCell configWithDelegate:self
|
||||
title:L(@"pref_calibration_title")
|
||||
isOn:[MWMSettings compassCalibrationEnabled]];
|
||||
}
|
||||
|
||||
- (void)show3dBuildingsAlert:(UITapGestureRecognizer *)recognizer {
|
||||
UIAlertController *alert =
|
||||
[UIAlertController alertControllerWithTitle:L(@"pref_map_3d_buildings_title")
|
||||
message:L(@"pref_map_3d_buildings_disabled_summary")
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
|
||||
UIAlertAction *okButton = [UIAlertAction actionWithTitle:@"OK"
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:nil];
|
||||
[alert addAction:okButton];
|
||||
|
||||
[self presentViewController:alert animated:YES completion:nil];
|
||||
}
|
||||
|
||||
- (void)configNavigationSection {
|
||||
NSString *nightMode = nil;
|
||||
switch ([MWMSettings theme]) {
|
||||
case MWMThemeVehicleDay:
|
||||
|
@ -196,7 +180,23 @@ using namespace power_management;
|
|||
break;
|
||||
}
|
||||
[self.nightModeCell configWithTitle:L(@"pref_map_style_title") info:nightMode];
|
||||
}
|
||||
|
||||
- (void)show3dBuildingsAlert:(UITapGestureRecognizer *)recognizer {
|
||||
UIAlertController *alert =
|
||||
[UIAlertController alertControllerWithTitle:L(@"pref_map_3d_buildings_title")
|
||||
message:L(@"pref_map_3d_buildings_disabled_summary")
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
|
||||
UIAlertAction *okButton = [UIAlertAction actionWithTitle:@"OK"
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:nil];
|
||||
[alert addAction:okButton];
|
||||
|
||||
[self presentViewController:alert animated:YES completion:nil];
|
||||
}
|
||||
|
||||
- (void)configNavigationSection {
|
||||
bool _ = true, on = true;
|
||||
auto &f = GetFramework();
|
||||
f.Load3dMode(on, _);
|
||||
|
|
|
@ -401,10 +401,6 @@
|
|||
<outlet property="title" destination="Xqo-QZ-3fd" id="W1h-0a-CQ2"/>
|
||||
</connections>
|
||||
</tableViewCell>
|
||||
</cells>
|
||||
</tableViewSection>
|
||||
<tableViewSection headerTitle="НАВИГАЦИЯ" id="E4E-hs-9xW">
|
||||
<cells>
|
||||
<tableViewCell contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="SettingsTableViewLinkCell" id="QNt-XC-xma" customClass="SettingsTableViewLinkCell" customModule="Organic_Maps" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="578" width="414" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
|
@ -440,6 +436,10 @@
|
|||
<outlet property="title" destination="q7P-cj-3tZ" id="3sG-Xy-G0r"/>
|
||||
</connections>
|
||||
</tableViewCell>
|
||||
</cells>
|
||||
</tableViewSection>
|
||||
<tableViewSection headerTitle="НАВИГАЦИЯ" id="E4E-hs-9xW">
|
||||
<cells>
|
||||
<tableViewCell contentMode="scaleToFill" selectionStyle="none" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="SettingsTableViewSwitchCell" id="X5R-fv-yd7" customClass="SettingsTableViewSwitchCell" customModule="Organic_Maps" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="622" width="414" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
|
|
Loading…
Add table
Reference in a new issue