Can SwiftUI ScrollView Infinite scroll ?

Hi, can scrollview in SwiftUI infinite scroll? like repeating the items when user scroll left and right.

It's working when scroll from left to right by appending items to scrollview. but from right to left,
insert new items to the beginning for scrollview it will not work.
Technically it can, using ForEach method calling in data from a server or algorithm (or whatever your data source is). Just create a cell view to handle the data and present to user.

Code Block
import swiftUI
struct contentView: View {
@State var infiniteDataSource: DataSourceType
var body: some View {
ScrollView {
ForEach(infiniteDataSource) { data in
cellView(data: data)
}
}
}
struct cellView: View {
let data : DataSourceType //from top of content view
var body : some View {
Text("\(data.textStuff)")
// include whatever other content you want to show, configure this view to your liking
}
}



For the sake of time I didn't configure the data model because I'm guessing you've done that already, but this would be an efficient way of infinite scroll in swiftUI using ForEach in data source.

I hope that works,
roroCoder
Can SwiftUI ScrollView Infinite scroll ?
 
 
Q