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()
Loading

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)