Skip to main content
The StyleSheet API provides an abstraction similar to CSS StyleSheets for creating and managing component styles. It offers performance benefits through style validation and optimization.

Import

Methods

create()

Creates an optimized StyleSheet from a style object.
object
required
An object containing named style definitions.Each key becomes a style name, and each value is a style object.
Returns: An immutable object with the same keys, optimized for performance. Benefits:
  • Validates style properties at creation time
  • Freezes style objects in development mode
  • Enables performance optimizations
  • Provides better error messages
  • Allows style IDs for efficient bridging

flatten()

Flattens an array of style objects into a single aggregated style object.
array | object
required
A style object, array of styles, or nested array of styles.
Returns: A single flattened style object.

compose()

Combines two styles, with the second style overriding properties in the first.
object
First style object (base styles).
object
Second style object (override styles).
Returns: Combined style. If either style is falsy, returns the other without allocating an array.

Properties

hairlineWidth

The thinnest line width that can be displayed on the device.
Returns: number - Typically 1 / PixelRatio.get(), always at least 1 physical pixel.

absoluteFill

Pre-defined style for absolute positioning that fills the entire parent.
Equivalent to:

Examples

Basic Usage

Combining Styles

Using compose()

Using flatten()

Using hairlineWidth

Using absoluteFill

Responsive Styles

Conditional Styles

Shadows and Elevation

Reusable Style Compositions

Dynamic Styles

Nested Style Arrays

Style Properties

Layout Props

  • width, height
  • margin, marginTop, marginRight, marginBottom, marginLeft
  • padding, paddingTop, paddingRight, paddingBottom, paddingLeft
  • flex, flexDirection, flexWrap, flexGrow, flexShrink, flexBasis
  • justifyContent, alignItems, alignSelf, alignContent
  • position ('relative', 'absolute')
  • top, right, bottom, left
  • zIndex

Transform Props

Color and Background

  • backgroundColor
  • opacity
  • overflow ('visible', 'hidden', 'scroll')

Border Props

  • borderWidth, borderTopWidth, borderRightWidth, borderBottomWidth, borderLeftWidth
  • borderColor, borderTopColor, borderRightColor, borderBottomColor, borderLeftColor
  • borderRadius, borderTopLeftRadius, borderTopRightRadius, borderBottomLeftRadius, borderBottomRightRadius
  • borderStyle ('solid', 'dotted', 'dashed')

Shadow Props (iOS)

  • shadowColor
  • shadowOffset ({ width: number, height: number })
  • shadowOpacity
  • shadowRadius

Elevation (Android)

  • elevation

Text Props

  • color
  • fontSize, fontWeight, fontFamily, fontStyle
  • lineHeight, letterSpacing
  • textAlign ('left', 'right', 'center', 'justify')
  • textDecorationLine ('none', 'underline', 'line-through')
  • textTransform ('none', 'uppercase', 'lowercase', 'capitalize')

Performance Tips

Always use StyleSheet.create() instead of inline styles. It validates styles once and creates optimized style IDs.
Avoid creating new style objects or arrays on every render. This defeats performance optimizations.
Use StyleSheet.compose() for optimal performance when combining two styles, especially in reusable components.

Common Patterns

Theme-based Styles

Style Inheritance