GridRow

A horizontal row in a two dimensional grid container.

ComponentiOS 16.0+macOS 13.0+tvOS 16.0+watchOS 9.0+GridRow in SwiftUI

Declaration

React
import { GridRow } from 'swiftui-react-native';
Swift
@frozen nonisolated struct GridRow<Content> where Content : View

Initializers

One SwiftUI initializer backs <GridRow>.

React
<GridRow
  alignment?: SwiftUI.VerticalAlignment | null
>
  children?: ReactNode
</GridRow>
Swift
nonisolated init(
    alignment: VerticalAlignment? = nil,
    @ContentBuilder content: () -> Content
)
  • An 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's Grid/init(alignment:horizontalSpacing:verticalSpacing:content:) initializer, which is VerticalAlignment/center by default.

    Default `nil`

  • childrenReactNode

    Content. 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.