Declaration
compose().disabled(disabled: boolean)nonisolated func disabled(_ disabled: Bool) -> some ViewParameters
disabled*booleanA Boolean value that determines whether someone can interact with this view.
Return value
A view that controls whether someone can interact with this view.
Discussion
Add this modifier to a view to indicate whether it responds to
interactions such as a tap, click, or gesture. The following example
disables a Button when the Boolean value isLoading is true:
@State private var isLoading: Bool = false
var body: some View {
Button("Load") { }
.disabled(isLoading)
}Add this modifier to a container, such as a VStack, to indicate
whether views in the container are currently interactive, and to
override any .disabled(_:) modifiers you set on views within the
container or view hierarchy. In the following example, the
.disabled(true) modifier on the VStack disables all of the
Button instances in the stack, even the button that has the
modifier .disabled(false).
VStack {
Button("One") {}
.disabled(false)
Button("Two") {}
Button("Three") {}
}
.disabled(true)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.
- 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.
- 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.