The scroll behavior that aligns scroll targets to container-based geometry.
In the following example, every view in the lazy stack is flexible
in both directions and the scroll view settles to container-aligned
boundaries.
ScrollView {
LazyVStack(spacing: 0.0) {
ForEach(items) { item in
FullScreenItem(item)
}
}
}
.scrollTargetBehavior(.paging)
Updates the proposed target that a scrollable view should scroll to.
The system calls this method in two main cases:
- When a scroll gesture ends, it calculates where it would naturally
scroll to using its deceleration rate. The system
provides this calculated value as the target of this method.
- When a scrollable view's size changes, it calculates where it should
be scrolled given the new size and provides this calculates value
as the target of this method.
You can implement this method to override the calculated target
which will have the scrollable view scroll to a different position
than it would otherwise.
Omit the output parameters from the call. The result contains $ret and $out, with target inside $out.