Skip to main content

Box component

🗃️ Based on restyle, inherits ViewProps except style properties.

**Note that the Box component is not directly based on the View component, but on react-native/Libraries/Components/View/ViewNativeComponent

Effect demonstration

1. Square with blue background

<Box width={200} height={200} backgroundColor="primaryColor" margin="x3" />
Box-Demo-1

2. Center text

<Box
width={200}
height={200}
borderWidth={1}
marginHorizontal={"x4"}
borderColor="borderColor"
justifyContent="center"
alignItems="center"
>
<Text>Hello, Box</Text>
</Box>
Box-Demo-1

API

Except for the style properties, other properties are consistent with ViewProps. Style attributes are based on restyle, which flattens the properties originally wrapped in style and adopts the constraints defined in Theme. details as follows:

General properties

For definition, see: https://reactnative.dev/docs/layout-props

PropertiesRequiredDescriptionTypeDefault Value
backgroundColorfalseBackground color. The value is colorsstring
opacityfalseTransparency. Value 0 -1number1
visiblefalseWhether it is visiblebooleantrue

The value is spacing in Theme.

For definition, see: https://reactnative.dev/docs/layout-props

PropertiesRequiredDescriptionTypeDefault Value
marginfalse
marginStartfalse
marginEndfalse
marginHorizontalfalse
marginVerticalfalse
marginLeftfalse
marginRightfalse
marginBottomfalse
marginTopfalse
paddingfalse
paddingStartfalse
paddingEndfalse
paddingHorizontalfalse
paddingVerticalfalse
paddingLeftfalse
paddingRightfalse
paddingBottomfalse
paddingTopfalse

For definition, see: https://reactnative.dev/docs/layout-props

PropertiesRequiredDescriptionTypeDefault Value
widthfalse
minWidthfalse
maxWidthfalse
heightfalse
maxHeightfalse
minHeightfalse
flexfalse
flexDirectionfalse
flexBasisfalse
flexGrowfalse
flexShrinkfalse
flexWrapfalse
alignContentfalse
alignItemsfalse
alignSelffalse
justifyContentfalse
aspectRatiofalse
overflowfalse

For definition, see: https://reactnative.dev/docs/layout-props

PropertiesRequiredDescriptionTypeDefault Value
positionfalse
startfalse
endfalse
leftfalse
rightfalse
bottomfalse
topfalse
zIndexfalse

For the definition, see: https://reactnative.dev/docs/view-style-props

PropertiesRequiredDescriptionTypeDefault Value
borderWidthfalse
borderLeftWidthfalse
borderRightWidthfalse
borderBottomWidthfalse
borderTopWidthfalse
borderStartWidthfalse
borderEndWidthfalse
borderStylefalse
borderColorfalse
borderStartColorfalse
borderEndColorfalse
borderLeftColorfalse
borderRightColorfalse
borderBottomColorfalse
borderTopColorfalse
borderRadiusfalse
borderBottomStartRadiusfalse
borderBottomEndRadiusfalse
borderBottomLeftRadiusfalse
borderBottomRightRadiusfalse
borderTopStartRadiusfalse
borderTopEndRadiusfalse
borderTopLeftRadiusfalse
borderTopRightRadiusfalse

For definition, see: https://reactnative.dev/docs/shadow-props

PropertiesRequiredDescriptionTypeDefault Value
elevationfalse
shadowOffsetfalse
shadowOpacityfalse
shadowRadiusfalse
shadowColorfalse