Declaration
import { HStack } from 'swiftui-react-native';@frozen nonisolated struct HStack<Content> where Content : ViewInitializers
One SwiftUI initializer backs <HStack>.
<HStack
alignment?: SwiftUI.VerticalAlignment
spacing?: number | null
>
children?: ReactNode
</HStack>nonisolated init(
alignment: VerticalAlignment = .center,
spacing: CGFloat? = nil,
@ContentBuilder content: () -> Content
)alignmentSwiftUI.VerticalAlignmentThe guide for aligning the subviews in this stack. This guide has the same vertical screen coordinate for every subview.
Default
`.center`spacingnumber | nullThe distance between adjacent subviews, or
nilif you want the stack to choose a default distance for each pair of subviews.Default
`nil`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
Unlike LazyHStack, which only renders the views when your app needs to
display them onscreen, an HStack renders the views all at once, regardless
of whether they are on- or offscreen. Use the regular HStack when you have
a small number of subviews or don't want the delayed rendering behavior
of the "lazy" version.
The following example shows a simple horizontal stack of five text views:
var body: some View {
HStack(
alignment: .top,
spacing: 10
) {
ForEach(
1...5,
id: \.self
) {
Text("Item \($0)")
}
}
}protocol, like when you want to create a conditional layout using
AnyLayout, use HStackLayout instead.
From Apple’s SwiftUI documentation. Code samples there are Swift.
Relationships
Conforms to
- View
See also
More in Layout.
- AnyLayoutA type-erased instance of the layout protocol.
- GeometryReaderA container view that defines its content as a function of its own size and coordinate space.
- GlassEffectContainerA view that combines multiple glass shapes into a single shape that can morph individual shapes into one another.
- GridA container view that arranges other views in a two dimensional layout.
- GridLayoutA grid that you can use in conditional layouts.
- GridRowA horizontal row in a two dimensional grid container.
- HStackLayoutA horizontal container that you can use in conditional layouts.
- LazyHGridA container view that arranges its child views in a grid that grows horizontally, creating items only as needed.
- LazyHStackA view that arranges its children in a line that grows horizontally, creating items only as needed.
- LazyVGridA container view that arranges its child views in a grid that grows vertically, creating items only as needed.
- LazyVStackA view that arranges its children in a line that grows vertically, creating items only as needed.
- ScrollViewA scrollable view.