navigationBar root shows navigation Bar destination when left-edge swipe

why my destination view navigationBarTitle and NavigationBarItems(trailing) show on the root navigationBar when i do left-edge swipe in swiftui , I swipe the screen to the right, and see the root view, but my destination view items are now showing on my root navigationBar ?
if I do it fast, it goes to the root view without any problem, when I do it slow the problem occurs, oh and everything pass, the default back button, the title, and the trailing item when is there.

Thanks


Answered by mlipiz in 621413022
Code Block language
import SwiftUI
struct ContentView: View {
    var body: some View {
        NavigationView {
            NavigationLink(destination: SecondCounter()){
                Text("Show Second Counter View")}
                .navigationBarTitle("RootView")
        }
    }
    struct SecondCounter : View {
        @State var timer: Timer? = nil
        @State private var secCounter = 0
      
        var body: some View {
            Text("")
                .navigationBarTitle("Second Counter View" ,displayMode:.inline)
                .navigationBarItems(trailing:Text("\(secCounter)"))
                .onAppear {
                    self.secondCounter()
                }
            .onDisappear {
                self.timer?.invalidate()
                self.timer = nil
            }
        }
        func secondCounter () {
            timer =  Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { _ in
                self.secCounter += 1
            })
        }
    }
    struct ContentView_Previews: PreviewProvider {
        static var previews: some View {
            ContentView()
        }
    }
}


this is the whole program where I get the errors
the navigationBarTitle string var I was using was not private , I make it private, and now the navigationBarTitle don't pass to the root view, when I am not using the timer. Now im fighting with a countodown timer I have as a navigationBarItems trailing, and that one is getting fuzzy, and all the bar appears on the root view.
thanks
I don't know how to edit the question again, sorry. The private var resolution was a false alarm, the counter is the problem, when I do the left-edge,i see more of the root vies, the counter immediately stops, and if I stays on the destination view then timer becomes blurry, and if I tap on < Back, the root view appears with the navigationBar of the destination view. If I go all the way to the right, the root view appears fine, without the destination view bar.
it only happens when the timer is working .
I don't know how to edit the question again, sorry again.
when I begin the left-edge scrolling, that I see the root view, the navigationBarItems(trailing), stop to upgrade the counter, but the timer continue working, (I print my var onBarRighTitle, and continue upgrading), when I stop the scrolling and stay in the destination view, the text receive again the output, and becomes blurry.
Accepted Answer
Code Block language
import SwiftUI
struct ContentView: View {
    var body: some View {
        NavigationView {
            NavigationLink(destination: SecondCounter()){
                Text("Show Second Counter View")}
                .navigationBarTitle("RootView")
        }
    }
    struct SecondCounter : View {
        @State var timer: Timer? = nil
        @State private var secCounter = 0
      
        var body: some View {
            Text("")
                .navigationBarTitle("Second Counter View" ,displayMode:.inline)
                .navigationBarItems(trailing:Text("\(secCounter)"))
                .onAppear {
                    self.secondCounter()
                }
            .onDisappear {
                self.timer?.invalidate()
                self.timer = nil
            }
        }
        func secondCounter () {
            timer =  Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { _ in
                self.secCounter += 1
            })
        }
    }
    struct ContentView_Previews: PreviewProvider {
        static var previews: some View {
            ContentView()
        }
    }
}


this is the whole program where I get the errors
Resolved !!!!
I use .toolbar IOS 14, and now the problem is not happening. I'm very happy
Your total silence did not help with this question, but I hope somebody, somewhere learned something from it.
navigationBar root shows navigation Bar destination when left-edge swipe
 
 
Q