We have a NavigationView embedded within a TabView, like this:
TabView(selection: $tabSelection) {
NavigationView {
When a view gets pushed onto the stack in the NavigationView,
the NavigationBar appears too high, almost under the StatusBar, as shown in the attached picture. If you touch the StatusBar, somehow it alerts the NavigationBar to scoot downward into its correct position.
I discovered a hack where I quickly toggle the StatusBar off, then back on, which accomplishes the same thing. My question, though, is why is this necessary? Why isn't the NavigationBar in the correct place to begin with?
Here's the hack that fixes it:
.onAppear {
withAnimation(.linear(duration: 0.3)) {
appViewModel.hideStatusBar.toggle()
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
withAnimation(.easeInOut(duration: 0.3)) {
appViewModel.hideStatusBar.toggle()
}
}
}