diff --git a/docs/flexbox.md b/docs/flexbox.md index f4b44da084c..2e713e576c5 100644 --- a/docs/flexbox.md +++ b/docs/flexbox.md @@ -1197,6 +1197,118 @@ const styles = StyleSheet.create({ export default App; ``` +## Row Gap, Column Gap and Gap + +- [`rowGap`](layout-props#rowgap) sets the size of the gap (gutter) between an element's rows. + +- [`columnGap`](layout-props#columngap) sets the size of the gap (gutter) between an element's columns. + +- [`gap`](layout-props#gap) sets the size of the gap (gutter) between rows and columns. It is a shorthand for `rowGap` and `columnGap`. + +You can use `flexWrap` and `alignContent` alongwith `gap` to add consistent spacing between items. + +```SnackPlayer name=Row%20Gap%20and%20Column%20Gap +import React, { useState } from "react"; +import { View, Text, StyleSheet, TextInput } from "react-native"; + +const RowGapAndColumnGap = () => { + const [rowGap, setRowGap] = useState(10); + const [columnGap, setColumnGap] = useState(10); + + return ( + + + + + + + + ); +}; + +const PreviewLayout = ({ + children, + handleColumnGapChange, + handleRowGapChange, + rowGap, + columnGap, +}) => ( + + + + Row Gap + handleRowGapChange(Number(v))} + /> + + + Column Gap + handleColumnGapChange(Number(v))} + /> + + + + {children} + + +); + +const styles = StyleSheet.create({ + itemsCenter: { alignItems: "center" }, + inputContainer: { + gap: 4, + flexDirection: "row", + justifyContent: "space-around", + }, + previewContainer: { padding: 10, flex: 1 }, + input: { + borderBottomWidth: 1, + paddingVertical: 3, + width: 50, + textAlign: "center", + }, + container: { + flex: 1, + marginTop: 8, + backgroundColor: "aliceblue", + maxHeight: 400, + flexWrap: "wrap", + alignContent: "flex-start", + }, + box: { + width: 50, + height: 80, + }, + box1: { + backgroundColor: "orangered", + }, + box2: { + backgroundColor: "orange", + }, + box3: { + backgroundColor: "mediumseagreen", + }, + box4: { + backgroundColor: "deepskyblue", + }, + box5: { + backgroundColor: "mediumturquoise", + }, +}); + +export default RowGapAndColumnGap; +``` + ## Width and Height The `width` property specifies the width of an element's content area. Similarly, the `height` property specifies the height of an element's content area. diff --git a/docs/layout-props.md b/docs/layout-props.md index c39be8674cb..3e142eb9a12 100644 --- a/docs/layout-props.md +++ b/docs/layout-props.md @@ -301,6 +301,16 @@ See https://developer.mozilla.org/en-US/docs/Web/CSS/bottom for more details of --- +### `columnGap` + +`columnGap` works like `column-gap` in CSS. Only pixel units are supported in React Native. See https://developer.mozilla.org/en-US/docs/Web/CSS/column-gap for more details. + +| Type | Required | +| ------ | -------- | +| number | No | + +--- + ### `direction` `direction` specifies the directional flow of the user interface. The default is `inherit`, except for root node which will have value based on the current locale. See https://yogalayout.com/docs/layout-direction for more details. @@ -407,6 +417,16 @@ When `flex` is -1, the component is normally sized according to `width` and `hei --- +### `gap` + +`gap` works like `gap` in CSS. Only pixel units are supported in React Native. See https://developer.mozilla.org/en-US/docs/Web/CSS/gap for more details. + +| Type | Required | +| ------ | -------- | +| number | No | + +--- + ### `height` `height` sets the height of this component. @@ -719,6 +739,16 @@ See https://developer.mozilla.org/en-US/docs/Web/CSS/right for more details of h --- +### `rowGap` + +`rowGap` works like `row-gap` in CSS. Only pixel units are supported in React Native. See https://developer.mozilla.org/en-US/docs/Web/CSS/row-gap for more details. + +| Type | Required | +| ------ | -------- | +| number | No | + +--- + ### `start` When the direction is `ltr`, `start` is equivalent to `left`. When the direction is `rtl`, `start` is equivalent to `right`.