Lian
Lian

Reputation: 157

TabView - PageTabView()

I am working on TabView with a bunch of items and they are kind of laggy. I couldn't find LazyTabView on the internet, so is there an alternative way to load smoothly. Thank you. My code is:

struct ContentView: View {
    var body: some View {
        TabView {
            ForEach(1..<1001, id: \.self) { i in
                Text("Row \(i)")
            }
        }
        .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
    }
}

struct ContentView_Previews: PreviewProvider {
    static_var previews: some View {
        ContentView()
    }
}

Upvotes: 1

Views: 559

Answers (1)

you could try something different, like this approach using a ScrollView and LazyHGrid:

struct ContentView: View {
    var body: some View {
        GeometryReader { geom in
            ScrollView(.horizontal) {
                LazyHGrid(rows: [GridItem(.flexible())]) {
                    ForEach(1..<1001, id: \.self) { i in
                        Text("Row \(i)").frame(width: geom.size.width)
                    }
                }
            }
        }
    }
}

Upvotes: 2

Related Questions