I am trying to make an infinite scroll calling the different pages of an api, my problem is that the function onAppear
is called before the view is displayed, then it is called to reload when the screen opens and not when you scroll to the bottom, I do not know if it is a problem of my Xcode or what, even with this simple code it happens to me:
struct ContentView: View {
var body: some View {
ScrollView {
VStack {
ForEach(1...120, id: \.self) { index in
Text("Item \(index)")
.onAppear {
if index == 120 {
print("End reached")
}
}
}
}
}
}
}
I have tried to make a paginated view with many tutorials on the internet, not only with examples on StackOverflow and as far as I can see this is how it should be done but it doesn't work for me.