Skip to content

Commit fc9c877

Browse files
Switch to night style when Dark Mode is enabled (#4143)
* Initial implementation. * Transition whenever mode changes and remove print statements. * Add public property to safe guard logic. * Update changelog and remove availability statements. * Set usesNightStyleInDarkMode to false by default. * Make usesNightStyleInDarkMode documentation more clear.
1 parent dca085b commit fc9c877

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* Added the `NavigationViewControllerDelegate.navigationViewController(_:didSelect:)` and `NavigationViewControllerDelegate.navigationViewController(_:didSelect:)` methods that allow selection of the waypoint and continuous alternative. ([#4175](https://github.com/mapbox/mapbox-navigation-ios/pull/4175))
3737
* MapboxMobileEvents dependency is replaced with CoreTelemetry (part of MapboxCommon). ([#4011](https://github.com/mapbox/mapbox-navigation-ios/pull/4011))
3838
* Deprecated `NavigationEventsManager.init(activeNavigationDataSource:passiveNavigationDataSource:accessToken:mobileEventsManager:)` in favour of `NavigationEventsManager.init(activeNavigationDataSource:passiveNavigationDataSource:accessToken:)`. ([#4011](https://github.com/mapbox/mapbox-navigation-ios/pull/4011))
39+
* Added `NavigationViewController.usesNightStyleInDarkMode` property to control whether night style is used in dark mode. ([#4143](https://github.com/mapbox/mapbox-navigation-ios/pull/4143))
3940

4041
## v2.8.1
4142

Sources/MapboxNavigation/NavigationViewController.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,10 @@ open class NavigationViewController: UIViewController, NavigationStatusPresenter
444444
setupNavigationService()
445445
setupVoiceController()
446446
setupNavigationCamera()
447+
448+
if usesNightStyleInDarkMode && self.traitCollection.userInterfaceStyle == .dark {
449+
styleManager.applyStyle(type: .night)
450+
}
447451
}
448452

449453
open override func viewWillAppear(_ animated: Bool) {
@@ -456,6 +460,12 @@ open class NavigationViewController: UIViewController, NavigationStatusPresenter
456460
notifyUserAboutLowVolumeIfNeeded()
457461
}
458462

463+
override open func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
464+
if usesNightStyleInDarkMode {
465+
transitionStyle(to: newCollection)
466+
}
467+
}
468+
459469
func notifyUserAboutLowVolumeIfNeeded() {
460470
guard !(navigationService.locationManager is SimulatedLocationManager) else { return }
461471
guard !NavigationSettings.shared.voiceMuted else { return }
@@ -791,6 +801,11 @@ open class NavigationViewController: UIViewController, NavigationStatusPresenter
791801
*/
792802
public var waypointStyle: WaypointStyle = .annotation
793803

804+
/**
805+
Controls whether night style will be used whenever dark mode is enabled. Defaults to `false`.
806+
*/
807+
public var usesNightStyleInDarkMode: Bool = false
808+
794809
var approachingDestinationThreshold: CLLocationDistance = DefaultApproachingDestinationThresholdDistance
795810
var passedApproachingDestinationThreshold: Bool = false
796811
var currentLeg: RouteLeg?
@@ -820,6 +835,14 @@ open class NavigationViewController: UIViewController, NavigationStatusPresenter
820835
return currentStatusBarStyle
821836
}
822837
}
838+
839+
func transitionStyle(to newCollection: UITraitCollection) {
840+
if newCollection.userInterfaceStyle == .dark {
841+
styleManager.applyStyle(type: .night)
842+
} else {
843+
styleManager.applyStyle(type: .day)
844+
}
845+
}
823846
}
824847

825848
// MARK: - NavigationViewDelegate methods

0 commit comments

Comments
 (0)