0

I am wanting to add a TabView with a List, inside another List. The issue is that adding a list with a TabView that has a list inside makes it so that the view is small. Can't figure out if this scenario is possible.

The reason it needs two List is because i am going to add the Tab Selector as a sticky header, which comes built in by using Section inside the List.

@State private var selectedTab = 1
var body: some View {
    List {
        // TAB SELECTOR
        HStack {
            Spacer()
            Button(action: {selectedTab = 1}) {
                Text("First Tab")
            }
            Spacer()
            Button(action: {selectedTab = 2}) {
                Text("Second Tab")
            }
            Spacer()
            Button(action: {selectedTab = 3}) {
                Text("Thrid Tab")
            }
            Spacer()
        }
        
        // TABS
        TabView(selection: $selectedTab) {
            Text("First Tab View")
                .tag(1)

            VStack {
                List {
                    ForEach(0 ..< 20) { index in
                        Text("This is index \(index)")
                    }
                }
            }
            .tag(2)

            Text("Third Tab View")
                .tag(3)
        }
    }
}
abcdefg
  • 97
  • 1
  • 9
  • Is there a reason you are using a list instead of a vstack? ie, do you need the user to be able to edit the list? – yawnobleix Jun 14 '22 at 05:09
  • TabView is really not designed to be part of List - it is expected to be on root level. I don't think you'll make it work properly as in code in question. – Asperi Jun 14 '22 at 05:28

0 Answers0