Skip to content

Commit

Permalink
First pass at the overall behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthetechie committed Oct 31, 2024
1 parent 649a68c commit 4053e51
Show file tree
Hide file tree
Showing 16 changed files with 157 additions and 53 deletions.
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))
}
}
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!
camera = navigationCamera
},
onTapExit: onTapExit,
currentRoadNameView: currentRoadNameView
)
Expand All @@ -117,6 +123,8 @@ public struct DynamicallyOrientingNavigationView: View, CustomizableNavigatingIn
topTrailing?()
} midLeading: {
midLeading?()
} bottomLeading: {
bottomLeading?()
} 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?
Button(action: action) {
Image(systemName: isMuted ? "speaker.slash.fill" : "speaker.2.fill")
.resizable()
Expand Down
Loading

0 comments on commit 4053e51

Please sign in to comment.