Skip to content

Commit

Permalink
Revisions to demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
Archdoog committed Jan 15, 2024
1 parent e572879 commit 7173028
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion apple/DemoApp/Demo/NavigationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ struct NavigationView: View {
stepAdvance: .relativeLineStringDistance(minimumHorizontalAccuracy: 32, automaticAdvanceDistance: 10))

if let simulated = locationManager as? SimulatedLocationProvider {
try simulated.start(route: route)
try simulated.startSimulating(route: route)
print("DemoApp: starting route simulation")
}
}
Expand Down
56 changes: 28 additions & 28 deletions apple/Sources/FerrostarCore/FerrostarCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,31 +143,33 @@ public protocol FerrostarCoreDelegate: AnyObject {
///
/// You should call this rather than setting properties directly
private func update(newState: UniFFI.TripState, location: CLLocation) {
tripState = newState

switch (newState) {
case .navigating(snappedUserLocation: let snappedLocation, remainingSteps: let remainingSteps, distanceToNextManeuver: let distanceToNextManeuver):
observableState?.snappedLocation = CLLocation(userLocation: snappedLocation)
observableState?.courseOverGround = location.course
observableState?.currentStep = remainingSteps.first
// TODO: This isn't great; the core should probably just tell us which instruction to display
observableState?.visualInstructions = remainingSteps.first?.visualInstructions.last(where: { instruction in
distanceToNextManeuver <= instruction.triggerDistanceBeforeManeuver
})
observableState?.distanceToNextManeuver = distanceToNextManeuver
// TODO
// observableState?.spokenInstruction = currentStep.spokenInstruction.last(where: { instruction in
// currentStepRemainingDistance <= instruction.triggerDistanceBeforeManeuver
// })
case .complete:
// TODO: "You have arrived"?
observableState?.visualInstructions = nil
observableState?.snappedLocation = location // We arrived; no more snapping needed
observableState?.courseOverGround = location.course
observableState?.spokenInstruction = nil
}
DispatchQueue.main.async {
self.tripState = newState

switch (newState) {
case .navigating(snappedUserLocation: let snappedLocation, remainingSteps: let remainingSteps, distanceToNextManeuver: let distanceToNextManeuver):
self.observableState?.snappedLocation = CLLocation(userLocation: snappedLocation)
self.observableState?.courseOverGround = location.course
self.observableState?.currentStep = remainingSteps.first
// TODO: This isn't great; the core should probably just tell us which instruction to display
self.observableState?.visualInstructions = remainingSteps.first?.visualInstructions.last(where: { instruction in
distanceToNextManeuver <= instruction.triggerDistanceBeforeManeuver
})
self.observableState?.distanceToNextManeuver = distanceToNextManeuver
// TODO
// observableState?.spokenInstruction = currentStep.spokenInstruction.last(where: { instruction in
// currentStepRemainingDistance <= instruction.triggerDistanceBeforeManeuver
// })
case .complete:
// TODO: "You have arrived"?
self.observableState?.visualInstructions = nil
self.observableState?.snappedLocation = location // We arrived; no more snapping needed
self.observableState?.courseOverGround = location.course
self.observableState?.spokenInstruction = nil
}

delegate?.core(self, didUpdateNavigationState: TripState(newState))
self.delegate?.core(self, didUpdateNavigationState: TripState(newState))
}
}
}

Expand All @@ -178,10 +180,8 @@ extension FerrostarCore: LocationManagingDelegate {
let newState = navigationController?.updateUserLocation(location: location.userLocation, state: state) else {
return
}

DispatchQueue.main.async {
self.update(newState: newState, location: location)
}

update(newState: newState, location: location)
}

public func locationManager(_ manager: LocationProviding, didUpdateHeading newHeading: CLHeading) {
Expand Down

0 comments on commit 7173028

Please sign in to comment.