onScrollVisibilityChange for Lists

I cannot make the new onScrollVisibilityChange work within Lists. Is this an expected limitation or am I doing something wrong? Please see the sample code below.

Thank you!

struct TestView: View {

@State var isTitleVisible: Bool = true
    
    var body: some View {
        List {
            Section {
                Text("Title")
            }
            .onScrollVisibilityChange { isVisible in
                self.isTitleVisible = isVisible
            }
                     
            Section {
                ForEach((0..<100), id: \.self) { i in
                    Text(i.formatted())
                }
                /// Changes the background color from green to red once the title is no more visible
                .listRowBackground(isTitleVisible ? Color.green : .red)
            }
        }
    }
}
Answered by DTS Engineer in 803777022

@tomas.bek You should add the modifier on the List instead. You can also use onScrollGeometryChange(for:of:action:) if you need to do custom calculations based off the scroll geometry changes.

Accepted Answer

@tomas.bek You should add the modifier on the List instead. You can also use onScrollGeometryChange(for:of:action:) if you need to do custom calculations based off the scroll geometry changes.

@tomas.bek The code above can work well

struct TestView: View {

    @State var isTitleVisible: Bool = true
    
    var body: some View {
        List {
            Section {
                Group {
                    Text("Title")
                }
                .onAppear {
                    isTitleVisible = true
                }
                .onDisappear {
                    isTitleVisible = false
                }
            }
            
            Section {
                ForEach((0..<100), id: \.self) { i in
                    Text(i.formatted())
                }
                /// Changes the background color from green to red once the title is no more visible
                .listRowBackground(isTitleVisible ? Color.green : .red)
            }
        }
    }
}

But I still do not understand why onScrollVisibilityChange cannot work inside a List.

onScrollVisibilityChange for Lists
 
 
Q