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

iOS Route Overview #330

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
30 changes: 30 additions & 0 deletions apple/Sources/FerrostarMapLibreUI/Extensions/NavigationState.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import FerrostarCore
import MapLibre
import MapLibreSwiftUI

extension NavigationState {
var routeOverviewCamera: MapViewCamera? {
guard let firstCoordinate = routeGeometry.first else {
return nil
}

let initial = MLNCoordinateBounds(
sw: firstCoordinate.clLocationCoordinate2D,
ne: firstCoordinate.clLocationCoordinate2D
)
let bounds = routeGeometry.reduce(initial) { acc, coord in
MLNCoordinateBounds(
sw: CLLocationCoordinate2D(latitude: min(acc.sw.latitude, coord.lat), longitude: min(
acc.sw.longitude,
coord.lng
)),
ne: CLLocationCoordinate2D(
latitude: max(acc.ne.latitude, coord.lat),
longitude: max(acc.ne.longitude, coord.lng)
)
)
}

return MapViewCamera.boundingBox(bounds, edgePadding: UIEdgeInsets(top: 20, left: 100, bottom: 20, right: 100))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The padding values are silly because the implementation in the MapLibre SwiftUI DSL seems to be broken.

}
}
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ public struct DynamicallyOrientingNavigationView: View, CustomizableNavigatingIn
public var topCenter: (() -> AnyView)?
public var topTrailing: (() -> AnyView)?
public var midLeading: (() -> AnyView)?
public var bottomLeading: (() -> AnyView)?
public var bottomTrailing: (() -> AnyView)?

let isMuted: Bool
@@ -106,8 +107,13 @@ public struct DynamicallyOrientingNavigationView: View, CustomizableNavigatingIn
showZoom: true,
onZoomIn: { camera.incrementZoom(by: 1) },
onZoomOut: { camera.incrementZoom(by: -1) },
showCentering: !camera.isTrackingUserLocationWithCourse,
onCenter: { camera = navigationCamera },
cameraControlState: camera.isTrackingUserLocationWithCourse ? .showRouteOverview {
if let overviewCamera = navigationState?.routeOverviewCamera {
camera = overviewCamera
}
} : .showRecenter { // TODO: Third case when not navigating!
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TBD the best way to express this logic given the limits of view code; probably in an extension / helper function.

camera = navigationCamera
},
onTapExit: onTapExit,
currentRoadNameView: currentRoadNameView
)
@@ -117,6 +123,8 @@ public struct DynamicallyOrientingNavigationView: View, CustomizableNavigatingIn
topTrailing?()
} midLeading: {
midLeading?()
} bottomLeading: {
bottomLeading?()
Comment on lines +126 to +127
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Undo this change; recenter will stay in lower left corner.

} bottomTrailing: {
bottomTrailing?()
}.complementSafeAreaInsets(parentGeometry: geometry, minimumInsets: minimumSafeAreaInsets)
@@ -131,8 +139,13 @@ public struct DynamicallyOrientingNavigationView: View, CustomizableNavigatingIn
showZoom: true,
onZoomIn: { camera.incrementZoom(by: 1) },
onZoomOut: { camera.incrementZoom(by: -1) },
showCentering: !camera.isTrackingUserLocationWithCourse,
onCenter: { camera = navigationCamera },
cameraControlState: camera.isTrackingUserLocationWithCourse ? .showRouteOverview {
if let overviewCamera = navigationState?.routeOverviewCamera {
camera = overviewCamera
}
} : .showRecenter { // TODO: Third case when not navigating!
camera = navigationCamera
},
onTapExit: onTapExit,
currentRoadNameView: currentRoadNameView
)
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ public struct LandscapeNavigationView: View, CustomizableNavigatingInnerGridView
public var topCenter: (() -> AnyView)?
public var topTrailing: (() -> AnyView)?
public var midLeading: (() -> AnyView)?
public var bottomLeading: (() -> AnyView)?
public var bottomTrailing: (() -> AnyView)?

let isMuted: Bool
@@ -99,8 +100,11 @@ public struct LandscapeNavigationView: View, CustomizableNavigatingInnerGridView
showZoom: true,
onZoomIn: { camera.incrementZoom(by: 1) },
onZoomOut: { camera.incrementZoom(by: -1) },
showCentering: !camera.isTrackingUserLocationWithCourse,
onCenter: { camera = navigationCamera },
cameraControlState: camera.isTrackingUserLocationWithCourse ? CameraControlState.showRecenter {
// TODO:
} : .showRecenter {
camera = navigationCamera
},
onTapExit: onTapExit,
currentRoadNameView: currentRoadNameView
)
@@ -110,6 +114,8 @@ public struct LandscapeNavigationView: View, CustomizableNavigatingInnerGridView
topTrailing?()
} midLeading: {
midLeading?()
} bottomLeading: {
bottomLeading?()
} bottomTrailing: {
bottomTrailing?()
}.complementSafeAreaInsets(parentGeometry: geometry, minimumInsets: minimumSafeAreaInsets)
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ struct LandscapeNavigationOverlayView: View, CustomizableNavigatingInnerGridView
var topCenter: (() -> AnyView)?
var topTrailing: (() -> AnyView)?
var midLeading: (() -> AnyView)?
var bottomLeading: (() -> AnyView)?
var bottomTrailing: (() -> AnyView)?

var speedLimit: Measurement<UnitSpeed>?
@@ -25,8 +26,7 @@ struct LandscapeNavigationOverlayView: View, CustomizableNavigatingInnerGridView
var onZoomIn: () -> Void
var onZoomOut: () -> Void

var showCentering: Bool
var onCenter: () -> Void
var cameraControlState: CameraControlState

var onTapExit: (() -> Void)?
let currentRoadNameView: AnyView?
@@ -46,8 +46,7 @@ struct LandscapeNavigationOverlayView: View, CustomizableNavigatingInnerGridView
showZoom: Bool = false,
onZoomIn: @escaping () -> Void = {},
onZoomOut: @escaping () -> Void = {},
showCentering: Bool = false,
onCenter: @escaping () -> Void = {},
cameraControlState: CameraControlState = .hidden,
onTapExit: (() -> Void)? = nil,
currentRoadNameView: AnyView?
) {
@@ -60,8 +59,7 @@ struct LandscapeNavigationOverlayView: View, CustomizableNavigatingInnerGridView
self.showZoom = showZoom
self.onZoomIn = onZoomIn
self.onZoomOut = onZoomOut
self.showCentering = showCentering
self.onCenter = onCenter
self.cameraControlState = cameraControlState
self.onTapExit = onTapExit
self.currentRoadNameView = currentRoadNameView
}
@@ -117,15 +115,16 @@ struct LandscapeNavigationOverlayView: View, CustomizableNavigatingInnerGridView
showZoom: showZoom,
onZoomIn: onZoomIn,
onZoomOut: onZoomOut,
showCentering: showCentering,
onCenter: onCenter
cameraControlState: cameraControlState
)
.innerGrid {
topCenter?()
} topTrailing: {
topTrailing?()
} midLeading: {
midLeading?()
} bottomLeading: {
bottomLeading?()
} bottomTrailing: {
bottomTrailing?()
}
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ struct PortraitNavigationOverlayView<T: SpokenInstructionObserver & ObservableOb
var topCenter: (() -> AnyView)?
var topTrailing: (() -> AnyView)?
var midLeading: (() -> AnyView)?
var bottomLeading: (() -> AnyView)?
var bottomTrailing: (() -> AnyView)?

var speedLimit: Measurement<UnitSpeed>?
@@ -28,8 +29,7 @@ struct PortraitNavigationOverlayView<T: SpokenInstructionObserver & ObservableOb
var onZoomIn: () -> Void
var onZoomOut: () -> Void

var showCentering: Bool
var onCenter: () -> Void
var cameraControlState: CameraControlState

var onTapExit: (() -> Void)?
let currentRoadNameView: AnyView?
@@ -48,8 +48,7 @@ struct PortraitNavigationOverlayView<T: SpokenInstructionObserver & ObservableOb
showZoom: Bool = false,
onZoomIn: @escaping () -> Void = {},
onZoomOut: @escaping () -> Void = {},
showCentering: Bool = false,
onCenter: @escaping () -> Void = {},
cameraControlState: CameraControlState = .hidden,
onTapExit: (() -> Void)? = nil,
currentRoadNameView: AnyView?
) {
@@ -62,8 +61,7 @@ struct PortraitNavigationOverlayView<T: SpokenInstructionObserver & ObservableOb
self.onMute = onMute
self.onZoomIn = onZoomIn
self.onZoomOut = onZoomOut
self.showCentering = showCentering
self.onCenter = onCenter
self.cameraControlState = cameraControlState
self.onTapExit = onTapExit
self.currentRoadNameView = currentRoadNameView
}
@@ -86,15 +84,16 @@ struct PortraitNavigationOverlayView<T: SpokenInstructionObserver & ObservableOb
showZoom: showZoom,
onZoomIn: onZoomIn,
onZoomOut: onZoomOut,
showCentering: showCentering,
onCenter: onCenter
cameraControlState: cameraControlState
)
.innerGrid {
topCenter?()
} topTrailing: {
topTrailing?()
} midLeading: {
midLeading?()
} bottomLeading: {
bottomLeading?()
} bottomTrailing: {
bottomTrailing?()
}
@@ -103,7 +102,7 @@ struct PortraitNavigationOverlayView<T: SpokenInstructionObserver & ObservableOb
let progress = navigationState?.currentProgress
{
VStack {
if !showCentering {
if case .showRouteOverview = cameraControlState {
currentRoadNameView
}

Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ public struct PortraitNavigationView: View, CustomizableNavigatingInnerGridView,
public var topCenter: (() -> AnyView)?
public var topTrailing: (() -> AnyView)?
public var midLeading: (() -> AnyView)?
public var bottomLeading: (() -> AnyView)?
public var bottomTrailing: (() -> AnyView)?

public var minimumSafeAreaInsets: EdgeInsets
@@ -101,8 +102,11 @@ public struct PortraitNavigationView: View, CustomizableNavigatingInnerGridView,
showZoom: true,
onZoomIn: { camera.incrementZoom(by: 1) },
onZoomOut: { camera.incrementZoom(by: -1) },
showCentering: !camera.isTrackingUserLocationWithCourse,
onCenter: { camera = navigationCamera },
cameraControlState: camera.isTrackingUserLocationWithCourse ? CameraControlState.showRecenter {
// TODO:
} : .showRecenter { // TODO: Third case when not navigating!
camera = navigationCamera
},
onTapExit: onTapExit,
currentRoadNameView: currentRoadNameView
)
@@ -112,6 +116,8 @@ public struct PortraitNavigationView: View, CustomizableNavigatingInnerGridView,
topTrailing?()
} midLeading: {
midLeading?()
} bottomLeading: {
bottomLeading?()
} bottomTrailing: {
bottomTrailing?()
}.complementSafeAreaInsets(parentGeometry: geometry, minimumInsets: minimumSafeAreaInsets)
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ public protocol CustomizableNavigatingInnerGridView where Self: View {
var topCenter: (() -> AnyView)? { get set }
var topTrailing: (() -> AnyView)? { get set }
var midLeading: (() -> AnyView)? { get set }
var bottomLeading: (() -> AnyView)? { get set }
var bottomTrailing: (() -> AnyView)? { get set }
}

@@ -21,12 +22,14 @@ public extension CustomizableNavigatingInnerGridView {
@ViewBuilder topCenter: @escaping () -> some View = { Spacer() },
@ViewBuilder topTrailing: @escaping () -> some View = { Spacer() },
@ViewBuilder midLeading: @escaping () -> some View = { Spacer() },
@ViewBuilder bottomLeading: @escaping () -> some View = { Spacer() },
@ViewBuilder bottomTrailing: @escaping () -> some View = { Spacer() }
) -> Self {
var newSelf = self
newSelf.topCenter = { AnyView(topCenter()) }
newSelf.topTrailing = { AnyView(topTrailing()) }
newSelf.midLeading = { AnyView(midLeading()) }
newSelf.bottomLeading = { AnyView(bottomLeading()) }
newSelf.bottomTrailing = { AnyView(bottomTrailing()) }
return newSelf
}
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ public struct MuteUIButton: View {
}

public var body: some View {
// TODO: Use NavigationUIButton?
Button(action: action) {
Image(systemName: isMuted ? "speaker.slash.fill" : "speaker.2.fill")
.resizable()
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import FerrostarCore
import SwiftUI

/// Determines which camera control is shown in the navigation inner grid view.
public enum CameraControlState {
/// Don't show any camera control.
case hidden

/// Shows the recenter button.
///
/// The action is responsible for resetting the camera
/// to a state that follows the user.
case showRecenter(() -> Void)

/// Shows the route overview button.
///
/// The action is responsible for transitioning the camera to an overview of the route.
case showRouteOverview(() -> Void)
}
Comment on lines +4 to +19
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the first significant design decision. I think that an enum makes the camera control states significantly cleaner to express. We can add more later if necessary, but the common ones are here.


/// When navigation is underway, we use this standardized grid view with pre-defined metadata and interactions.
/// This is the default UI and can be customized to some extent. If you need more customization,
/// use the ``InnerGridView``.
@@ -14,8 +31,7 @@ public struct NavigatingInnerGridView: View, CustomizableNavigatingInnerGridView
let onZoomIn: () -> Void
let onZoomOut: () -> Void

let showCentering: Bool
let onCenter: () -> Void
let cameraControlState: CameraControlState

let showMute: Bool
let isMuted: Bool
@@ -26,6 +42,7 @@ public struct NavigatingInnerGridView: View, CustomizableNavigatingInnerGridView
public var topCenter: (() -> AnyView)?
public var topTrailing: (() -> AnyView)?
public var midLeading: (() -> AnyView)?
public var bottomLeading: (() -> AnyView)?
public var bottomTrailing: (() -> AnyView)?

/// The default navigation inner grid view.
@@ -42,12 +59,7 @@ public struct NavigatingInnerGridView: View, CustomizableNavigatingInnerGridView
/// - showZoom: Whether to show the provided zoom control or not.
/// - onZoomIn: The on zoom in tapped action. This should be used to zoom the user in one increment.
/// - onZoomOut: The on zoom out tapped action. This should be used to zoom the user out one increment.
/// - showCentering: Whether to show the centering control. This is typically determined by the Map's centering
/// state.
/// - onCenter: The action that occurs when the user taps the centering control (to re-center the map on the
/// user).
/// - showMute: Whether to show the provided mute toggle or not.
/// - spokenInstructionObserver: The spoken instruction observer (for driving mute button state).
/// - cameraControlState: Which camera control to show (and its respective action).
public init(
speedLimit: Measurement<UnitSpeed>? = nil,
speedLimitStyle: SpeedLimitView.SignageStyle? = nil,
@@ -57,8 +69,7 @@ public struct NavigatingInnerGridView: View, CustomizableNavigatingInnerGridView
showZoom: Bool = false,
onZoomIn: @escaping () -> Void = {},
onZoomOut: @escaping () -> Void = {},
showCentering: Bool = false,
onCenter: @escaping () -> Void = {}
cameraControlState: CameraControlState = .hidden
) {
self.speedLimit = speedLimit
self.speedLimitStyle = speedLimitStyle
@@ -68,8 +79,7 @@ public struct NavigatingInnerGridView: View, CustomizableNavigatingInnerGridView
self.showZoom = showZoom
self.onZoomIn = onZoomIn
self.onZoomOut = onZoomOut
self.showCentering = showCentering
self.onCenter = onCenter
self.cameraControlState = cameraControlState
}

public var body: some View {
@@ -86,6 +96,29 @@ public struct NavigatingInnerGridView: View, CustomizableNavigatingInnerGridView
},
topCenter: { topCenter?() },
topTrailing: {
// TODO: Extract to a separate view?
switch cameraControlState {
case .hidden:
// Nothing
EmptyView()
case let .showRecenter(onCenter):
NavigationUIButton(action: onCenter) {
Image(systemName: "location.north.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 18, height: 18)
}
.shadow(radius: 8)
case let .showRouteOverview(onRouteOverview):
NavigationUIButton(action: onRouteOverview) {
Image(systemName: "point.bottomleft.forward.to.point.topright.scurvepath")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 18, height: 18)
}
.shadow(radius: 8)
}
Comment on lines +99 to +120
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The important thing to note here is that we have moved the recenter button to be in the top corner. The logic behind that is that we probably only ever care about having one camera button visible at a time in my opinion (differing opinions welcome :D). So the camera button slot will either be a recenter button, a route overview button, or hidden, depending on state driven higher up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed; we will move the recenter button to the bottom left corner to keep with convention.


if showMute {
MuteUIButton(isMuted: isMuted, action: onMute)
.shadow(radius: 8)
@@ -104,19 +137,7 @@ public struct NavigatingInnerGridView: View, CustomizableNavigatingInnerGridView
Spacer()
}
},
bottomLeading: {
if showCentering {
NavigationUIButton(action: onCenter) {
Image(systemName: "location.north.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 18, height: 18)
}
.shadow(radius: 8)
} else {
Spacer()
}
},
bottomLeading: { bottomLeading?() },
bottomCenter: {
// This view does not allow center content to prevent overlaying the puck.
Spacer()
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
isMuted: true,
onMute: {},
showZoom: true,
showCentering: true
cameraControlState: .showRecenter {}
)
.padding()
}
@@ -26,7 +26,7 @@
isMuted: false,
onMute: {},
showZoom: true,
showCentering: true
cameraControlState: .showRecenter {}
)
.environment(\.locale, .init(identifier: "fr_FR"))
.padding()
@@ -40,10 +40,36 @@
showMute: false,
onMute: {},
showZoom: true,
showCentering: true
cameraControlState: .showRecenter {}
)
.environment(\.locale, .init(identifier: "fr_FR"))
.padding()
}
}

func test_CameraControlsHidden() {
assertView {
NavigatingInnerGridView(
isMuted: true,
showMute: true,
onMute: {},
showZoom: true,
cameraControlState: .hidden
)
.padding()
}
}

func test_RouteOverviewCameraControl() {
assertView {

Check failure on line 64 in apple/Tests/FerrostarSwiftUITests/Views/NavigatingInnerGridViewTests.swift

GitHub Actions / test (FerrostarCore-Package, platform=iOS Simulator,name=iPhone 15,OS=17.2)

test_RouteOverviewCameraControl, failed - Snapshot does not match reference.
NavigatingInnerGridView(
isMuted: true,
showMute: true,
onMute: {},
showZoom: true,
cameraControlState: .showRouteOverview {}
)
.padding()
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Unchanged files with check annotations Beta

extension FerrostarCore: LocationManagingDelegate {
@MainActor
public func locationManager(_: LocationProviding, didUpdateLocations locations: [UserLocation]) {

Check warning on line 378 in apple/Sources/FerrostarCore/FerrostarCore.swift

GitHub Actions / test (FerrostarCore-Package, platform=iOS Simulator,name=iPhone 15,OS=17.2)

main actor-isolated instance method 'locationManager(_:didUpdateLocations:)' cannot be used to satisfy nonisolated protocol requirement; this is an error in the Swift 6 language mode

Check warning on line 378 in apple/Sources/FerrostarCore/FerrostarCore.swift

GitHub Actions / test (FerrostarCore-Package, platform=iOS Simulator,name=iPhone 15,OS=17.2)

main actor-isolated instance method 'locationManager(_:didUpdateLocations:)' cannot be used to satisfy nonisolated protocol requirement; this is an error in the Swift 6 language mode
guard let location = locations.last,
let state = state?.tripState,
let newState = navigationController?.updateUserLocation(location: location, state: state)
}
queue.async {
self.synthesizer.speak(utterance)

Check warning on line 41 in apple/Sources/FerrostarCore/Speech/SpokenInstructionObserver.swift

GitHub Actions / test (FerrostarCore-Package, platform=iOS Simulator,name=iPhone 15,OS=17.2)

capture of 'utterance' with non-sendable type 'AVSpeechUtterance' in a `@Sendable` closure; this is an error in the Swift 6 language mode
}
}
await fulfillment(of: [routeDeviationCallbackExp], timeout: 1.0)
await fulfillment(of: [loadedAltRoutesExp], timeout: 1.0)
XCTAssert(core.state?.isCalculatingNewRoute == false, "Expected to no longer be calculating a new route")

Check failure on line 398 in apple/Tests/FerrostarCoreTests/FerrostarCoreTests.swift

GitHub Actions / test (FerrostarCore-Package, platform=iOS Simulator,name=iPhone 15,OS=17.2)

testCustomRouteDeviationHandler, XCTAssertTrue failed - Expected to no longer be calculating a new route
}
// TODO: Various location services failure modes (need special mocks to simulate these)