diff --git a/.breakage-allowlist b/.breakage-allowlist index a3dd32ca5a..fa36589284 100644 --- a/.breakage-allowlist +++ b/.breakage-allowlist @@ -4,3 +4,5 @@ Func CarPlayManagerDelegate.carPlayManager(_:waypointCircleLayerWithIdentifier:s Func CarPlayManagerDelegate.carPlayManager(_:waypointSymbolLayerWithIdentifier:sourceIdentifier:) has been added as a protocol requirement Func CarPlayNavigationViewControllerDelegate.carPlayNavigationViewController(_:waypointCircleLayerWithIdentifier:sourceIdentifier:) has been added as a protocol requirement Func CarPlayNavigationViewControllerDelegate.carPlayNavigationViewController(_:waypointSymbolLayerWithIdentifier:sourceIdentifier:) has been added as a protocol requirement +Func CarPlayNavigationViewControllerDelegate.carPlayNavigationViewController(_:guidanceBackgroundColorFor:) has been added as a protocol requirement +Func CarPlayManagerDelegate.carPlayNavigationViewController(_:guidanceBackgroundColorFor:) has been added as a protocol requirement \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index c6c62a0d6e..b4e59fa600 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Packaging +* Add ability to configure `CPMapTemplate.guidanceBackgroundColor` via delegate method https://github.com/mapbox/mapbox-navigation-ios/pull/4620#pullrequestreview-1974123920 * MapboxNavigation now requires [MapboxMaps v10.16.5](https://github.com/mapbox/mapbox-maps-ios/releases/tag/v10.16.5). ([#4605](https://github.com/mapbox/mapbox-navigation-ios/pull/4605)) * MapboxCoreNavigation now requires [MapboxDirections v2.12.0](https://github.com/mapbox/mapbox-directions-swift/releases/tag/v2.12.0). ([#4605](https://github.com/mapbox/mapbox-navigation-ios/pull/4605)) * MapboxCoreNavigation now requires [MapboxNavigationNative v202._x_](https://github.com/mapbox/mapbox-navigation-native-ios/releases/tag/202.0.0). ([#4605](https://github.com/mapbox/mapbox-navigation-ios/pull/4605)) diff --git a/Sources/MapboxNavigation/CarPlayManager.swift b/Sources/MapboxNavigation/CarPlayManager.swift index d854689153..4b523642dc 100644 --- a/Sources/MapboxNavigation/CarPlayManager.swift +++ b/Sources/MapboxNavigation/CarPlayManager.swift @@ -1243,7 +1243,12 @@ extension CarPlayManager: CarPlayNavigationViewControllerDelegate { // MARK: CarPlayMapViewControllerDelegate Methods extension CarPlayManager: CarPlayMapViewControllerDelegate { - + + public func carPlayNavigationViewController(_ carPlayNavigationViewController: CarPlayNavigationViewController, + guidanceBackgroundColorFor style: UIUserInterfaceStyle) -> UIColor? { + delegate?.carPlayNavigationViewController(self, guidanceBackgroundColorFor: style) + } + public func carPlayMapViewController(_ carPlayMapViewController: CarPlayMapViewController, didAdd finalDestinationAnnotation: PointAnnotation, pointAnnotationManager: PointAnnotationManager) { diff --git a/Sources/MapboxNavigation/CarPlayManagerDelegate.swift b/Sources/MapboxNavigation/CarPlayManagerDelegate.swift index 3e90baa8dd..263a5dfd4c 100644 --- a/Sources/MapboxNavigation/CarPlayManagerDelegate.swift +++ b/Sources/MapboxNavigation/CarPlayManagerDelegate.swift @@ -532,6 +532,17 @@ public protocol CarPlayManagerDelegate: AnyObject, UnimplementedLogging, CarPlay shouldUpdateNotificationFor maneuver: CPManeuver, with travelEstimates: CPTravelEstimates, in mapTemplate: CPMapTemplate) -> Bool + + /** + Asks the receiver to adjust the default color of the main instruction background color for a specific user interface style. + According to `CPMapTemplate.guidanceBackgroundColor` Navigation SDK can't guarantee that a custom color returned in this function will be actually applied, it's up to CarPlay. + + - parameter carPlayManager: The `CarPlayManager` object. + - parameter style: A default `UIUserInterfaceStyle` generated by the system. + - returns: A `UIColor` which will be used to update `CPMapTemplate.guidanceBackgroundColor` + */ + func carPlayNavigationViewController(_ carPlayManager: CarPlayManager, + guidanceBackgroundColorFor style: UIUserInterfaceStyle) -> UIColor? } public extension CarPlayManagerDelegate { @@ -863,6 +874,7 @@ public extension CarPlayManagerDelegate { func carPlayManager(_ carPlayManager: CarPlayManager, shouldShowNotificationFor maneuver: CPManeuver, in mapTemplate: CPMapTemplate) -> Bool { + logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug) return false } @@ -872,6 +884,7 @@ public extension CarPlayManagerDelegate { func carPlayManager(_ carPlayManager: CarPlayManager, shouldShowNotificationFor navigationAlert: CPNavigationAlert, in mapTemplate: CPMapTemplate) -> Bool { + logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug) return false } @@ -882,8 +895,18 @@ public extension CarPlayManagerDelegate { shouldUpdateNotificationFor maneuver: CPManeuver, with travelEstimates: CPTravelEstimates, in mapTemplate: CPMapTemplate) -> Bool { + logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug) return false } + + /** + `UnimplementedLogging` prints a warning to standard output the first time this method is called. + */ + func carPlayNavigationViewController(_ carPlayManager: CarPlayManager, + guidanceBackgroundColorFor style: UIUserInterfaceStyle) -> UIColor? { + logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug) + return nil + } } /** diff --git a/Sources/MapboxNavigation/CarPlayNavigationViewController.swift b/Sources/MapboxNavigation/CarPlayNavigationViewController.swift index 2963bc520d..83ad10112e 100644 --- a/Sources/MapboxNavigation/CarPlayNavigationViewController.swift +++ b/Sources/MapboxNavigation/CarPlayNavigationViewController.swift @@ -288,13 +288,15 @@ open class CarPlayNavigationViewController: UIViewController, BuildingHighlighti currentUserInterfaceStyle = .dark } } - + + let backgroundColor = delegate?.carPlayNavigationViewController(self, guidanceBackgroundColorFor: currentUserInterfaceStyle) + switch currentUserInterfaceStyle { case .dark: - mapTemplate.guidanceBackgroundColor = .black + mapTemplate.guidanceBackgroundColor = backgroundColor ?? .black mapTemplate.tripEstimateStyle = .dark default: - mapTemplate.guidanceBackgroundColor = .white + mapTemplate.guidanceBackgroundColor = backgroundColor ?? .white mapTemplate.tripEstimateStyle = .light } } @@ -916,14 +918,8 @@ open class CarPlayNavigationViewController: UIViewController, BuildingHighlighti text += "\n\(secondaryText)" } primaryManeuver.instructionVariants = [text] - - // Add maneuver arrow - if #available(iOS 13.0, *) { - primaryManeuver.symbolImage = visualInstruction.primaryInstruction.maneuverImage(side: visualInstruction.drivingSide, - type: styleManager?.currentStyleType) - } else { - primaryManeuver.symbolSet = visualInstruction.primaryInstruction.maneuverImageSet(side: visualInstruction.drivingSide) - } + + primaryManeuver.symbolSet = visualInstruction.primaryInstruction.maneuverImageSet(side: visualInstruction.drivingSide) let junctionImage = guidanceViewManeuverRepresentation(for: visualInstruction, navigationService: navigationService) diff --git a/Sources/MapboxNavigation/CarPlayNavigationViewControllerDelegate.swift b/Sources/MapboxNavigation/CarPlayNavigationViewControllerDelegate.swift index 944125731d..8a49c9a839 100644 --- a/Sources/MapboxNavigation/CarPlayNavigationViewControllerDelegate.swift +++ b/Sources/MapboxNavigation/CarPlayNavigationViewControllerDelegate.swift @@ -123,6 +123,17 @@ public protocol CarPlayNavigationViewControllerDelegate: AnyObject, Unimplemente */ func carPlayNavigationViewController(_ carPlayNavigationViewController: CarPlayNavigationViewController, willAdd layer: Layer) -> Layer? + + /** + Asks the receiver to adjust the default color of the main instruction background color for a specific user interface style. + According to `CPMapTemplate.guidanceBackgroundColor` Navigation SDK can't guarantee that a custom color returned in this function will be actually applied, it's up to CarPlay. + + - parameter carPlayNavigationViewController: The `CarPlayNavigationViewController` object. + - parameter style: A default `UIUserInterfaceStyle` generated by the system. + - returns: A `UIColor` which will be used to update `CPMapTemplate.guidanceBackgroundColor` + */ + func carPlayNavigationViewController(_ carPlayNavigationViewController: CarPlayNavigationViewController, + guidanceBackgroundColorFor style: UIUserInterfaceStyle) -> UIColor? } public extension CarPlayNavigationViewControllerDelegate { @@ -218,4 +229,13 @@ public extension CarPlayNavigationViewControllerDelegate { logUnimplemented(protocolType: CarPlayNavigationViewControllerDelegate.self, level: .debug) return nil } + + /** + `UnimplementedLogging` prints a warning to standard output the first time this method is called. + */ + func carPlayNavigationViewController(_ carPlayNavigationViewController: CarPlayNavigationViewController, + guidanceBackgroundColorFor style: UIUserInterfaceStyle) -> UIColor? { + logUnimplemented(protocolType: CarPlayNavigationViewControllerDelegate.self, level: .debug) + return nil + } }