In SwiftUI, where are the control events, i.e. scrollViewDidScroll to detect the bottom of list data

后端 未结 5 1775
南笙
南笙 2020-12-09 18:57

In SwiftUI, does anyone know where are the control events such as scrollViewDidScroll to detect when a user reaches the bottom of a list causing an event to retrieve additio

5条回答
  •  無奈伤痛
    2020-12-09 19:34

    You can to check that the latest element is appeared inside onAppear.

    struct ContentView: View {
        @State var items = Array(1...30)
    
        var body: some View {
            List {
                ForEach(items, id: \.self) { item in
                    Text("\(item)")
                    .onAppear {
                        if let last == self.items.last {
                            print("last item")
                            self.items += last+1...last+30
                        }
                    }
                }
            }
        }
    }
    

提交回复
热议问题