Group
A type that collects multiple instances of a content type --- like views, scenes, or commands --- into a single unit.
Declaration
import { Group } from 'swiftui-react-native';@frozen struct Group<Content>Initializers
2 SwiftUI initializers back <Group>. The props you pass pick one.
<Group>
children?: ReactNode
</Group>@export(implementation) nonisolated init(
@ContentBuilder content: () -> Content
)childrenReactNodeContent. 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
Use a group to collect multiple views into a single instance, without
affecting the layout of those views, like an SwiftUI.HStack,
SwiftUI.VStack, or SwiftUI.Section would. After creating a group,
any modifier you apply to the group affects all of that group's members.
For example, the following code applies the SwiftUI.Font.headline
font to three views in a group.
Group {
Text("SwiftUI")
Text("Combine")
Text("Swift System")
}
.font(.headline)Because you create a group of views with a SwiftUI.ContentBuilder, you can
use the group's initializer to produce different kinds of views from a
conditional, and then optionally apply modifiers to them. The following
example uses a Group to add a navigation bar title,
regardless of the type of view the conditional produces:
Group {
if isLoggedIn {
WelcomeView()
} else {
LoginView()
}
}
.navigationBarTitle("Start")The modifier applies to all members of the group --- and not to the group
itself. For example, if you apply View.onAppear(perform:) to the above
group, it applies to all of the views produced by the if isLoggedIn
conditional, and it executes every time isLoggedIn changes.
Because a group of views itself is a view, you can compose a group within
other content builders, including nesting within other groups. This allows you
to add large numbers of views to different content builder containers. The
following example uses a Group to collect 10 SwiftUI.Text instances,
meaning that the vertical stack's content builder returns only two views ---
the group, plus an additional SwiftUI.Text:
var body: some View {
VStack {
Group {
Text("1")
Text("2")
Text("3")
Text("4")
Text("5")
Text("6")
Text("7")
Text("8")
Text("9")
Text("10")
}
Text("11")
}
}You can initialize groups with several types other than SwiftUI.View,
such as SwiftUI.Scene and SwiftUI.ToolbarContent. The closure you
provide to the group initializer uses the corresponding builder type
(SwiftUI.SceneBuilder, SwiftUI.ToolbarContentBuilder, and so on),
and the capabilities of these builders vary between types. For example,
you can use groups to return large numbers of scenes or toolbar content
instances, but not to return different scenes or toolbar content based
on conditionals.
From Apple’s SwiftUI documentation. Code samples there are Swift.
Relationships
Conforms to
- AccessibilityRotorContent
- Commands
- CustomizableToolbarContent
- Scene
- SceneAccessoryContent
- Swift.Copyable
- Swift.Escapable
- TabContent
- TableColumnContent
- TableRowContent
- ToolbarContent
- View
See also
More in Views.
- ArrangementViewA view that arranges primary and secondary content using an adaptive layout that responds to the environment.
- ControlGroupA container view that displays semantically-related controls in a visually-appropriate manner for the context
- DividerA visual element that can be used to separate other content.
- EditButtonA button that toggles the edit mode environment value.
- EmptyViewA view that doesn't contain any content.
- GaugeA view that shows a value within a range.
- GroupBoxA stylized view, with an optional label, that visually collects a logical grouping of content.
- RenameButtonA button that triggers a standard rename action.
- SwipeActionsSwipe actions of a list row (SwiftUI swipeActions(edge:allowsFullSwipe:content:)). Place it inside a List.
- TimelineViewA view that updates according to a schedule that you provide.
- ViewThatFitsA view that adapts to the available space by providing the first child view that fits.