SwiftUI view in list, detect when fully visible?

Viewed 20

I have this simple view:

struct ContentView: View {
    
    let items = [1,2,3,4,5,6,7,8,9,10,11,12,13,14]
    
    var body: some View {
        List {
            ForEach(items, id:\.self) { i in
                Text("item \(i)")
                    .frame(height:200)
                    .onAppear {
                        print("A: \(i)")
                    }
                    .onDisappear {
                        print("D: \(i)")
                    }
            }
        }
    }
    
}

I would like to know when the cell's rect is fully visible. As is, onAppear triggers as soon as the cell comes in the view as I scroll. However, I'd like to get a hook that tells me when the cell is fully visible.

How could I do that in SwiftUI?

0 Answers
Related