I have a TabView within a ScrollView. Even though I give a fixed height to Color.orange of 500, the height of the TabView does not expand as it should.
The problem only appears when TabView is rendered within ScrollView.
struct TabViewProblems: View {
var body: some View {
ScrollView {
TabView(selection: .constant(0), content: {
Color.orange.height(500)
})
.tabViewStyle(.page(indexDisplayMode: .always))
}
}
}
This problem does NOT exist when TabView or ScrollView are on there own.
struct TabViewProblems: View {
var body: some View {
ScrollView {
// TabView(selection: .constant(0), content: {
Color.orange.height(500)
// })
// .tabViewStyle(.page(indexDisplayMode: .always))
}
}
}
struct TabViewProblems: View {
var body: some View {
// ScrollView {
TabView(selection: .constant(0), content: {
Color.orange.height(500)
})
.tabViewStyle(.page(indexDisplayMode: .always))
// }
}
}
How can this be fixed? I don't want to give TabView a fixed height, I want it to assume the height of it's contents.
The accepted answer for this similar question says that "when you set an infinite height on object inside the scrollview it takes only the space that the content really needs." Here, the content explicitly needs a height of 500, but that still is not being respected.