I use .frame(in: .scrollView) to read a scroll view offset and show/hide a title.

But I observe a jump in the offset if the content extends below the safe area (when there's no View above).

Does adding the title change the frame I read? Should it?

Code: https://gist.github.com/alpennec/388b144ff4ef9a6f07a58181adac29bc

cc @curtclifton @lucabernardi

#SwiftUI #iOSDev

@alpennec Your scroll view touches the top safe area when the header is hidden, and is extending its size to cover it. It stops touching it when you show the header, shrinks, and the offset inside changes.
You can check by adding a consistent padding between top and scroll view.

@auramagi yep, I got the mental model around what’s happening.

But why is the frame not the same when the content inset is updated? The frame in the .scrollview should be the same (assuming scrollview means viewport).

Any workaround in mind if I want to still allow the content to go below the safe area?

@alpennec I'd just rebuild without calculating insets manually.
Hide/unhide with opacity (to keep height consistent) title when the visibility changes.
ScrollView { }.safeAreaInset(edge: .top) { top }

onScrollVisibilityChange on the title inside the scroll to detect when it is off-screen.

@auramagi Thank you, I'll try this approach!