There is an issue with the NavigationStack
in WatchOS 10 when used with TabView
: the navigation back from a top bar NavigationLink
destination can stay two or three times on the destination when trying to come back to the navigation root.
Here are the conditions for the issue to occur:
TabView
insideNavigationStack
ToolbarItem
associated with a tab from theTabView
--not the wholeTabView
ToolbarItem
placed at.topBarLeading
or.topBarTrailing
Notes:
- Wrapping the tab with a
NavigationStack
insideTabView
fails to run - Placing the
ToolbarItem
at.bottomBar
works as expected - Second level
NavigationLink
from the destination also works as expected
Is there a way to fix? Or is it a WatchOS 10 issue. Thank you!
Code to replicate the issue:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationStack {
TabView {
Text("Tab 1")
.toolbar {
ToolbarItem(placement: .topBarLeading) {
NavigationLink() {
Text("Destination")
} label: {
Image(systemName: "hand.tap")
}
}
}
Text("Tab 2")
}
.tabViewStyle(.verticalPage)
}
}
}
Run the app, tap the hand icon, and then tap the caret (or swipe right) to come back to the main screen. (It may require a second take to experience the issue.)