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()
}
}
`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. 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.
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, the counter is working .
when I begin the left-edge senter code here
crolling, 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.
Thanks