Hey guys! Created SwiftUI HList. Where you can put thousand of elements inside a horizontal list but only visible elements are are loaded. You can preview how does it work in action using swift playground.
struct ClippedContentView: View {
var body: some View {
HList(numberOfItems: 10000, itemWidth: 80) { index in
Text("\(index)")
}
.frame(width: 200, height: 60)
.border(Color.black, width: 2)
.clipped()
}
}
above code would generate list view (black frame) with clipped contend. It means it doesn't draw stuff beyond frame.
Bellow example, shows you how the visible content is generated and how many views is loaded. Plus you can see how it does reuse elements.
struct ContentView: View {
var body: some View {
HList(numberOfItems: 10000, itemWidth: 80) { index in
Text("\(index)")
}
.frame(width: 200, height: 60)
.border(Color.black, width: 2)
}
}
Let me know what you think! I hope it will solve you performance issues while loading thousand of elements in horizontal lists.
Thanks for this solution mate! It's a really big problem and needed. I can recommend a fix for gestures. If you change .gesture with .simultaneousGesture, users can use tap gesture or other gestures too for items.