Declaration
import { GridRow } from 'swiftui-react-native';@frozen nonisolated struct GridRow<Content> where Content : ViewInitializers
One SwiftUI initializer backs <GridRow>.
<GridRow
alignment?: SwiftUI.VerticalAlignment | null
>
children?: ReactNode
</GridRow>nonisolated init(
alignment: VerticalAlignment? = nil,
@ContentBuilder content: () -> Content
)alignmentSwiftUI.VerticalAlignment | nullAn optional
[VerticalAlignment](/docs/values/verticalalignment)for the row. If you don't specify a value, the row uses the vertical alignment component of the[Alignment](/docs/values/alignment)parameter that you specify in the grid'sGrid/init(alignment:horizontalSpacing:verticalSpacing:content:)initializer, which isVerticalAlignment/centerby default.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
Use one or more GridRow instances to define the rows of a Grid
container. The child views inside the row define successive grid cells.
You can add rows to the grid explicitly, or use the ForEach structure
to generate multiple rows. Similarly, you can add cells to the row
explicitly or you can use ForEach to generate multiple cells inside
the row. The following example mixes these strategies:
Grid {
GridRow {
Color.clear
.gridCellUnsizedAxes([.horizontal, .vertical])
ForEach(1..<4) { column in
Text("C\(column)")
}
}
ForEach(1..<4) { row in
GridRow {
Text("R\(row)")
ForEach(1..<4) { _ in
Circle().foregroundStyle(.mint)
}
}
}
}The grid in the example above has an explicit first row and three generated rows. Similarly, each row has an explicit first cell and three generated cells:
To create an empty cell, use something invisible, like the
ShapeStyle.clear color that appears in the first column of the first
row in the example above. However, if you use a flexible view like a
Color or a Spacer, you might also need to add the
View.gridCellUnsizedAxes(_:) modifier to prevent the view from
taking up more space than the other cells in the row or column need.
that resolves to the absence of a view and doesn't generate a cell.
By default, the cells in the row use the Alignment that you define
when you initialize the Grid. However, you can override the vertical
alignment for the cells in a row by providing a VerticalAlignment
value to the row's init(alignment:content:) initializer.
If you apply a view modifier to a row, the row applies the modifier to
all of the cells, similar to how a Group behaves. For example, if
you apply the View.border(_:width:) modifier to a row, SwiftUI draws
a border on each cell in the row rather than around the row.
From Apple’s SwiftUI documentation. Code samples there are Swift.
Relationships
Conforms to
- Swift.Copyable
- Swift.Escapable
- 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.
- HStackA view that arranges its subviews in a horizontal line.
- 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.