I am facing very serious problem in my project. The scenario is something like this.
A SwiftUi screen has NavigationBar -> Sticky Header -> Horizontal TabBarItems -> TabView
then each TabView
has it’s own View
using ListView
or ScrollView
as required
Problem is ListView
or ScrollView
is not auto growing as per content even its not visible until not giving the height to TabView or ContentView
and i can’t calculate the content height and give it to the page because content ate too dynamic and big.
Sample code is as follow –
struct ContentView: View {
var body: some View {
VStack {
VStack{
Text("Sticky Header")
}
ScrollView {
HeaderView()
CustomTabView()
.frame(height: 100) <--- I don't want to give this height anymore.
}
}
.padding()
}
}
struct HeaderView: View {
var body: some View {
Image("W")
.resizable()
.frame(minWidth: 0, maxWidth: .infinity)
.frame(height: 200)
}
}
struct CustomTabView: View {
var body: some View {
TabView(content: {
FirstTavView()
FirstTavView()
FirstTavView()
})
.tabViewStyle(.page(indexDisplayMode: .never))
}
}
struct FirstTavView: View {
var body: some View {
List(0..<100) { index in
Text("Index number is --- > (index)")
}
}
}
2
Answers
Your solution is just using LazyVStack and StickeyHeader by pinnedViews. Layout inside will grow up with your content instead.
And control your parent by set frame for tabview.
I’m new in this technology but I think I have the solution.