Reputation: 327
I have a view with a toolbar at the bottom that I am navigating to using a NavigationLink
. But when the view appears, the toolbar is shown a little too low. After half a second or so it then suddenly jumps into place. It only happens the first time after the app is started. If I go back to the first view and start the navigation again it is shown in the correct place immediately.
Here are the files to reproduce it:
ContentView:
struct ContentView: View {
var body: some View {
NavigationView {
NavigationLink {
ToolbarView()
} label: {
Text("Hello, world!")
}
}
}
}
ToolbarView:
struct ToolbarView: View {
var body: some View {
ScrollView {
VStack {
Text("Text1")
Text("Text2")
}
}
.toolbar {
ToolbarItemGroup(placement: .bottomBar) {
Spacer()
Button {
} label: {
Image(systemName: "trash")
}
}
}
}
}
Is this a SwiftUI bug?
Here are pictures before and after the jump. Check the trash at the bottom. If the toolbar has a color it is of course even more obvious.
Upvotes: 5
Views: 1314
Reputation: 120002
navigationView
:.navigationViewStyle(.stack)
navigationLink
:ToolbarItemGroup(placement: .bottomBar) { Spacer() }
The completed code would be:
struct ContentView: View {
var body: some View {
NavigationView {
NavigationLink {
ToolbarView()
} label: {
Text("Hello, world!")
}
.toolbar {
ToolbarItemGroup(placement: .bottomBar) { Spacer() } // <- prevents main page jumpings
}
}
.navigationViewStyle(.stack) // <- prevents detail page jumping
}
}
Don't worry about the RTL layout
Upvotes: 3