stadiamaps / ferrostar

A FOSS navigation SDK built from the ground up for the future
https://stadiamaps.github.io/ferrostar/
Other
180 stars 25 forks source link

Speed limit view remains after navigation ends #325

Open ianthetechie opened 3 weeks ago

ianthetechie commented 3 weeks ago

Expected behavior: when resetting navigation state to nil, the navigation-specific elements of the UI should disappear. The speed limit view currently remains. It appears to be something broken with the plumbing for getting these updates through.

I have confirmed via NSLog debugging that the speed limit state update is indeed processed through the Combine pipeline in AnnotationPublisher (under the if let mapSpeedLimit block). However, it does not seem to come back around to SwiftUI, since the navigationSpeedLimit modifier is not re-invoked with the new value.

diff --git a/Package.swift b/Package.swift
index 96e0af1..fe80627 100644
--- a/Package.swift
+++ b/Package.swift
@@ -5,7 +5,7 @@ import PackageDescription

 let binaryTarget: Target
 let maplibreSwiftUIDSLPackage: Package.Dependency
-let useLocalFramework = false
+let useLocalFramework = true
 let useLocalMapLibreSwiftUIDSL = false

 if useLocalFramework {
diff --git a/apple/Sources/FerrostarCore/Annotations/AnnotationPublisher.swift b/apple/Sources/FerrostarCore/Annotations/AnnotationPublisher.swift
index 6e03871..e36c1ed 100644
--- a/apple/Sources/FerrostarCore/Annotations/AnnotationPublisher.swift
+++ b/apple/Sources/FerrostarCore/Annotations/AnnotationPublisher.swift
@@ -50,15 +50,26 @@ public class AnnotationPublisher<Annotation: Decodable>: ObservableObject, Annot
         // automatically when the Published instance deinitializes. Because of this, the assign(to:) operator
         // doesn’t return an AnyCancellable that you’re responsible for like assign(to:on:) does."

+        // FIXME: Something wrong here?
         navigationState
             .map(decodeAnnotation)
             .receive(on: DispatchQueue.main)
-            .assign(to: &$currentValue)
+//            .assign(to: &$currentValue)
+            .sink { [weak self] annotation in
+                NSLog("3 Annotation sink: \(annotation)")
+                self?.currentValue = annotation
+            }
+            .store(in: &cancellables)

         if let mapSpeedLimit {
             $currentValue
                 .map(mapSpeedLimit)
-                .assign(to: &$speedLimit)
+//                .assign(to: &$speedLimit)
+                .sink { [weak self] speedLimit in
+                    NSLog("1 Speed Limit sink: \(speedLimit)")
+                    self?.speedLimit = speedLimit
+                }
+                .store(in: &cancellables)
         }
     }

diff --git a/apple/Sources/FerrostarCore/Annotations/Models/ValhallaOSRMAnnotation.swift b/apple/Sources/FerrostarCore/Annotations/Models/ValhallaOSRMAnnotation.swift
index 79ab5b3..7a0bc8f 100644
--- a/apple/Sources/FerrostarCore/Annotations/Models/ValhallaOSRMAnnotation.swift
+++ b/apple/Sources/FerrostarCore/Annotations/Models/ValhallaOSRMAnnotation.swift
@@ -31,11 +31,12 @@ public extension AnnotationPublisher {
     /// - Parameter onError: An optional error closure (runs when a `DecoderError` occurs)
     /// - Returns: The annotation publisher.
     static func valhallaExtendedOSRM(
-        onError: @escaping (Error) -> Void = { _ in }
+        onError: @escaping (Error) -> Void = { e in NSLog("Error parsing annotation: \(e)") }
     ) -> AnnotationPublisher<ValhallaExtendedOSRMAnnotation> {
         AnnotationPublisher<ValhallaExtendedOSRMAnnotation>(
             mapSpeedLimit: {
-                $0?.speedLimit?.measurementValue
+                NSLog("0 Speed limit: \($0?.speedLimit?.measurementValue)")
+                return $0?.speedLimit?.measurementValue
             },
             onError: onError
         )
diff --git a/apple/Sources/FerrostarSwiftUI/ViewModifiers/SpeedLimitViewModifier.swift b/apple/Sources/FerrostarSwiftUI/ViewModifiers/SpeedLimitViewModifier.swift
index c5a0211..fa7ed86 100644
--- a/apple/Sources/FerrostarSwiftUI/ViewModifiers/SpeedLimitViewModifier.swift
+++ b/apple/Sources/FerrostarSwiftUI/ViewModifiers/SpeedLimitViewModifier.swift
@@ -20,6 +20,7 @@ public extension SpeedLimitViewHost {
         speedLimitStyle: SpeedLimitView.SignageStyle
     ) -> Self {
         var newSelf = self
+        NSLog("2 New Speed limit: \(speedLimit), \(speedLimitStyle)")
         newSelf.speedLimit = speedLimit
         newSelf.speedLimitStyle = speedLimitStyle
         return newSelf