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

[cherry-pick] Add support for carplay to hide waypoints from route line #4608

Merged
merged 3 commits into from
Mar 11, 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
6 changes: 5 additions & 1 deletion .breakage-allowlist
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
Constructor NavigationEventsManager.init(activeNavigationDataSource:passiveNavigationDataSource:accessToken:mobileEventsManager:) has been removed
Import MapboxMobileEvents has been removed
Import MapboxMobileEvents has been removed
Func CarPlayManagerDelegate.carPlayManager(_:waypointCircleLayerWithIdentifier:sourceIdentifier:) has been added as a protocol requirement
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@

* Fixed an issue where starting navigation while connected to CarPlay but not having window active resulted in CarPlay view to be stuck at preview screen. ([#4477](https://github.com/mapbox/mapbox-navigation-ios/pull/4477))
* Fixed an issue where maneuver arrow was not changing color following day/night style automatic toggling. ([#4482](https://github.com/mapbox/mapbox-navigation-ios/pull/4482))
* Added the ability to configure waypoints via `CarPlayManagerDelegate` object. ([#4482](https://github.com/mapbox/mapbox-navigation-ios/pull/4606))

### Routing
* Fixed an issue where `NavigationSettings.tileStoreConfiguration.navigatorLocation.tileStoreURL` was used as a base url for route refresh requests instead of `NavigationSettings.directions.credentials.host`. ([#4483](https://github.com/mapbox/mapbox-navigation-ios/pull/4483))
Expand Down
11 changes: 11 additions & 0 deletions Sources/MapboxNavigation/CarPlayManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,17 @@ extension CarPlayManager: CPMapTemplateDelegate {
// MARK: CarPlayNavigationViewControllerDelegate Methods

extension CarPlayManager: CarPlayNavigationViewControllerDelegate {
public func carPlayNavigationViewController(_ carPlayNavigationViewController: CarPlayNavigationViewController,
waypointCircleLayerWithIdentifier identifier: String,
sourceIdentifier: String) -> MapboxMaps.CircleLayer? {
delegate?.carPlayManager(self, waypointCircleLayerWithIdentifier: identifier, sourceIdentifier: sourceIdentifier)
}

public func carPlayNavigationViewController(_ carPlayNavigationViewController: CarPlayNavigationViewController,
waypointSymbolLayerWithIdentifier identifier: String,
sourceIdentifier: String) -> SymbolLayer? {
delegate?.carPlayManager(self, waypointSymbolLayerWithIdentifier: identifier, sourceIdentifier: sourceIdentifier)
}

public func carPlayNavigationViewControllerWillDismiss(_ carPlayNavigationViewController: CarPlayNavigationViewController,
byCanceling canceled: Bool) {
Expand Down
46 changes: 46 additions & 0 deletions Sources/MapboxNavigation/CarPlayManagerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,32 @@ public protocol CarPlayManagerDelegate: AnyObject, UnimplementedLogging, CarPlay
to parentViewController: UIViewController,
pointAnnotationManager: PointAnnotationManager)

/**
Asks the receiver to return a `SymbolLayer` for waypoint symbols, given an identifier and source.
This method is invoked any time waypoints are added or shown.

- parameter carPlayManager: The `CarPlayManager` object.
- parameter identifier: The `SymbolLayer` identifier.
- parameter sourceIdentifier: Identifier of the source, which contains the waypoint data that this method would style.
- returns: A `SymbolLayer` that the map applies to all waypoint symbols.
*/
func carPlayManager(_ carPlayManager: CarPlayManager,
waypointSymbolLayerWithIdentifier identifier: String,
sourceIdentifier: String) -> SymbolLayer?

/**
Asks the receiver to return a `CircleLayer` for waypoints, given an identifier and source.
This method is invoked any time waypoints are added or shown.

- parameter carPlayManager: The `CarPlayManager` object.
- parameter identifier: The `CircleLayer` identifier.
- parameter sourceIdentifier: Identifier of the source, which contains the waypoint data that this method would style.
- returns: A `CircleLayer` that the map applies to all waypoints.
*/
func carPlayManager(_ carPlayManager: CarPlayManager,
waypointCircleLayerWithIdentifier identifier: String,
sourceIdentifier: String) -> CircleLayer?

// MARK: Transitioning Between Templates

/**
Expand Down Expand Up @@ -692,6 +718,26 @@ public extension CarPlayManagerDelegate {
logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug)
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func carPlayManager(_ carPlayManager: CarPlayManager,
waypointSymbolLayerWithIdentifier identifier: String,
sourceIdentifier: String) -> SymbolLayer? {
logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug)
return nil
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func carPlayManager(_ carPlayManager: CarPlayManager,
waypointCircleLayerWithIdentifier identifier: String,
sourceIdentifier: String) -> CircleLayer? {
logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug)
return nil
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
Expand Down
16 changes: 16 additions & 0 deletions Sources/MapboxNavigation/CarPlayNavigationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,22 @@ extension CarPlayNavigationViewController: NavigationServiceDelegate {

extension CarPlayNavigationViewController: NavigationMapViewDelegate {

public func navigationMapView(_ navigationMapView: NavigationMapView,
waypointCircleLayerWithIdentifier identifier: String,
sourceIdentifier: String) -> CircleLayer? {
delegate?.carPlayNavigationViewController(self,
waypointCircleLayerWithIdentifier: identifier,
sourceIdentifier: sourceIdentifier)
}

public func navigationMapView(_ navigationMapView: NavigationMapView,
waypointSymbolLayerWithIdentifier identifier: String,
sourceIdentifier: String) -> SymbolLayer? {
delegate?.carPlayNavigationViewController(self,
waypointSymbolLayerWithIdentifier: identifier,
sourceIdentifier: sourceIdentifier)
}

public func navigationMapView(_ navigationMapView: NavigationMapView,
didAdd finalDestinationAnnotation: PointAnnotation,
pointAnnotationManager: PointAnnotationManager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,33 @@ public protocol CarPlayNavigationViewControllerDelegate: AnyObject, Unimplemente
func carPlayNavigationViewController(_ carPlayNavigationViewController: CarPlayNavigationViewController,
routeLineLayerWithIdentifier identifier: String,
sourceIdentifier: String) -> LineLayer?


/**
Asks the receiver to return a `SymbolLayer` for waypoint symbols, given an identifier and source.
This method is invoked any time waypoints are added or shown.

- parameter carPlayNavigationViewController: The `CarPlayNavigationViewController` object.
- parameter identifier: The `SymbolLayer` identifier.
- parameter sourceIdentifier: Identifier of the source, which contains the waypoint data that this method would style.
- returns: A `SymbolLayer` that the map applies to all waypoint symbols.
*/
func carPlayNavigationViewController(_ carPlayNavigationViewController: CarPlayNavigationViewController,
waypointSymbolLayerWithIdentifier identifier: String,
sourceIdentifier: String) -> SymbolLayer?

/**
Asks the receiver to return a `CircleLayer` for waypoints, given an identifier and source.
This method is invoked any time waypoints are added or shown.

- parameter carPlayNavigationViewController: The `CarPlayNavigationViewController` object.
- parameter identifier: The `CircleLayer` identifier.
- parameter sourceIdentifier: Identifier of the source, which contains the waypoint data that this method would style.
- returns: A `CircleLayer` that the map applies to all waypoints.
*/
func carPlayNavigationViewController(_ carPlayNavigationViewController: CarPlayNavigationViewController,
waypointCircleLayerWithIdentifier identifier: String,
sourceIdentifier: String) -> CircleLayer?

/**
Asks the receiver to return a `LineLayer` for the casing layer that surrounds route line,
given a layer identifier and a source identifier.
Expand Down Expand Up @@ -133,7 +159,27 @@ public extension CarPlayNavigationViewControllerDelegate {
pointAnnotationManager: PointAnnotationManager) {
logUnimplemented(protocolType: CarPlayNavigationViewControllerDelegate.self, level: .debug)
}


/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func carPlayNavigationViewController(_ carPlayNavigationViewController: CarPlayNavigationViewController,
waypointSymbolLayerWithIdentifier identifier: String,
sourceIdentifier: String) -> SymbolLayer? {
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,
waypointCircleLayerWithIdentifier identifier: String,
sourceIdentifier: String) -> CircleLayer? {
logUnimplemented(protocolType: CarPlayNavigationViewControllerDelegate.self, level: .debug)
return nil
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
Expand Down
19 changes: 18 additions & 1 deletion Tests/MapboxNavigationTests/CarPlayManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import CwlPreconditionTesting
@testable import TestHelper
@testable import MapboxNavigation
@testable import MapboxCoreNavigation
import MapboxMaps

class CarPlayManagerTests: TestCase {
var carPlayManager: CarPlayManager!
Expand Down Expand Up @@ -60,7 +61,23 @@ class CarPlayManagerTests: TestCase {
simulateCarPlayDisconnection(carPlayManager)
XCTAssertTrue(eventsManagerSpy.sendCarPlayDisconnectEventCalled)
}


func testReturnSourceCircleLayer() {
let id = "test"
let layer = CircleLayer(id: id)
delegate.circleLayer = layer
let expectedLayerId = delegate.carPlayManager(carPlayManager, waypointCircleLayerWithIdentifier: id, sourceIdentifier: id)?.id
XCTAssertEqual(layer.id, expectedLayerId)
}

func testReturnSourceSymbolLayer() {
let id = "test"
let layer = SymbolLayer(id: id)
delegate.symbolLayer = layer
let expectedLayerId = delegate.carPlayManager(carPlayManager, waypointSymbolLayerWithIdentifier: id, sourceIdentifier: id)?.id
XCTAssertEqual(layer.id, expectedLayerId)
}

func testWindowAndIntefaceControllerAreSetUpWithSearchWhenConnected() {
let searchDelegate = TestCarPlaySearchControllerDelegate()
let searchButtonHandler: ((CPBarButton) -> Void) = { [weak self] _ in
Expand Down
16 changes: 16 additions & 0 deletions Tests/MapboxNavigationTests/CarPlayUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import CarPlay
@testable import MapboxNavigation
@testable import MapboxCoreNavigation
@testable import MapboxDirections
import MapboxMaps
import CarPlayTestHelper
import TestHelper


func simulateCarPlayConnection(_ carPlayManager: CarPlayManager) {
let interfaceController = FakeCPInterfaceController(context: #function)
let window = CPWindow()
Expand Down Expand Up @@ -92,6 +94,20 @@ class CarPlayManagerDelegateSpy: CarPlayManagerDelegate {
var returnedLeadingBarButtons: [CPBarButton]?
var returnedTrailingBarButtons: [CPBarButton]?
var returnedMapButtons: [CPMapButton]?
var symbolLayer: SymbolLayer?
var circleLayer: CircleLayer?

func carPlayManager(_ carPlayManager: CarPlayManager,
waypointCircleLayerWithIdentifier identifier: String,
sourceIdentifier: String) -> CircleLayer? {
circleLayer
}

func carPlayManager(_ carPlayManager: CarPlayManager,
waypointSymbolLayerWithIdentifier identifier: String,
sourceIdentifier: String) -> SymbolLayer? {
symbolLayer
}

func carPlayManager(_ carPlayManager: CarPlayManager,
willPreview trip: CPTrip) -> CPTrip {
Expand Down