Height and Width # | Edit on GitHub |
A component's height and width determine its size on the screen.
The simplest way to set the dimensions of a component is by adding a fixed width
and height
to style. All dimensions in React Native are unitless, and represent density-independent pixels.
Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.
Use flex
in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1
, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex
given, the higher the ratio of space a component will take compared to its siblings.
A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed
width
andheight
orflex
, the parent will have dimensions of 0 and theflex
children will not be visible.
After you can control a component's size, the next step is to learn how to lay it out on the screen.
Recently, we have been working hard to make the documentation better based on your feedback. Your responses to this yes/no style survey will help us gauge whether we moved in the right direction with the improvements. Thank you!