In SwiftUI, I have a layout shift bug. Here’s a code sample that reproduces the issue.
struct ContentView: View {
var body: some View {
TabView {
Tab("Home", systemImage: "house") {
NavigationStack {
ScrollView(.vertical) {
NavigationLink("Tap Me") {
VStack(alignment:.center) {
Text("Content")
Spacer()
}
.navigationTitle("Content")
.toolbar(.hidden, for: .tabBar)
}
}
.navigationTitle("Home")
}
}
}
}
}
On iPad, the tab bar appears at the top of the screen. When you tap the navigation link, the navigation title “Content” and the text view “Content” appear on the screen initially appear with empty space at the top of the screen where the tab bar was, and then, a second later, the whole layout shifts up as the tab bar disappears (without an animation).
This doesn’t happen on iPhone. There, the tab bar overlays the ScrollView, so hiding/showing it doesn’t shift the content.
How do I fix this layout shift issue on iPad?