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

Speed limit view remains after navigation ends #325

Open
ianthetechie opened this issue Oct 30, 2024 · 0 comments
Open

Speed limit view remains after navigation ends #325

ianthetechie opened this issue Oct 30, 2024 · 0 comments
Labels
bug Something isn't working iOS

Comments

@ianthetechie
Copy link
Contributor

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
@ianthetechie ianthetechie added bug Something isn't working iOS labels Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working iOS
Projects
None yet
Development

No branches or pull requests

1 participant