OutlineGroup
A structure that computes views and disclosure groups on demand from an underlying collection of tree-structured, identified data.
Declaration
import { OutlineGroup } from 'swiftui-react-native';struct OutlineGroup<Data, ID, Parent, Leaf, Subgroup> where Data : RandomAccessCollection, ID : HashableInitializers
4 SwiftUI initializers back <OutlineGroup>. The props you pass pick one.
<OutlineGroup
data: any[]
childrenPath: string
>
children?: (arg0: SymbolicValue) => unknown
</OutlineGroup>init<DataElement>(
_ data: Data,
children: KeyPath<DataElement, Data?>,
@ContentBuilder content: @escaping (DataElement) -> Leaf
)
where ID == DataElement.ID, DataElement : Identifiable, DataElement == Data.Elementdata*any[]A collection of tree-structured, identified data.
childrenPath*stringA key path to a property whose non-
nilvalue gives the children ofdata. A non-nilbut empty value denotes an element capable of having children that's currently childless, such as an empty directory in a file system. On the other hand, if the property at the key path isnil, then the outline group treatsdataas a leaf in the tree, like a regular file in a file system.Swift
children: KeyPath<DataElement, Data?>children(arg0: SymbolicValue) => unknownA content builder that produces a content view based on an element in
data.Swift
content: (DataElement) -> Leaf
Also takes the common view props: modifiers, style and testID.
Overview
Use an outline group when you need a view that can represent a hierarchy of data by using disclosure views. This allows the user to navigate the tree structure by using the disclosure views to expand and collapse branches.
In the following example, a tree structure of FileItem data offers a
simplified view of a file system. Passing the root of this tree and the
key path of its children allows you to quickly create a visual
representation of the file system.
struct FileItem: Hashable, Identifiable, CustomStringConvertible {
var id: Self { self }
var name: String
var children: [FileItem]? = nil
var description: String {
switch children {
case nil:
return "๐ \(name)"
case .some(let children):
return children.isEmpty ? "๐ \(name)" : "๐ \(name)"
}
}
}
let data =
FileItem(name: "users", children:
[FileItem(name: "user1234", children:
[FileItem(name: "Photos", children:
[FileItem(name: "photo001.jpg"),
FileItem(name: "photo002.jpg")]),
FileItem(name: "Movies", children:
[FileItem(name: "movie001.mp4")]),
FileItem(name: "Documents", children: [])
]),
FileItem(name: "newuser", children:
[FileItem(name: "Documents", children: [])
])
])
OutlineGroup(data, children: \.children) { item in
Text("\(item.description)")
}Type parameters
Five generic type constraints define a specific OutlineGroup instance:
Data: The type of a collection containing the children of an element in the tree-shaped data.ID: The type of the identifier for an element.Parent: The type of the visual representation of an element whose children property is non-nilLeaf: The type of the visual representation of an element whose children property isnil.Subgroup: A type of a view that groups a parent view and a view representing its children, typically with some mechanism for showing and hiding the children
From Appleโs SwiftUI documentation. Code samples there are Swift.
Relationships
Conforms to
- Swift.Copyable
- Swift.Escapable
- TableRowContent
- 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.
- DisclosureGroupA view that shows or hides another content view, based on the state of a disclosure control.
- MultiDatePickerA control for picking multiple dates.
- 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.