diff --git a/docs/layout-props.md b/docs/layout-props.md index a1f03e3f5aa..657aa22df5a 100644 --- a/docs/layout-props.md +++ b/docs/layout-props.md @@ -3,6 +3,172 @@ id: layout-props title: Layout Props --- +## Example + +The following example shows how different properties can affect or shape a React Native layout. +You can try for example to add or remove squares from the UI while changing the values of the property `flexWrap`. +Find more detailed examples about this properties in the [Layout with Flexbox](flexbox) docs page. + +```SnackPlayer name=LayoutProps%20Example +import React, { useState } from 'react'; +import { Button, ScrollView, StyleSheet, Text, View } from 'react-native'; +import Constants from 'expo-constants'; + +const App = () => { + const flexDirections = ['row', 'row-reverse', 'column', 'column-reverse']; + const justifyContents = [ + 'flex-start', + 'flex-end', + 'center', + 'space-between', + 'space-around', + 'space-evenly', + ]; + const alignItemsArr = [ + 'flex-start', + 'flex-end', + 'center', + 'stretch', + 'baseline', + ]; + const wraps = ['nowrap', 'wrap', 'wrap-reverse']; + const directions = ['inherit', 'ltr', 'rtl']; + const [flexDirection, setFlexDirection] = useState(0); + const [justifyContent, setJustifyContent] = useState(0); + const [alignItems, setAlignItems] = useState(0); + const [direction, setDirection] = useState(0); + const [wrap, setWrap] = useState(0); + + const hookedStyles = { + flexDirection: flexDirections[flexDirection], + justifyContent: justifyContents[justifyContent], + alignItems: alignItemsArr[alignItems], + direction: directions[direction], + flexWrap: wraps[wrap], + }; + + const changeSetting = (value, options, setterFunction) => { + if (value == options.length - 1) { + setterFunction(0); + return; + } + setterFunction(value + 1); + }; + + const Square = () => { + const sqStyle = { + width: 50, + height: 50, + backgroundColor: randomHexColor(), + }; + return ; + }; + const [squares, setSquares] = useState([Square(), Square(), Square()]); + return ( + <> + + + {squares.map(elem => elem)} + + + + +