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
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
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
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand All @@ -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)
Expand All @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand All @@ -110,6 +114,8 @@ public struct LandscapeNavigationView: View, CustomizableNavigatingInnerGridView
topTrailing?()
} midLeading: {
midLeading?()
} bottomLeading: {
bottomLeading?()
} bottomTrailing: {
bottomTrailing?()
}.complementSafeAreaInsets(parentGeometry: geometry, minimumInsets: minimumSafeAreaInsets)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>?
Expand All @@ -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?
Expand All @@ -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?
) {
Expand All @@ -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
}
Expand Down Expand Up @@ -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?()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>?
Expand All @@ -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?
Expand All @@ -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?
) {
Expand All @@ -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
}
Expand All @@ -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?()
}
Expand All @@ -103,7 +102,7 @@ struct PortraitNavigationOverlayView<T: SpokenInstructionObserver & ObservableOb
let progress = navigationState?.currentProgress
{
VStack {
if !showCentering {
if case .showRouteOverview = cameraControlState {
currentRoadNameView
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand All @@ -112,6 +116,8 @@ public struct PortraitNavigationView: View, CustomizableNavigatingInnerGridView,
topTrailing?()
} midLeading: {
midLeading?()
} bottomLeading: {
bottomLeading?()
} bottomTrailing: {
bottomTrailing?()
}.complementSafeAreaInsets(parentGeometry: geometry, minimumInsets: minimumSafeAreaInsets)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public struct MuteUIButton: View {
}

public var body: some View {
// TODO: Use NavigationUIButton?
ianthetechie marked this conversation as resolved.
Show resolved Hide resolved
Button(action: action) {
Image(systemName: isMuted ? "speaker.slash.fill" : "speaker.2.fill")
.resizable()
Expand Down
Loading
Loading