The Grid
component in the Scripting app provides a flexible container for arranging child views in a two-dimensional grid layout. It supports customizable alignment, spacing, and nested child components to create visually appealing layouts.
Grid
ComponentA container view that arranges other views in a two-dimensional layout.
GridProps
Property | Type | Default | Description |
---|---|---|---|
alignment |
Alignment |
center |
The alignment for child views within each grid cell. Options include leading , center , or trailing . |
horizontalSpacing |
number |
Platform-defined | The horizontal distance, in points, between each cell. Defaults to a platform-appropriate value if not set. |
verticalSpacing |
number |
Platform-defined | The vertical distance, in points, between each cell. Defaults to a platform-appropriate value if not set. |
children |
(VirtualNode | undefined | null | (VirtualNode | undefined | null)[])[] | VirtualNode |
N/A | The child components or nodes to be arranged in the grid. |
GridRow
ComponentA child component of Grid
that represents a horizontal row in the grid layout. Use GridRow
to group and align child views horizontally within the grid.
GridRowProps
Property | Type | Default | Description |
---|---|---|---|
alignment |
VerticalAlignment |
center |
Aligns the content vertically within the row. Options include top , center , or bottom . |
children |
(VirtualNode | undefined | null | (VirtualNode | undefined | null)[])[] | VirtualNode |
N/A | The child components or nodes to be arranged horizontally in the row. |
Below is an example demonstrating how to use the Grid
and GridRow
components to create a layout with rows, text, images, and dividers.
Output Layout
Text
element ("Hello") and an Image
with the globe
icon, aligned vertically to the center.Image
with the wave
icon and a Text
element ("World"), aligned vertically to the bottom.Grid: Alignment
leading
: Aligns content to the start of the cell.center
: Centers content within the cell (default).trailing
: Aligns content to the end of the cell.GridRow: Alignment
top
: Aligns content to the top of the row.center
: Centers content vertically within the row (default).bottom
: Aligns content to the bottom of the row.Horizontal and Vertical Spacing
Children
VirtualNode
components, including Text
, Image
, GridRow
, and custom components.The Grid
and GridRow
components work seamlessly with other supported UI elements:
Divider
: Adds a visual separator between rows.Text
, Image
, and Custom Components: Use any supported UI components as children of GridRow
.The following showcases an image of the output:
This layout corresponds to the example provided, showing two rows with a divider.
Grid
's cell alignment with GridRow
's vertical alignment for precise layout control.Grid
and GridRow
makes them suitable for responsive designs with varying content.Feel free to experiment with different child components and spacing configurations to create tailored designs for your UIs!