Declaration
compose().scrollBounceBehavior(
behavior: SwiftUI.ScrollBounceBehavior,
options?: {
axes?: SwiftUI.AxisSet;
}
)nonisolated func scrollBounceBehavior(
_ behavior: ScrollBounceBehavior,
axes: Axis.Set = [.vertical]
) -> some ViewParameters
behavior*SwiftUI.ScrollBounceBehaviorThe bounce behavior to apply to any scrollable views within the configured view. Use one of the
ScrollBounceBehaviorvalues.options.axesSwiftUI.AxisSetThe set of axes to apply
behaviorto. The default isAxis.vertical.
Return value
A view that's configured with the specified scroll bounce behavior.
Discussion
Use this modifier to indicate whether scrollable views bounce when
people scroll to the end of the view's content, taking into account the
relative sizes of the view and its content. For example, the following
ScrollView only enables bounce behavior if its content is large
enough to require scrolling:
ScrollView {
Text("Small")
Text("Content")
}
.scrollBounceBehavior(.basedOnSize)The modifier passes the scroll bounce mode through the Environment,
which means that the mode affects any scrollable views in the modified
view hierarchy. Provide an axis to the modifier to constrain the kinds
of scrollable views that the mode affects. For example, all the scroll
views in the following example can access the mode value, but
only the two nested scroll views are affected, because only they use
horizontal scrolling:
ScrollView { // Defaults to vertical scrolling.
ScrollView(.horizontal) {
ShelfContent()
}
ScrollView(.horizontal) {
ShelfContent()
}
}
.scrollBounceBehavior(.basedOnSize, axes: .horizontal)You can use this modifier to configure any kind of scrollable view,
including ScrollView, List, Table, and TextEditor:
List {
Text("Hello")
Text("World")
}
.scrollBounceBehavior(.basedOnSize)See also
More in Layout.
- alignmentGuideSets the view's vertical alignment.
- aspectRatioConstrains this view's dimensions to the specified aspect ratio.
- containerCornerOffsetAdjusts the view's layout to avoid the container view's corner insets for the specified edges.
- containerRelativeFramePositions this view within an invisible frame with a size relative to the nearest container.
- controlSizeSets the size for controls within this view.
- defaultScrollAnchorAssociates an anchor to control which part of the scroll view's content should be rendered by default.
- dynamicTypeSizeSets the Dynamic Type size within the view to the given value.
- fixedSizeFixes this view at its ideal size.
- flipsForRightToLeftLayoutDirectionSets whether this view mirrors its contents horizontally when the layout direction is right-to-left.
- framePositions this view within an invisible frame.
- geometryGroupIsolates the geometry (e.g. position and size) of the view from its parent view.
- gridCellAnchorSpecifies a custom alignment anchor for a view that acts as a grid cell.