Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CarPlay background maneuver card #4621

Merged
merged 5 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .breakage-allowlist
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 6 additions & 1 deletion Sources/MapboxNavigation/CarPlayManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 23 additions & 0 deletions Sources/MapboxNavigation/CarPlayManagerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}
}

/**
Expand Down
18 changes: 7 additions & 11 deletions Sources/MapboxNavigation/CarPlayNavigationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}