I have a large data set of elements in cache that I need to show, to implement the infinite pagination I thought to do it like this:
@State var historyPagination: Int = 10
ForEach(Array(myLocalArrayData.enumerated()), id: \.element) { index, data in
if(index < historyPagination) {
MyView(data: data)
}
}
// I have this because there is something weird going on that when I reach the bottom it adds to the count, even though the data hasn't changed
let dataCount: Int = myLocalArrayData.count
LazyVStack {
if (dataCount > historyPagination) {
ProgressView()
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.historyPagination += 10
}
}
}
}
The problem I'm having is that when it gets to the bottom part the spining animation doesn't go away and if I scroll a little bit up and then down I can see when I print the values that historyPagination keeps being added +10. It also seems to re-render the foreach (once I reach the "bottom")
What am I doing wrong and is there a better way of doing it?
Thanks
EDIT:
This glitch seems to only happen after certain amount of data, for example I tested it with 40 items and works fine, but if I have 200 items it seems bugged. Is there something like with Text("") in a view that you can't have more than x amount (I don't remember how many, 5, 10?) without putting it in a Group.