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

New car play change colors logic #4620

Merged
merged 5 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 CarPlayManagerDelegate.carPlayNavigationViewController(_:guidanceBackgroundColor:) has been added as a protocol requirement
Func CarPlayNavigationViewControllerDelegate.carPlayNavigationViewController(_:guidanceBackgroundColor:) has been added as a protocol requirement
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,
guidanceBackgroundColor style: UIUserInterfaceStyle) -> UIColor? {
delegate?.carPlayNavigationViewController(self, guidanceBackgroundColor: style)
}

public func carPlayMapViewController(_ carPlayMapViewController: CarPlayMapViewController,
didAdd finalDestinationAnnotation: PointAnnotation,
pointAnnotationManager: PointAnnotationManager) {
Expand Down
22 changes: 22 additions & 0 deletions Sources/MapboxNavigation/CarPlayManagerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,16 @@ 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
chizhavko marked this conversation as resolved.
Show resolved Hide resolved
chizhavko marked this conversation as resolved.
Show resolved Hide resolved

- 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,
guidanceBackgroundColor style: UIUserInterfaceStyle) -> UIColor?
chizhavko marked this conversation as resolved.
Show resolved Hide resolved
}

public extension CarPlayManagerDelegate {
Expand Down Expand Up @@ -863,6 +873,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 +883,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 +894,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,
guidanceBackgroundColor style: UIUserInterfaceStyle) -> UIColor? {
logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug)
return nil
chizhavko marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
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, guidanceBackgroundColor: 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for history, some info on why we made this change.

From Apple CarPlay development guide:

If the maneuver has an associated symbol, such as a turn right arrow, provide an image
using symbolSet. [...] You must provide two image variants using CPImageSet—one is used for rendering
the symbol on light backgrounds, the other is used for rendering the symbol on dark backgrounds.

Since we don't know which custom background color a developer might provide, we always use symbolSet to pass both white and dark symbols for maneuvers, CarPlay will choose a better version on its own.


let junctionImage = guidanceViewManeuverRepresentation(for: visualInstruction,
navigationService: navigationService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ 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
chizhavko marked this conversation as resolved.
Show resolved Hide resolved

- 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,
guidanceBackgroundColor style: UIUserInterfaceStyle) -> UIColor?
}

public extension CarPlayNavigationViewControllerDelegate {
Expand Down Expand Up @@ -218,4 +228,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,
guidanceBackgroundColor style: UIUserInterfaceStyle) -> UIColor? {
logUnimplemented(protocolType: CarPlayNavigationViewControllerDelegate.self, level: .debug)
return nil
}
}