"Unwrapping" Scrolling

For a number of complex views in my app, I need to embed scrollable objects (like List, Form or TextEditor) in a ScrollView. To do that, I need to apply a limit to the height of the embedded object.

What I would like to do is set that limit to the actual height of the content being displayed in the List, Form, TextEditor, etc. (Note that this height calculation should be dynamic, so that content changes are properly displayed.

I attempted the following:

    @State listHeight: CGFloat = .zero

    List {
        ... content here
    }
    .onScrollGeometryChange(for: CGFloat.self, of: { geometry in
        return geometry.contentSize.height
    }, action: { oldValue, newValue in
        if oldValue != newValue {
            listHeight = newValue
        }
    })
    .frame(height: listHeight)
    .scrollDisabled(true)

This does not work because geometry.contentSize.height is always 0. So it is apparent that .onScrollGeometryChangedoes not interact with the internal scrolling mechanism of List. (Note, however, that.scrollDisabled` does work.)

Does anyone have a suggestion on how I might get this to work?

Which os builds are you testing on? If onScrollGeometryChange isn’t providing you the scroll geometry changes please file a feedback report and post the FB number here for my reference.

Bug Reporting: How and Why? has tips on creating your bug report.

Just a quick reply -- I'll put together a sample project for the feedback report and have it for you tomorrow (Wednesday).

I am using Xcode 16.4 running on macOS 15.7 working with a project where the Minimum Deployment Target is iOS 18.0 (I changed it from 17.0 to try using the .onScrollGeometryChange API).

I see the problem (i.e., listHeight = 0 on both #Preview and on the Simulator (running the iPad mini (6th generation) 18.1 simulation.

More tomorrow -- hopefully with a sample project and an FB#.

I created a sample project demonstrating that .onScrollGeometryChange returns no data when applied to List, Form, or TextEdtior.

FB19922481

"Unwrapping" Scrolling
 
 
Q