diff --git a/apple/DemoApp/Demo/NavigationView.swift b/apple/DemoApp/Demo/NavigationView.swift index 49d84ca0..f23cbc69 100644 --- a/apple/DemoApp/Demo/NavigationView.swift +++ b/apple/DemoApp/Demo/NavigationView.swift @@ -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") } } diff --git a/apple/Sources/FerrostarCore/FerrostarCore.swift b/apple/Sources/FerrostarCore/FerrostarCore.swift index cc146149..acac0f94 100644 --- a/apple/Sources/FerrostarCore/FerrostarCore.swift +++ b/apple/Sources/FerrostarCore/FerrostarCore.swift @@ -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)) + } } } @@ -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) {