Page icon

grid Layout

The grid layout arranges components in equal-sized containers based on rows and cols.

{
  "type": "view",
  "layout": "grid",
  "spacing": 4,
  "rows": 2,
  "cols": 2,
  "components": [
    {
      "type": "button",
      "text": "First"
    },
    {
      "type": "button",
      "text": "Second"
    },
    {
      "type": "button",
      "text": "Third"
    },
    {
      "type": "button",
      "text": "Fourth"
    }
  ]
}

Components are added in wrapped rows starting from the top left.

Empty space is valid, so if you define a 3x3 grid and only add 6 components, you'll get an empty row at the bottom.

Properties

rows
INTEGER
Default: 2, Range: 1-128

How many rows for this layout.

cols
INTEGER
Default: 2, Range: 1-128

How many cols for this layout.

padding
INTEGER
Default: 0, Range: 0-64

Inset the content around the perimeter of the view by the padding amount.

spacing
INTEGER
Default: 0, Range: 0-64

Add spacing between the components in the view.

Constraints

Each component can use the shared constraints to refine their position within the layout.

Resizing Behaviour

The desired size for the grid is based on the largest added component, and each grid container is sized equally.

When rendering, the available space is equally divided into rows and cols, taking into account spacing and padding.