Declaration
compose().scrollClipDisabled(disabled?: boolean)nonisolated func scrollClipDisabled(
_ disabled: Bool = true
) -> some ViewParameters
disabledbooleanA Boolean value that specifies whether to disable scroll view clipping.
Return value
A view that disables or enables scroll view clipping.
Discussion
By default, a scroll view clips its content to its bounds, but you can disable that behavior by using this modifier. For example, if the views inside the scroll view have shadows that extend beyond the bounds of the scroll view, you can use this modifier to avoid clipping the shadows:
struct ContentView: View {
var disabled: Bool
let colors: [Color] = [.red, .green, .blue, .mint, .teal]
var body: some View {
ScrollView(.horizontal) {
HStack(spacing: 20) {
ForEach(colors, id: \.self) { color in
Rectangle()
.frame(width: 100, height: 100)
.foregroundStyle(color)
.shadow(color: .primary, radius: 20)
}
}
}
.scrollClipDisabled(disabled)
}
}The scroll view in the above example clips when the
content view's disabled input is false, as it does
if you omit the modifier, but not when the input is true:
@TabNavigator { @Tab("True") {
}
@Tab("False") {
}}
While you might want to avoid clipping parts of views that exceed the
bounds of the scroll view, like the shadows in the above example, you
typically still want the scroll view to clip at some point.
Create custom clipping by using the View.clipShape(_:style:)
modifier to add a different clip shape. The following code disables
the default clipping and then adds rectangular clipping that exceeds
the bounds of the scroll view by the default padding amount:
ScrollView(.horizontal) {
// ...
}
.scrollClipDisabled()
.padding()
.clipShape(Rectangle())See also
More in Input and interaction.
- allowsHitTestingConfigures whether this view participates in hit test operations.
- allowsWindowActivationEventsConfigures whether gestures in this view hierarchy can handle events that activate the containing window.
- buttonRepeatBehaviorSets whether buttons in this view should repeatedly trigger their actions on prolonged interactions.
- disabledAdds a condition that controls whether someone can interact with this view.
- handlesExternalEventsSpecifies the external events that the view's scene handles if the scene is already open.
- helpAdds help text to a view using a localized string resource that you provide.
- invalidatableContentMark the receiver as their content might be invalidated.
- keyboardShortcutAssigns a keyboard shortcut to the modified control.
- scrollDisabledDisables or enables scrolling in scrollable views.
- scrollDismissesKeyboardConfigures the behavior in which scrollable content interacts with the software keyboard.
- sensoryFeedbackPlays the specified feedback when the provided trigger value changes.
- userActivityAdvertises a user activity type.