Skip to main content
Version: 4.60

grid

Arranges content as tiles, arranged from top left to bottom right.

Field Configurations

KeyTypeDescriptionDefault Value
"children"ArrayList of child layers.null
"columns"NumberThe number of columns.12
"consumesKeyboard"BooleanIf 'true' is set, the grid adjusts automatically when the keyboard is opened. iOS only.false
"displayMode"DisplayModeDetermines in which way the elements should be loaded."eager"
"fullyVisible"StringSpecifies whether to fire the scroll event when an element is visible or only when it is fully visible.null
"horizontalItemSpacing"UnitSizeSpacing between elements in the horizontal direction0
"insets"ObjectInsets the content of the grid by the given values.null
"scrollDirection"StringThe direction in which the grid scrolls.null
"scrollEvent"StringEvent that is fired while scrollingnull
"scrollOnAppear"StringThe grid will automatically scroll to the set value when it appears."none"
"scrolling"BooleanIndicates if scrolling is allowedtrue
"verticalItemSpacing"UnitSizeSpacing between elements in the vertical direction0
"verticalScrollIndicator"BooleanSpecifies whether a scroll indicator should be displayed.false

Inherited

From Base Layer

Base Layer

Field Configurations

KeyTypeDescriptionDefault Value
"_value"Value[PREVIEW] Dynamic value of the layer.null
"accessibilityAppendState"StringDefines this layer appends its state to the accessibility text.null
"accessibilityText"StringText for accessibility navigation. Can be translated.null
"actions"ActionListList of actions, which will be executed when the layer is tapped.null
"borderColor"ColorThe color of the border in hex color value.null
"borderRadius"UnitSizeThe radius applies to all corners; with a borderWidth of 0 the border is not drawn and radius is set anyway.0
"borderWidth"UnitSizeThe width of the border.0
"bottomLeftRadius"UnitSizeRadius for the bottom left corner.0
"bottomRightRadius"UnitSizeRadius for the bottom right corner.0
"classes"ArrayList of classes for layer styles.null
"conditions"ConditionsList of conditions to alter the layer state.null
"constraints"ConstraintsA list of constraints defining the position of the layer in a layout.null
"consumesKeyboard"BooleanThis layer will be used to shrink, if a keyboard is shown.null
"dataKey"StringName for assigning data to this layer.null
"focusColor"ColorThe highlight color of this layer when it is focused. Mainly used on TV. If no color is provided, the pressedColor will be used.null
"hidden"BooleanIndicates whether the layer is hidden. Default: false.false
"isAccessibilityElement"StringDefines if this layer is important for accessibility navigation. The default depends on the layer type.null
"layerRotation"NumberThe layer is rotated by the specified degree.0
"name"StringUnique name in the layout. Used for alignment or actions.null
"opacity"NumberThe opacity of the layer.1
"overInsetBottom"BooleanDetermines if this layer ignores the save space at the bottom of the device.false
"overInsetTop"BooleanDetermines if this layer ignores the save space at the top of the device.false
"pressedColor"ColorThe highlight color of this layer when it is pressed. Mainly used on TV. If no color is provided, the focusColor will be used.null
"safeArea"SafeAreaTypeObjectDetermines the safe area behaviour.null
"shadowElevation"NumberThe elevation of this layer for casting shadows.0
"state"StringThe state the layer will use as default."default"
"states"LayerStatesA list of named states that affect the appearance of the layer.null
"topLeftRadius"UnitSizeRadius for the top left corner.0
"topRightRadius"UnitSizeRadius for the top right corner.0
"touchFeedback"TouchFeedbackDetermines if the layer should show a touch feedback if touched."visible"
"trackingKey"StringDefines a key for a scroll event.null
"type"LayerTypeThe type of the layernull
"value"Value(Initial) value of the layer.null

Examples

Example 1: Create a grid with three children

Goal: Creates a three-color container on the grid.

The following code can be used to accomplish this:

{
"type": "grid",
"columns": "12",
"constraints": [
{
"type": "pos",
"x": "0",
"y": "0"
},
{
"type": "size",
"width": "100%",
"height": "100%"
}
],
"children": [
{
"type": "container",
"constraints": [
{
"type": "grid",
"colSpan": "3",
"aspectRatio": "8"
}
],
"children": [
{
"type": "color",
"value": "#6d7070",
"constraints": [
{
"type": "pos",
"x": 0,
"y": 0
},
{
"type": "pos",
"x": 0,
"y": 0,
"anchor": "se",
"relativeAnchor": "se"
}
]
}
]
},
{
"type": "container",
"constraints": [
{
"type": "grid",
"colSpan": "9",
"aspectRatio": "8"
}
],
"children": [
{
"type": "color",
"value": "#34a7c9",
"constraints": [
{
"type": "pos",
"x": 0,
"y": 0
},
{
"type": "pos",
"x": 0,
"y": 0,
"anchor": "se",
"relativeAnchor": "se"
}
]
}
]
},
{
"type": "container",
"constraints": [
{
"type": "grid",
"colSpan": "12",
"aspectRatio": "4"
}
],
"children": [
{
"type": "color",
"value": "#f3f3f3",
"constraints": [
{
"type": "pos",
"x": 0,
"y": 0
},
{
"type": "pos",
"x": 0,
"y": 0,
"anchor": "se",
"relativeAnchor": "se"
}
]
}
]
}
]
}

If the sum of children's colSpans is greater than 12, the next children will be moved one step below.

Result:

Screenshot of the app showing the results of the sample code from Example 1.
A grid layer with three children has been created.

Example 2: Create a grid and add 'insert' as a child to display dynamic data.

Goal: Create a grid and add an insert layer to retrieve images from a database table and display them.

  1. Add a grid layer to the layout:
{
"type": "grid",
"columns": "12",
"classes": [
"fullSize"
],
"children": [
{
"name": "images",
"type": "insert",
"source": "query",
"sourceParams": {
"table": "images",
"query": "all",
"layout": "i_image",
"template": "imageInsert",
"columnSpan": "12",
"aspectRatio": "3.5"
}
}
]
}

A full-screen grid with an insert layer as a child has been created. It is not functioning yet, because the following components have not yet been created:
1.table:images and query: all in it.
2.layout:i_image.
3.client_template: imageInsert

  1. Create a database table with queries:
{
"table": {
"name": "images",
"fields": [
{
"name": "ID",
"type": "TEXT"
},
{
"name": "image_url",
"type": "TEXT"
}
],
"primaryKey": [
"ID"
],
"queries": {
"all": {
"custom": "SELECT * FROM images"
},
"byId": {
"custom": "SELECT * FROM images WHERE images.ID = ?"
}
}
},
"data": [
{
"ID": 1,
"image_url": "http://res.appframework.de/media/demo/image1.png"
},
{
"ID": 2,
"image_url": "http://res.appframework.de/media/demo/image2.jpg"
},
{
"ID": 3,
"image_url": "http://res.appframework.de/media/demo/image3.jpg"
}
]
}
  1. Create a i_image layout:
{
"name": "i_image",
"layers": [
{
"type": "container",
"classes": [
"fullSize"
],
"children": [
{
"type": "image",
"dataKey": "myImage",
"scaleType": "scaleAspectFill",
"classes": [
"fullSize"
]
}
]
}
]
}
  1. Create a client template to display the value from the database table in the i_image layout:
{
"name": "imageInsert",
"content": {
"myImage": {
"value": "{{image_url}}"
}
}
}

Result:

Screenshot of the app showing the results of the sample code from Example 2.
A grid layer has been created with an insert layer as a child to display dynamic data.