I am facing an issue with the TabView implementation and I don’t know if I am using it wrong or there is an issue within SwiftUI. I wrote a small sample to reproduce it:
import SwiftUI
struct PlayContentView: View {
var body: some View {
TabView {
ContentView()
}
.background(Color.green)
.edgesIgnoringSafeArea(.top)
.tabViewStyle(.page(indexDisplayMode: .never))
}
}
struct ContentView: View {
var body: some View {
NavigationStack {
VStack(spacing: 0) {
VStack(spacing: 0) {
ZStack {
VStack(spacing: 0) {
Text("Title")
Text("Text")
}
}
.frame(maxWidth: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/, maxHeight: 80, alignment: .bottom)
.padding(.top, 12)
.background(Color.yellow)
Divider()
.overlay(Color.black)
}
ScrollView([.vertical, .horizontal], showsIndicators: false) {
VStack {
}
.frame(width: 200, height: 300)
.frame(maxWidth: .infinity)
.background(Color.gray)
}
.background(Color.blue)
}
.toolbar {
ToolbarItem(placement: .status) {
Text("press me")
}
}
}
}
}
#Preview {
PlayContentView()
}
The result looks like this:
As you can see the gray box is not centered vertically, it has more space on the top as on the bottom. When I change the TabView to a ZStack then the space seems correct, so I think the issue lies within the TabView. I also changed the tabViewStyle to displayMode .always and then I can see that a small dot appears inside the bottom bar. So I think the TabView has not the correct height. When I disable the toolbar, then I can also see that the blue background goes to the bottom and then I also can see that gray box is centered. I guess that the TabView does not respect the toolbar correctly. Did anyone else had this issue before?