DisclosureGroup
A view that shows or hides another content view, based on the state of a disclosure control.
Declaration
Initializers
6 SwiftUI initializers back <DisclosureGroup>. The props you pass pick one.
<DisclosureGroup
title: string
>
children?: ReactNode
</DisclosureGroup>nonisolated init(
_ titleKey: LocalizedStringKey,
@ContentBuilder content: @escaping () -> Content
)title*stringThe key for the localized label of
selfthat describes the content of the disclosure group.Swift
titleKey: LocalizedStringKeychildrenReactNodeContent. Strings become
Text; React Native views are laid out by Yoga and placed by SwiftUI.Swift
content: () -> Content
Also takes the common view props: modifiers, style and testID.
Overview
A disclosure group view consists of a label to identify the contents, and a control to show and hide the contents. Showing the contents puts the disclosure group into the "expanded" state, and hiding them makes the disclosure group "collapsed".
In the following example, a disclosure group contains two toggles and
an embedded disclosure group. The top level disclosure group exposes its
expanded state with the bound property, topLevelExpanded. By expanding
the disclosure group, the user can use the toggles to update the state of
the toggleStates structure.
struct ToggleStates {
var oneIsOn: Bool = false
var twoIsOn: Bool = true
}
@State private var toggleStates = ToggleStates()
@State private var topExpanded: Bool = true
var body: some View {
DisclosureGroup("Items", isExpanded: $topExpanded) {
Toggle("Toggle 1", isOn: $toggleStates.oneIsOn)
Toggle("Toggle 2", isOn: $toggleStates.twoIsOn)
DisclosureGroup("Sub-items") {
Text("Sub-item 1")
}
}
}From Apple’s SwiftUI documentation. Code samples there are Swift.
Relationships
Conforms to
- View
See also
More in Controls.
- ButtonA control that initiates an action.
- ColorPickerA control used to select a color from the system color picker UI.
- DatePickerA control for selecting an absolute date.
- MultiDatePickerA control for picking multiple dates.
- OutlineGroupA structure that computes views and disclosure groups on demand from an underlying collection of tree-structured, identified data.
- PasteButtonA system button that reads items from the pasteboard and delivers it to a closure.
- PickerA control for selecting from a set of mutually exclusive values.
- SecureFieldA control into which people securely enter private text.
- SliderA control for selecting a value from a bounded linear range of values.
- StepperA control that performs increment and decrement actions.
- SubscriptionViewA view that subscribes to a publisher with an action.
- TableA container that presents rows of data arranged in one or more columns, optionally providing the ability to select one or more members.