Skip to content

Commit

Permalink
Fix carplay background maneuver card
Browse files Browse the repository at this point in the history
  • Loading branch information
chizhavko committed Apr 2, 2024
1 parent f565d8f commit 677ceff
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 12 deletions.
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
- 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?
}

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
}
}

/**
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)

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
- 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
}
}

0 comments on commit 677ceff

Please sign in to comment.