Declaration
compose().scrollDisabled(disabled: boolean)nonisolated func scrollDisabled(_ disabled: Bool) -> some ViewParameters
disabled*booleanA Boolean that indicates whether scrolling is disabled.
Discussion
Use this modifier to control whether a ScrollView can scroll:
@State private var isScrollDisabled = false
var body: some View {
ScrollView {
VStack {
Toggle("Disable", isOn: $isScrollDisabled)
MyContent()
}
}
.scrollDisabled(isScrollDisabled)
}SwiftUI passes the disabled property through the environment, which means you can use this modifier to disable scrolling for all scroll views within a view hierarchy. In the following example, the modifier affects both scroll views:
ScrollView {
ForEach(rows) { row in
ScrollView(.horizontal) {
RowContent(row)
}
}
}
.scrollDisabled(true)You can also use this modifier to disable scrolling for other kinds
of scrollable views, like a List or a TextEditor.
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.
- scrollClipDisabledSets whether a scroll view clips its content to its bounds.
- 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.