React NativeScript

React NativeScript

  • Docs

›ELEMENTS: LAYOUT

INTRODUCTION

  • Introduction

GETTING STARTED

  • Quick Start
  • Environment Setup
  • Using React Devtools

CORE CONCEPTS

  • Native Access
  • Navigation
  • Node Roles
  • Modals
  • Plugins
  • Styling

SAMPLES

  • Apps

ELEMENTS: LAYOUT

  • AbsoluteLayout
  • DockLayout
  • FlexboxLayout
  • GridLayout
  • StackLayout
  • WrapLayout

ELEMENTS: COMPONENTS

  • ActivityIndicator
  • ActionBar
  • ActionItem
  • Button
  • DatePicker
  • Frame
  • HtmlView
  • Image
  • Label
  • ListView
  • ListPicker
  • NavigationButton
  • Page
  • Placeholder
  • Progress
  • ScrollView
  • SearchBar
  • SegmentedBar
  • Slider
  • Switch
  • TabView
  • TabViewItem
  • TextField
  • TextView
  • TimePicker
  • WebView

LICENCES

  • Licences
Edit

FlexboxLayout

<flexboxLayout> is a React wrapper around FlexboxLayout, a layout container that provides a non-exact implementation of the CSS Flexbox layout. This layout lets you arrange child components both horizontally and vertically.

See also:

  • Official top-level documentation
  • Detailed API specification

Examples

Default flex layout

The following example creates a row of three equally-sized elements that span across the entire height of the screen.

import * as React from "react";

<flexboxLayout backgroundColor="#3c495e">
  <label text="first" width={70} backgroundColor="#43b883"/>
  <label text="second" width={70} backgroundColor="#1c6b48"/>
  <label text="third" width={70} backgroundColor="#289062"/>
</flexboxLayout>

Licence: NativeScript Vue Artwork.

Column flex layout

The following example creates a column of three equally-sized elements that span across the entire width of the screen.

import * as React from "react";

<flexboxLayout flexDirection="column" backgroundColor="#3c495e">
  <label text="first" height={70} backgroundColor="#43b883"/>
  <label text="second" height={70} backgroundColor="#1c6b48"/>
  <label text="third" height={70} backgroundColor="#289062"/>
</flexboxLayout>

Licence: NativeScript Vue Artwork.

Row flex layout with items aligned to flex-start

The following example creates a row of three items placed at the top of the screen. Items are placed in the order they were declared in.

import * as React from "react";

<flexboxLayout alignItems="flex-start" backgroundColor="#3c495e">
  <label text="first" width={70} height={70} backgroundColor="#43b883"/>
  <label text="second" width={70} height={70} backgroundColor="#1c6b48"/>
  <label text="third" width={70} height={70} backgroundColor="#289062"/>
</flexboxLayout>

Licence: NativeScript Vue Artwork.

Row flex layout with custom order

The following example creates a row of three items placed at the top of the screen. Items are placed in a customized order.

import * as React from "react";

<flexboxLayout alignItems="flex-start" backgroundColor="#3c495e">
  <label text="first" order={2} width={70} height={70} backgroundColor="#43b883"/>
  <label text="second" order={3} width={70} height={70} backgroundColor="#1c6b48"/>
  <label text="third" order={1} width={70} height={70} backgroundColor="#289062"/>
</flexboxLayout>

Licence: NativeScript Vue Artwork.

Row flex layout with wrapping

The following example creates four items with enabled line wrapping. When the row runs out of space, the container wraps the last item on a new line.

import * as React from "react";

<flexboxLayout flexWrap="wrap" backgroundColor="#3c495e">
  <label text="first" width={30} backgroundColor="#43b883"/>
  <label text="second" width={30} backgroundColor="#1c6b48"/>
  <label text="third" width={30} backgroundColor="#289062"/>
  <label text="fourth" width={30} backgroundColor="#289062"/>
</flexboxLayout>

Licence: NativeScript Vue Artwork.

Column flex layout with reverse order and items with a different alignSelf

The following example shows how to use:

  • flexDirection to place items in a column, starting from the bottom.
  • justifyContent to create equal spacing between the vertically placed items.
  • alignSelf to modify the position of items across the main axis.
import * as React from "react";

<flexboxLayout
  flexDirection="column-reverse"
  justifyContent="space-around"
  backgroundColor="#3c495e"
>
  <label text="first" height={70} backgroundColor="#43b883"/>
  <label
    text="second"
    alignSelf="center"
    width={70}
    height={70}
    backgroundColor="#1c6b48"
  />
  <label
    text="third\nflex-end"
    alignSelf="flex-end"
    width={70}
    height={70}
    backgroundColor="#289062"
  />
  <label text="fourth" height={70} backgroundColor="#289062"/>
</flexboxLayout>

Licence: NativeScript Vue Artwork.

Props

NameTypeDescription
flexDirectionstringSets the direction for placing child elements in the flexbox container.
Valid values:
row (horizontal, left to right),
row-reverse (horizontal, right to left),
column (vertical, top to bottom), and
column-reverse (vertical, bottom to top).
Default value: row.
flexWrapstringSets whether child elements are forced in a single line or can flow into multiple lines. If set to multiple lines, also defines the cross axis which determines the direction new lines are stacked in.
Valid values:
nowrap (single line which may cause the container to overflow),
wrap (multiple lines, direction is defined by flexDirection),and
wrap-reverse (multiple lines, opposite to the direction defined by flexDirection).
Default value: nowrap.
justifyContentstringSets the alignment of child elements along the main axis. You can use it to distribute leftover space when all the child elements on a line are inflexible or are flexible but have reached their maximum size. You can also use it to control the alignment of items when they overflow the line.
Valid values:
flex-start (items are packed toward the start line),
flex-end (items are packed toward the end line),
center (items are centered along the line),
space-between (items are evenly distributed on the line; first item is on the start line, last item on the end line), and
space-around (items are evenly distributed on the line with equal space around them).
Default value: flex-start.
alignItemsstring(Android-only) Sets the alignment of child elements along the cross axis on the current line. Acts as justifyContent for the cross axis.
Valid values:
flex-start (cross-start margin edge of the items is placed on the cross-start line),
flex-end (cross-end margin edge of the items is placed on the cross-end line),
center (items are centered оn the cross axis),
baseline (the item baselines are aligned), and
stretch (items are stretched to fill the container but respect min-width and max-width).
Default value: stretch.
alignContentstringSets how lines are aligned in the flex container on the cross axis, similar to how justifyContent aligns individual items within the main axis.
This property has no effect when the flex container has only one line.
Valid values:
flex-start (lines are packed to the start of the container),
flex-end (lines are packed to the end of the container),
center (lines are packed to the center of the container),
space-between (lines are evenly distributed; the first line is at the start of the container while the last one is at the end),
space-around (lines are evenly distributed with equal space between them), and
stretch (lines are stretched to take up the remaining space).
Default value: stretch.

Extra props for child elements

When an element is a direct child of <flexboxLayout>, you can work with the following additional properties.

NameTypeDescription
ordernumberSets the order in which child element appear in relation to one another.
flexGrownumberIndicates that the child should grow in size, if necessary. Sets how much the child will grow in proportion to the rest of the child elements in the flex container.
flexShrinknumberIndicates that the child should shrink when the row runs out of space. Sets how much the flex item will shrink in proportion to the rest of the child elements in the flex container. When not specified, its value is set to 1.
alignSelfstring(Android-only) Overrides the alignItems value for the child.
Valid values:
flex-start (cross-start margin edge of the item is placed on the cross-start line),
flex-end (cross-end margin edge of the item is placed on the cross-end line),
center (item is centered on the cross axis),
baseline (the item baselines are aligned), and
stretch (items is stretched to fill the container but respects min-width and max-width).
Default value: stretch.
flexWrapBeforebooleanWhen true, forces the item to wrap onto a new line. This property is not part of the official Flexbox specification.
Default value: false.
rowSpannumberSpecifies the number of rows which this element spans across.
colSpannumberSpecifies the number of columns which this element spans across.

React NativeScript-specific props

None for <flexboxLayout>, nor for any of its children.

Last updated by Jamie Birch
← DockLayoutGridLayout →
  • Examples
    • Default flex layout
    • Column flex layout
    • Row flex layout with items aligned to flex-start
    • Row flex layout with custom order
    • Row flex layout with wrapping
    • Column flex layout with reverse order and items with a different alignSelf
  • Props
  • Extra props for child elements
  • React NativeScript-specific props
React NativeScript
Docs
Getting StartedUI Components Reference
Community
Stack OverflowChat on Slack in #reactTwitter
More
GitHub – React NativeScriptGitHub – Docs Site
Copyright © 2021 Jamie Birch