Styling
Everything to know about styling components.
Edge cases
Some differences (or unobvious cases) from RN and/or CSS:
- Default
flexDirection
iscolumn
(CSS default isrow
). - Default
alignContent
isflex-start
(CSS default isstretch
). - Default
flexShrink
is0
(CSS default is1
). flexBasis
takes precedence overwidth
andheight
if defined.- There’s no
margin: auto
. - Similarly to CSS and RN, if both top and bottom (or left and right) are defined and
height
(orwidth
) is not defined, the element will span the distance between those two edges. - Properties with higher specificity override properties with lower specificity (in CSS it is the that order matters).
In CSS
style="flex-grow: 1; flex: 2"
would use value2
forflex-grow
because it is defined later. Here corresponding code would use value1
forflex-grow
because it is more specific. Same goes formargin
,padding
,borderWidth
,gap
. box-sizing
is alwaysborder-box
, which means thatwidth
andheight
include bothpadding
andborder
(CSS default iscontent-box
).
Colors
Colors are defined as strings, similar to CSS.
Supported formats are hex (long and short variants – #f00
and #ff0000
), RGB, RGBA (rgba(255, 0, 0, 0.5)
), HSL (hsl(60 100% 50%)
, hsl(60, 100%, 50%, 0.8)
), HSLA, HSV.
RGB and HSV require adding A in the end to support alpha. In HSL it is optional. If color is not recognized, transparent
is used and warning is logged to the console. For the most up-to-date info check parseColor()
in the code.
API
TextStyleProps
/layout/styling.ts ↗
Controls how text is rendered. Note that due to a custom text renderer, there might be some differences in how text is rendered compared to a browser.
In-depth explanation of text rendering is available on the [Text Rendering](/text-rendering) page.
IMPORTANTThe library uses cap size as opposed to line height for calculating bounding box of text elements (see CapSize for more explanation). This results in most noticeable differences in buttons which require more vertical space than in browsers.
LayoutNodeState
/layout/styling.ts ↗
Internal state of the node. Might be useful for debugging or hacking around but it is subject to change at any point without notice.
Enums
List of enums used in the types above.
AlignItems
Corresponds to CSS align-items
. Controls positioning of children on the cross axis.
JustifyContent
Corresponds to CSS justify-content
. Controls positioning of children on the main axis.
AlignContent
Corresponds to CSS align-content
, which controls positions and sizes of lines in the flex
wrap. Does not have any effect if FlexWrap
is NoWrap
.
AlignSelf
Corresponds to CSS align-self
.
FlexDirection
Corresponds to CSS flex-direction
.
FlexWrap
Corresponds to CSS flex-wrap.
Overflow
Determines how the element is clipped. Corresponds to CSS overflow.
Display
Corresponds to CSS display.
Position
Corresponds to CSS position.
TextTransform
Corresponds to CSS text-transform
.
TextAlign
Corresponds to CSS text-align
.