FlexBox Layout
What is FlexBox Layout
Valdi uses FlexBox for layout. This should be familiar if you have done any web development.
The Valdi runtime integrates a cross-platform layout engine that follows the Web Flexbox specification. This engine calculates the positions and sizes of each element on the screen based on the properties provided in TypeScript, ensuring consistent layout across iOS, Android, and Desktop.
You can find examples and documentation on the different attributes for laying out views on the screen on the following references:
You can also practice on a real-time flexbox sandbox here:
FlexBox attributes in 30 seconds
Keep the following in mind:
main axis: in row mode it is the horizontal axis, in column mode it is the vertical axiscross axis: in row mode it is the vertical axis, in column mode it is the horizontal axis
FlexBox mainly uses the following attributes:
flexDirectionused to describe if children should be arranged in rows or columnsjustifyContentused to describe alignment of items along the main axisalignItemsused to describe alignment of items along the cross axis
Less often you might want to use other secondary attributes:
flexShrinkused to describe how the parent container should constrain item sizeflexGrowused to describe how item should occupy empty space in parent containerflexWrapused to describe how wrapping is done
FlexBox examples in 30 seconds
Example 1 Requirements
- A row of elements ➜
flexDirection=row - Horizontally centered ➜
justifyContent=center(in row mode, main axis is horizontal) - Vertically aligned to the bottom ➜
alignItems=flex-end(in row mode, cross axis is vertical)
go! 🎉
export class HelloWorld extends Component {
onRender() {
<view
flexDirection='row' // Row mode
justifyContent='center' // Main axis centered (row mode: main axis is horizontal)
alignItems='flex-end' // Cross axis toward end (row mode: cross axis is vertical)
backgroundColor='lightblue'
height={100}
>
{this.onRenderItems()}
</view>;
}
onRenderItems() {
for (let i = 0; i < 3; i++) {
<image src='https://placedog.net/500' height={64} width={64} border='1 solid red' />;
}
}
}

Example 2 Requirements
- A column of elements ➜
flexDirection=column - Vertically centered ➜
justifyContent=center(in column mode, main axis is vertical) - Horizontally aligned to the right ➜
alignItems=flex-end(in column mode, cross axis is horizontal)
go! 🎉
export class HelloWorld extends Component {
onRender() {
<view
flexDirection='column' // column mode
justifyContent='center' // Main axis centered (column mode: main axis is vertical)
alignItems='flex-end' // Cross axis toward end (column mode: cross axis is horizontal)
backgroundColor='lightblue'
height={100}
>
{this.onRenderItems()}
</view>;
}
onRenderItems() {
for (let i = 0; i < 3; i++) {
<label value='Hello World' border='1 solid red' backgroundColor='lightgrey' font={TextStyleFont.BODY}/>;
}
}
}

Things to keep in mind
flexDirectionwill impact every other flex attribute's behavior!justifyContent/alignItemsare equivalent, but apply to the main-axis/cross-axisalignSelfis equivalent toalignItems, but apply only on one child
Default behaviors
flexDirection= "column" (top to bottom)justifyContent= "flex-start" (start of the main-axis)alignItems= "stretch" (take all space in cross-axis)flexShrink= "0" (do not shrink content size when constrained by parent size)flexGrow= "0" (do not grow content size when space is available in parent)flexWrap= "no-wrap" (do not wrap around the cross-axis)
Was this page helpful?