Declaration
compose().selectionDisabled(isDisabled?: boolean)@export(implementation) nonisolated func selectionDisabled(
_ isDisabled: Bool = true
) -> some ViewParameters
isDisabledbooleanA Boolean value that determines whether users can select this view.
Discussion
Use this modifier to control the selectability of views in
selectable containers like List or Table. In the example,
below, the user can't select the first item in the list.
@Binding var selection: Item.ID?
@Binding var items: [Item]
var body: some View {
List(selection: $selection) {
ForEach(items) { item in
ItemView(item: item)
.selectionDisabled(item.id == items.first?.id)
}
}
}You can also use this modifier to specify the selectability of views
within a Picker. The following example represents a flavor picker
that disables selection on flavors that are unavailable.
Picker("Flavor", selection: $selectedFlavor) {
ForEach(Flavor.allCases) { flavor in
Text(flavor.rawValue.capitalized)
.selectionDisabled(isSoldOut(flavor))
}
}See also
More in Lists and tables.
- deleteDisabledAdds a condition for whether the view's view hierarchy is deletable.
- listItemTintSets the tint effect for content in a list.
- listRowBackgroundPlaces a custom background view behind a list row item.
- listRowInsetsSets the insets of rows in a list on the specified edges.
- listRowSeparatorSets the display mode for the separator associated with this specific row.
- listRowSeparatorTintSets the tint color associated with a row.
- listRowSpacingSets the vertical spacing between two adjacent rows in a List.
- listSectionIndexVisibilityChanges the visibility of the list section index.
- listSectionMarginsSet the section margins for the specific edges.
- listSectionSeparatorSets whether to hide the separator associated with a list section.
- listSectionSeparatorTintSets the tint color associated with a section.
- listSectionSpacingSets the spacing between adjacent sections in a List to a custom value.