Skip to content
Docs
Components
Layout
Box

Box

Wrapper around View component from react-native, it accepts every props from react native View component.

Import

import { Box } from 'react-native-ficus-ui';

Usage

Background color

EDITABLE EXAMPLE
<HStack spacing={10}>
  <Box h={40} w={40} bg="green.500" />
  <Box h={40} w={40} bg="teal.500" />
  <Box h={40} w={40} bg="yellow.500" />
  <Box h={40} w={40} bg="red.500" />
  <Box h={40} w={40} bg="blue.500" />
  <Box h={40} w={40} bg="gray.500" />
</HStack>

Shadows

EDITABLE EXAMPLE
<HStack spacing={10}>
  {['none', 'xs', 'sm', 'md', 'lg', 'xl', '2xl'].map(shadow => (
    <Box
      h={40}
      w={40}
      bg="white"
      borderRadius="sm"
      shadow={shadow}
      justifyContent="center"
      alignItems="center"
    >
      <Text>{shadow}</Text>
    </Box>
  ))}
</HStack>
🎉

React Native 0.76 introduces new style props boxShadow and filter for View, those props are now available on Ficus UI from version 1.3.0. You can pass boxShadow and filter props directly to Box component.

https://reactnative.dev/blog/2024/10/23/release-0.76-new-architecture#box-shadow-and-filter-style-props (opens in a new tab)

EDITABLE EXAMPLE
<Box
  h={40}
  w={40}
  bg="white"
  borderRadius="sm"
  boxShadow="5 5 5 0 rgba(255, 0, 0, 0.5)"
/>

Borders

EDITABLE EXAMPLE
<HStack spacing={10}>
  <Box
    h={40}
    w={40}
    borderColor="green.500"
    borderWidth={1}
  />
  <Box
    h={40}
    w={40}
    borderColor="yellow.500"
    borderWidth={1}
  />
  <Box h={40} w={40} borderColor="red.500" borderWidth={1} />
  <Box h={40} w={40} borderColor="blue.500" borderWidth={1} />
  <Box h={40} w={40} borderColor="gray.500" borderWidth={1} />
</HStack>

Border radius

EDITABLE EXAMPLE
<HStack spacing={10}>
  {['none', 'xs', 'sm', 'md', 'lg', 'xl', '2xl', 'full'].map(radius => (
    <Box h={40} w={40} borderRadius={radius} bg="blue.400" />
  ))}
</HStack>

Flex

EDITABLE EXAMPLE
<Box direction="row">
  <Box h={40} w={40} bg="red.400" flex={1} />
  <Box h={40} w={40} bg="yellow.400" flex={2} />
  <Box h={40} w={40} bg="green.400" flex={2} />
</Box>

Background image

EDITABLE EXAMPLE
<Box
  borderRadius="md"
  h={150}
  bgImg={{
    uri:
      'https://venngage-wordpress.s3.amazonaws.com/uploads/2018/09/Monochrome-Type-Simple-Background-Image.jpg',
  }}
/>

As prop

The as prop can be used to style any React Native component with Ficus UI.

EDITABLE EXAMPLE
<Box
  as={ReactNative.TouchableOpacity}
  bg="green.400"
  p="xl"
  mt="sm"
  borderRadius="md"
>
  <Text>Style any RN component with Ficus UI with "as" prop !</Text>
</Box>

Props

bg

The background color property (backgroundColor style prop in StyleSheet)

TypeRequired
stringNo

bgImg

The background image property. Will use ImageBackground component as parent wrapper.

TypeRequired
ImageSourcePropTypeNo

bgMode

The background image mode property.

TypeRequired
enum("contain", "cover", "stretch")No

m

The margin property (margin style prop in StyleSheet)

TypeRequired
number, stringNo

mt

The margin top property (marginTop style prop in StyleSheet)

TypeRequired
number, stringNo

mb

The margin bottom property (marginBottom style prop in StyleSheet)

TypeRequired
number, stringNo

mr

The margin right property (marginRight style prop in StyleSheet)

TypeRequired
number, stringNo

ml

The margin left property (marginLeft style prop in StyleSheet)

TypeRequired
number, stringNo

mx

The margin horizontal property (marginHorizontal style prop in StyleSheet)

TypeRequired
number, stringNo

my

The margin vertical property (marginVertical style prop in StyleSheet)

TypeRequired
number, stringNo

p

The padding property (padding style prop in StyleSheet)

TypeRequired
number, stringNo

pt

The padding top property (paddingTop style prop in StyleSheet)

TypeRequired
number, stringNo

pb

The padding bottom property (paddingBottom style prop in StyleSheet)

TypeRequired
number, stringNo

pr

The padding right property (paddingRight style prop in StyleSheet)

TypeRequired
number, stringNo

pl

The padding left property (paddingLeft style prop in StyleSheet)

TypeRequired
number, stringNo

px

The padding horizontal property (paddingHorizontal style prop in StyleSheet)

TypeRequired
number, stringNo

py

The padding vertical property (paddingVertical style prop in StyleSheet)

TypeRequired
number, stringNo

gap

The gap property (gap style prop in StyleSheet)

TypeRequired
number, stringNo

gapX

The gapX property (rowGap style prop in StyleSheet)

TypeRequired
number, stringNo

gapY

The gapY property (columnGap style prop in StyleSheet)

TypeRequired
number, stringNo

h

The height property (height style prop in StyleSheet)

TypeRequired
number, stringNo

w

The width property (width style prop in StyleSheet)

TypeRequired
number, stringNo

minH

The minimum height property (minHeight style prop in StyleSheet)

TypeRequired
number, stringNo

minW

The minimum width property (minWidth style prop in StyleSheet)

TypeRequired
number, stringNo

flex

The flex property for container (flex style prop in StyleSheet)

TypeRequired
numberNo

flexDirection

The flex direction property for container (flexDirection style prop in StyleSheet)

TypeRequired
enum("row", "column", "row-reverse", "column-reverse")No

direction

The flex direction property for container (flexDirection style prop in StyleSheet)

TypeRequired
enum("row", "column", "row-reverse", "column-reverse")No

flexWrap

The flex wrap property for container (flexWrap style prop in StyleSheet)

TypeRequired
enum("wrap", "nowrap", "wrap-reverse")No

wrap

The flex wrap property for container (flexWrap style prop in StyleSheet)

TypeRequired
enum("wrap", "nowrap", "wrap-reverse")No

flexGrow

The flex grow property for container (flexGrow style prop in StyleSheet)

TypeRequired
numberNo

grow

The flex grow property for container (flexGrow style prop in StyleSheet)

TypeRequired
numberNo

flexBasis

The flex basis property for container (flexBasis style prop in StyleSheet)

TypeRequired
number, stringNo

basis

The flex basis property for container (flexBasis style prop in StyleSheet)

TypeRequired
number, stringNo

flexShrink

The flex shrink property for container (flexShrink style prop in StyleSheet)

TypeRequired
numberNo

shrink

The flex shrink property for container (flexShrink style prop in StyleSheet)

TypeRequired
numberNo

justifyContent

The justify content property for container (justifyContent style prop in StyleSheet)

TypeRequired
enum("flex-start", "flex-end", "center", "space-between", "space-around", "space-evenly")No

alignItems

The align items property for container (alignItems style prop in StyleSheet)

TypeRequired
enum("flex-start", "flex-end", "center", "stretch", "baseline")No

alignSelf

The align self property for container (alignSelf style prop in StyleSheet)

TypeRequired
enum("auto", "flex-start", "flex-end", "center", "stretch", "baseline")No

position

The position property for container (position style prop in StyleSheet)

TypeRequired
enum("absolute", "relative")No

top

The top position property for container (top style prop in StyleSheet)

TypeRequired
numberNo

bottom

The bottom position property for container (bottom style prop in StyleSheet)

TypeRequired
numberNo

right

The right position property for container (right style prop in StyleSheet)

TypeRequired
numberNo

left

The left position property for container (left style prop in StyleSheet)

TypeRequired
numberNo

overflow

The overflow property for container (overflow style prop in StyleSheet)

TypeRequiredDefault
enum("visible", "scroll", "hidden")No"hidden"

borderRadius

The border radius property (borderRadius style prop in StyleSheet)

TypeRequiredDefault
number, stringNonone

borderTopRadius

The border radius top property (borderTopLeftRadius and borderTopRightRadius style props in StyleSheet)

TypeRequiredDefault
number, stringNonone

borderBottomRadius

The border radius bottom property (borderBottomLeftRadius and borderBottomRightRadius style props in StyleSheet)

TypeRequiredDefault
number, stringNonone

borderLeftRadius

The border radius left property (borderTopLeftRadius and borderBottomLeftRadius style props in StyleSheet)

TypeRequiredDefault
number, stringNonone

borderRightRadius

The border radius right property (borderTopRightRadius and borderBottomRightRadius style props in StyleSheet)

TypeRequiredDefault
number, stringNonone

borderTopLeftRadius

The border radius top left property (borderTopLeftRadius style prop in StyleSheet)

TypeRequiredDefault
number, stringNonone

borderTopRightRadius

The border radius top right property (borderTopRightRadius style prop in StyleSheet)

TypeRequiredDefault
number, stringNonone

borderBottomLeftRadius

The border radius bottom left property (borderBottomLeftRadius style prop in StyleSheet)

TypeRequiredDefault
number, stringNonone

borderBottomRightRadius

The border radius bottom right property (borderBottomRightRadius style prop in StyleSheet)

TypeRequiredDefault
number, stringNonone

borderColor

The border color property (borderColor style prop in StyleSheet)

TypeRequired
stringNo

borderTopColor

The border top color property (borderTopColor style prop in StyleSheet)

TypeRequired
stringNo

borderBottomColor

The border bottom color property (borderBottomColor style prop in StyleSheet)

TypeRequired
stringNo

borderRightColor

The border right color property (borderRightColor style prop in StyleSheet)

TypeRequired
stringNo

borderLeftColor

The border left color property (borderLeftColor style prop in StyleSheet)

TypeRequired
stringNo

borderWidth

The border width property (borderWidth style prop in StyleSheet)

TypeRequired
numberNo

borderTopWidth

The border top width property (borderTopWidth style prop in StyleSheet)

TypeRequired
numberNo

borderBottomWidth

The border bottom width property (borderBottomWidth style prop in StyleSheet)

TypeRequired
numberNo

borderRightWidth

The border right width property (borderRightWidth style prop in StyleSheet)

TypeRequired
numberNo

borderLeftWidth

The border left width property (borderLeftWidth style prop in StyleSheet)

TypeRequired
numberNo

shadow

The shadow property (shadowOffset and elevation style props in StyleSheet)

TypeRequired
numberNo

shadowColor

The shadow color property (shadowColor style props in StyleSheet)

TypeRequired
stringNo

boxShadow

NEW

The boxShadow property (boxShadow style prop in StyleSheet)

TypeRequired
string or objectNo

filter

NEW

The filter property (filter style prop in StyleSheet)

TypeRequired
string or objectNo

opacity

The opacity property (opacity style prop in StyleSheet)

TypeRequired
numberNo