Hello I have a scroll view and I would like to know when the user swipes to the bottom of it so that I can populate more data into it. The code I have below isn't working quite right. When the sim launches "hello" is printed about 5 times, and when I barely move it "hello" is printed like 10 more times, by the time I get to the bottom of the scroll view, "Hello" was printed like 100 times. How can I fix my code so that Hello is only printed when the bottom is reached.
import SwiftUI
import UIKit
struct FeedView: View {
@State private var scrollViewHeight = CGFloat.infinity
@Namespace private var scrollViewNameSpace
var body: some View {
mainInterFaceView
}
}
extension FeedView{
var mainInterFaceView: some View{
ZStack(){
ScrollView {
LazyVStack {
ForEach(viewModel.tweets) { tweet in
Button {
} label: {
someView()
.background(
GeometryReader { proxy in
Color.clear
.onChange(of: proxy.frame(in: .named(scrollViewNameSpace))) { newFrame in
if newFrame.minY < scrollViewHeight {
print("called")
}
}
}
)
}
}
}
}
.background(
GeometryReader { proxy in
Color.clear
.onChange(of: proxy.size, perform: { newSize in
let _ = print("ScrollView: ", newSize)
scrollViewHeight = newSize.height
})
}
)
.coordinateSpace(name: scrollViewNameSpace)
}
}
}