johnpatrickmorgan / NavigationBackport

Backported SwiftUI navigation APIs introduced in WWDC22
MIT License
865 stars 53 forks source link

Views stack up and doesn't pop when user leaves view #57

Open GioPalusa opened 1 week ago

GioPalusa commented 1 week ago

Something has happened quite recently, when I updated the package our app started behaving weirdly.

When I append a view to a path it navigates there, and I can go back correctly to the view that I was adding. BUT the next time I append a view to the stack, the stack hasn't been popped and I now get first the view I'm currently at, and then also the view that I previously dismissed.

I tried setting a fixed package version to 0.9.3 and then the problem disappeared. So something has happened after that release.

pop-behavior

The setup we have is that each tab gets their own @State private var pathName: NBNavigationPath = .init() on the main view of the app, that handles each tabs stacks, so the app only has three NBNavigationPath in the app, but multiple views append to them via an environment key

import SwiftUI
import NavigationBackport

struct NBNavigationEnvironmentKey: EnvironmentKey {
    static var defaultValue: Binding<NBNavigationPath> = .constant(.init())
}

extension EnvironmentValues {
    var navigationPath: Binding<NBNavigationPath> {
        get { self[NBNavigationEnvironmentKey.self] }
        set { self[NBNavigationEnvironmentKey.self] = newValue }
    }
}
zjinhu commented 6 days ago

I've noticed the same issue

johnpatrickmorgan commented 3 days ago

Thanks for raising this @GioPalusa. There's some additional info that might help to pin down the issue, if you're able to provide it please:

If you're able to help with any of those, it would be really useful. Thanks!