Styling
You can style Voltra components using React Native-style style props. The style prop works with a limited set of React Native properties that are automatically converted to SwiftUI modifiers under the hood.
React Native style prop
Voltra supports a limited subset of React Native style properties. When you pass a style prop to a Voltra component, these properties are automatically converted to SwiftUI modifiers under the hood. This makes it easy to get started if you're familiar with React Native styling.
Supported properties
The following React Native style properties are supported:
Layout:
width- Fixed width (number values only, percentages are ignored)height- Fixed height (number values only, percentages are ignored)flex- Flex shorthand (follows Yoga's behavior). Positive values act asflexGrow, negative values act asflexShrink. ExplicitflexGrow/flexShrinktake precedence if both are specified.flexGrow- Flex grow factor. When > 0, allows the view to grow to fill available space (converts to flexible frame withmaxWidth/maxHeightset to infinity)flexShrink- Flex shrink factor. When > 0, allows the view to shrink below its ideal size (setsminWidth/minHeightto 0)padding- Uniform padding on all edgespaddingTop,paddingBottom,paddingLeft,paddingRight- Individual edge paddingpaddingHorizontal,paddingVertical- Horizontal and vertical paddingmargin,marginTop,marginBottom,marginLeft,marginRight,marginHorizontal,marginVertical- All margin properties are mapped to padding in SwiftUI
Positioning:
position- Positioning mode:'static'(default),'relative', or'absolute'left- Horizontal position coordinate (used withposition)top- Vertical position coordinate (used withposition)zIndex- Z-order of the element
Style:
backgroundColor- Background color (hex strings, color names, or CSS gradient strings — see Gradients)opacity- Opacity value between 0 and 1borderRadius- Corner radius valueborderWidth- Border widthborderColor- Border color
Shadow:
shadowColor- Shadow colorshadowOffset- Shadow offset ({ width: number, height: number })shadowOpacity- Shadow opacityshadowRadius- Shadow blur radius
Text:
fontSize- Font size (maps tofontmodifier)fontWeight- Font weight (e.g.,'600','bold','regular')fontFamily- Custom font family name (see Custom Fonts section below)color- Text color (maps toforegroundStylemodifier)letterSpacing- Spacing between characters (maps tokerningmodifier)fontVariant- Font variant array (e.g.,['small-caps', 'tabular-nums']). Supported values:'small-caps'- Applies small caps styling (iOS 14+)'tabular-nums'- Applies monospaced digits (iOS 15+)
Effects:
overflow: 'hidden'- Clips content to bounds (maps toclippedmodifier)
Flexbox Properties (Opt-in)
When using the View component or enabling flexbox mode on VStack/HStack with layout="flex", additional flexbox properties become available via the style prop:
Container Properties:
flexDirection:'row'|'column'- Main axis directionalignItems:'flex-start'|'center'|'flex-end'|'stretch'- Cross-axis alignmentjustifyContent:'flex-start'|'center'|'flex-end'|'space-between'|'space-around'|'space-evenly'- Main-axis distributiongap: number - Spacing between children along the main axis (one-axis only, no columnGap/rowGap)
Child Properties:
flex: number - Shorthand for flexGrow/flexShrinkflexGrow: number - Growth factorflexShrink: number - Shrink factorflexBasis: number | 'auto' - Base sizealignSelf: Override parent's alignItems
Flexbox properties only work when flexbox layout is enabled. See Flexbox Layout for comprehensive documentation.
Limitations
Properties not listed above are ignored during rendering. This includes common React Native properties like:
- Flexbox layout properties (
flexDirection,justifyContent,alignItems,gap, etc.) are only available when using flexbox layout. Use theViewcomponent or setlayout="flex"on VStack/HStack to enable these properties. See Flexbox Layout for details. Propertiesflex,flexGrow,flexShrink,flexBasis, andalignSelfwork on children inside flexbox containers. columnGap,rowGap, andflexWrapproperties - Voltra only supports a singlegapvalue along the main axis, and does not support wrapping- Percentage-based widths and heights
rightandbottompositioning properties - Onlyleftandtopare supported- Most text styling properties beyond
fontSize,fontWeight,fontFamily,color,letterSpacing, andfontVariant - Live Update Overrides: Certain styling properties (like
heightorborderRadiuson progress bars) may be ignored when using live-updating features liketimerIntervalto ensure compatibility with smooth system animations.
Voltra supports CSS-style positioning with three modes:
position: 'static'- Normal layout flow.leftandtopare ignored.position: 'relative'- Offsets the element from its natural position usingleftandtop. The offset moves the element right (positiveleft) and down (positivetop).position: 'absolute'(default whenleft/topprovided) - Positions the element's center at the coordinates specified byleftandtop. This differs from CSS which positions from the top-left corner, but matches SwiftUI's native behavior.
Note: If you provide left or top without specifying position, it defaults to 'absolute' for backward compatibility. To ignore left/top, explicitly set position: 'static'.
For most layouts, prefer using stack alignment props (ZStack, VStack, HStack) which provide better layout control. Use positioning for fine-tuning or overlays.
See the Layout & Containers documentation for details on alignment.
Example
Gradients
The backgroundColor style property accepts CSS gradient strings in addition to solid colors. Gradients are rendered natively using SwiftUI gradient modifiers and are automatically clipped by borderRadius.
Invalid or unsupported gradient syntax is parsed in strict mode and results in no gradient background (instead of silent best-effort fallback).
Linear gradients
Supported directions: to right, to left, to top, to bottom, to top right, to top left, to bottom right, to bottom left.
Color stops
Explicit percentage positions are supported:
When positions are omitted, Voltra applies CSS-like stop fix-up:
- First and last unspecified stops default to
0%and100%. - Unspecified stops between explicit anchors are linearly interpolated.
- Non-monotonic explicit positions are clamped forward.
RGBA colors inside gradients
Radial gradients
Radial gradients are rendered with geometry-aware radii computed from the view size (closest-side, farthest-side, closest-corner, farthest-corner).
For ellipse, SwiftUI does not provide native elliptical radial gradients. Voltra approximates ellipse behavior by scaling a circular radial gradient.
Conic gradients
With border radius
Gradients are clipped by borderRadius automatically — no extra configuration needed:
Solid colors still work unchanged
Passing a plain color string to backgroundColor continues to work exactly as before:
Comparison with <LinearGradient> component
Use backgroundColor gradient strings for convenience and web-style syntax. Use <LinearGradient> when you need precise {x, y} coordinate control or dithering.
Scope and exclusions
- Supported core syntax:
linear-gradient(...),radial-gradient(...),conic-gradient(...). - Not supported in this parser:
repeating-linear-gradient(...),repeating-radial-gradient(...),repeating-conic-gradient(...).
Custom Fonts
Voltra supports custom fonts through the fontFamily style property.
Adding Custom Fonts to Your Project
Voltra supports custom fonts in your Live Activities and Widgets through two main methods:
1. Using Voltra's Font Configuration (Recommended)
The simplest way is to specify fonts directly in the Voltra plugin configuration. This follows the same pattern as expo-font:
The fonts array can include:
- Individual font files:
"./assets/fonts/CustomFont.ttf" - Entire directories:
"./assets/fonts"(all fonts in the directory will be included) - Supported formats:
.ttf,.otf,.woff,.woff2
2. Adding Fonts Manually in Xcode
For non-Expo projects or if you prefer manual configuration, you can add fonts directly to your Xcode project:
- Add your font files (
.otfor.ttf) to your Xcode project - Ensure they're included in the Live Activity target's "Copy Bundle Resources" build phase
- Add the font file names to your
Info.plistunder theUIAppFontskey for Live Activity target
For detailed instructions, see Apple's documentation on Applying custom fonts to text.
Using Custom Fonts
Once your fonts are added to the project, you can use them with the fontFamily style property:
The font family name you use in fontFamily should match the font's PostScript name, not the file name. You can find the PostScript name:
- In the Font Book app on macOS
- Using online tools like fontdrop.info
- In Xcode's font picker
For example, the font file Inter-Bold.ttf has the PostScript name Inter-Bold.
Font Weight with Custom Fonts
When using fontFamily, the fontWeight style property is ignored since you typically specify the exact font variant (e.g., Inter-Bold, Inter-Regular). If you need different weights, add multiple font files and specify the complete font name:
Example with Google Fonts
If you're using Google Fonts via @expo-google-fonts, they work seamlessly with Voltra:
If fontFamily is not specified or the font cannot be found, Voltra will fall back to the system font with the specified fontWeight.
