Style Attributes Reference
This document provides a comprehensive reference for all style attributes that can be used with the Style<T> object in Valdi. For usage patterns and best practices, see The Style<> Guide.
Yoga Layout Engine
Valdi's layout system is powered by Yoga, Facebook's cross-platform flexbox layout engine. The available flexbox attributes and their behavior are determined by the Yoga version used.
Current Yoga Version:
- Source Commit:
0be0e9fc0148aa609afdc31cb9670524f07050cb - Version Details: See
third-party/yoga/README.snap - Local Source:
third-party/yoga/ - Modifications: Custom modifications for Valdi integration (see README.snap for details)
Key Yoga Files:
- Enums/Types:
third-party/yoga/src/yoga/YGEnums.h - Style Properties:
third-party/yoga/src/yoga/style/Style.h - Core API:
third-party/yoga/src/yoga/Yoga.h
When debugging layout issues or understanding flexbox behavior, refer to this specific Yoga version as behavior may differ from other Yoga versions or standard CSS flexbox implementations.
Table of Contents
- Yoga Layout Engine
- Understanding Styles
- Common Layout Attributes
- Common View Attributes
- Element-Specific Styles
- Style Composition
- Performance Notes
- Practical Examples: Using Percentages
Understanding Styles
The Style<T> object allows you to group multiple attributes together for reuse and cleaner code. A style can contain any attribute that the element supports, except for the style property itself.
import { Style } from 'valdi_core/src/Style';
import { View } from 'valdi_tsx/src/NativeTemplateElements';
const myStyle = new Style<View>({
backgroundColor: '#ffffff',
padding: 16,
borderRadius: 8,
});
// Use in JSX:
<view style={myStyle} />
Key Points:
- Styles are typed -
Style<View>can only be used on<view>elements - Styles can be merged using
Style.merge() - Styles can be extended using
.extend() - Styles are overridden by inline attributes
- Styles should be created at initialization, not during render
Common Layout Attributes
These attributes are available on all elements (Layout, View, ScrollView, etc.) as they control layout and positioning.
Size Attributes
new Style<Layout>({
// Dimensions - support points, percentages, or 'auto'
width: 200, // number (points)
width: '50%', // string (percentage of parent width)
width: 'auto', // string (automatic sizing)
height: 100, // number (points)
height: '75%', // string (percentage of parent height)
height: 'auto', // string (automatic sizing)
// Size constraints - support points or percentages
minWidth: 50, // number (points)
minWidth: '20%', // string (percentage of parent width)
maxWidth: 500, // number (points)
maxWidth: '90%', // string (percentage of parent width)
minHeight: 50, // number (points)
minHeight: '10%', // string (percentage of parent height)
maxHeight: 500, // number (points)
maxHeight: '80%', // string (percentage of parent height)
// Aspect ratio - numeric ratio only (NOT a percentage)
aspectRatio: 1.5, // width/height ratio (1.5 means width is 1.5x height)
aspectRatio: 16/9, // common video aspect ratio
})
Percentage Calculation Examples:
// Parent container is 400pt wide x 600pt tall
// Child with width: '50%' will be 200pt wide (50% of 400pt)
// Child with height: '25%' will be 150pt tall (25% of 600pt)
// Child with margin: '10%' gets 10% of parent's width for horizontal margins (40pt)
// and 10% of parent's height for vertical margins (60pt)
Position Attributes
new Style<Layout>({
// Position type
position: 'relative', // 'relative' | 'absolute'
// Position offsets - support points or percentages
top: 10, // number (points)
top: '5%', // string (percentage of parent height)
right: 10, // number (points)
right: '5%', // string (percentage of parent width)
bottom: 10, // number (points)
bottom: '5%', // string (percentage of parent height)
left: 10, // number (points)
left: '5%', // string (percentage of parent width)
})
Position Percentage Behavior:
- Horizontal offsets (
left,right): Percentage is relative to parent's width - Vertical offsets (
top,bottom): Percentage is relative to parent's height
Spacing Attributes
new Style<Layout>({
// Margin (outside spacing) - supports points or percentages
margin: 10, // number (points, all sides)
margin: '5%', // string (percentage, all sides)
margin: '10 20', // string (top/bottom 10pt, left/right 20pt)
marginTop: 5, // number (points)
marginTop: '2%', // string (percentage of parent height)
marginRight: 5, // number (points)
marginRight: '3%', // string (percentage of parent width)
marginBottom: 5, // number (points)
marginBottom: '2%', // string (percentage of parent height)
marginLeft: 5, // number (points)
marginLeft: '3%', // string (percentage of parent width)
// Padding (inside spacing) - supports points or percentages
padding: 10, // number (points, all sides)
padding: '5%', // string (percentage, all sides)
padding: '10 20', // string (top/bottom 10pt, left/right 20pt)
paddingTop: 5, // number (points)
paddingTop: '2%', // string (percentage of parent height)
paddingRight: 5, // number (points)
paddingRight: '3%', // string (percentage of parent width)
paddingBottom: 5, // number (points)
paddingBottom: '2%', // string (percentage of parent height)
paddingLeft: 5, // number (points)
paddingLeft: '3%', // string (percentage of parent width)
})
Spacing Percentage Behavior:
- Horizontal spacing (
marginLeft,marginRight,paddingLeft,paddingRight): Percentage is relative to parent's width - Vertical spacing (
marginTop,marginBottom,paddingTop,paddingBottom): Percentage is relative to parent's height - Shorthand with percentage:
margin: '5%'applies 5% to all sides (horizontal uses parent width, vertical uses parent height)
Flexbox Layout Attributes
These attributes are implemented using Yoga, which provides a flexbox layout engine that closely follows the CSS Flexible Box Layout specification with some additions.
new Style<Layout>({
// Display mode
display: 'flex', // 'flex' | 'none'
overflow: 'visible', // 'visible' | 'scroll' (Yoga also supports 'hidden')
// Direction and orientation
direction: 'inherit', // 'inherit' | 'ltr' | 'rtl'
flexDirection: 'column', // 'column' | 'column-reverse' | 'row' | 'row-reverse'
// Flex properties for this element
flexGrow: 1, // number >= 0 (dimensionless, NOT a percentage)
flexShrink: 0, // number >= 0 (dimensionless, NOT a percentage)
flexBasis: 'auto', // string (automatic)
flexBasis: 100, // number (points)
flexBasis: '50%', // string (percentage of parent's main axis dimension)
flexWrap: 'no-wrap', // 'no-wrap' | 'wrap' | 'wrap-reverse'
// Alignment (for children)
justifyContent: 'flex-start', // 'flex-start' | 'center' | 'flex-end' |
// 'space-between' | 'space-around' | 'space-evenly'
alignItems: 'stretch', // 'stretch' | 'flex-start' | 'flex-end' |
// 'center' | 'baseline'
alignContent: 'flex-start', // Same options as justifyContent plus 'stretch'
// Self alignment (override parent's alignItems)
alignSelf: 'auto', // 'auto' | 'flex-start' | 'flex-end' | 'center' |
// 'stretch' | 'baseline' | 'space-between' | 'space-around'
})
Yoga-Specific Flexbox Behaviors
Aspect Ratio (Yoga Extension):
new Style<Layout>({
aspectRatio: 1.5, // number (width/height ratio)
// This is a Yoga-specific property, not in standard flexbox
})
Value Units: Yoga supports three types of values for dimensions and edges:
- Points: Absolute values (e.g.,
100) - Percent: Relative to parent (e.g.,
'50%') - Auto: Automatic sizing (e.g.,
'auto')
Where Percentages Are Supported: Percentage values are calculated relative to the parent element's corresponding dimension and are supported for:
- ✅ Size dimensions:
width,height,minWidth,maxWidth,minHeight,maxHeight - ✅ Spacing:
margin*,padding*(all directional variants) - ✅ Positioning:
top,right,bottom,left - ✅ Flex basis:
flexBasis
Where Percentages Are NOT Supported:
- ❌ Border properties:
borderWidth,borderRadius(points only) - ❌ Flex factors:
flexGrow,flexShrink(dimensionless numbers) - ❌ Aspect ratio:
aspectRatio(numeric ratio, not percentage) - ❌ Transform properties:
scaleX,scaleY,rotation,translationX,translationY(specific units) - ❌ Touch area:
touchAreaExtension*(points only) - ❌ Opacity and colors: Always specific formats
- ❌ Font sizes: Use point values or scaling options in font string
Alignment Extensions:
Yoga extends the standard flexbox alignContent and alignSelf to support space-between and space-around, which are not in the CSS flexbox spec for these properties.
Default Values: Some Yoga defaults differ from CSS flexbox:
alignItems:stretch(same as CSS)justifyContent:flex-start(same as CSS)flexDirection:column(CSS default isrow)position:relative(same as CSS)
Visibility & Performance Attributes
new Style<Layout>({
// Rendering control
zIndex: 1, // number (higher = on top)
animationsEnabled: true, // boolean
// Performance optimization
lazy: false, // boolean (shorthand for below)
lazyLayout: false, // boolean
limitToViewport: true, // boolean
// Viewport behavior
ignoreParentViewport: false, // boolean
extendViewportWithChildren: false, // boolean
// Estimated dimensions (for lazy layout)
estimatedWidth: 100, // number
estimatedHeight: 100, // number
})
Accessibility Attributes
new Style<Layout>({
// Accessibility category
accessibilityCategory: 'auto', // 'auto' | 'view' | 'text' | 'button' |
// 'image' | 'image-button' | 'input' |
// 'header' | 'link' | 'checkbox' | 'radio' |
// 'keyboard-key'
// Navigation behavior
accessibilityNavigation: 'auto', // 'auto' | 'passthrough' | 'leaf' |
// 'cover' | 'group' | 'ignored'
// Priority
accessibilityPriority: 0, // number
// Labels and hints
accessibilityLabel: 'Tap here', // string
accessibilityHint: 'Opens menu', // string
accessibilityValue: '50%', // string
// States
accessibilityStateDisabled: false, // boolean
accessibilityStateSelected: false, // boolean
accessibilityStateLiveRegion: false, // boolean
})
Common View Attributes
These attributes are available on all visible elements (View, ScrollView, ImageView, Label, etc.) as they control rendering and interaction.
Appearance Attributes
new Style<View>({
// Background
background: 'linear-gradient(#ff0000, #0000ff)', // gradient string
backgroundColor: '#ffffff', // color string
opacity: 1.0, // number 0.0-1.0
// Border
border: '2 solid #000000', // shorthand string
borderWidth: 2, // number or string
borderColor: '#000000', // color string
borderRadius: 8, // number or string ('8 8 0 0' for corners)
// Shadow
boxShadow: '0 2 10 rgba(0,0,0,0.1)', // string: 'x y blur color'
// Clipping
slowClipping: false, // boolean (degrades performance)
})
Gesture Attributes
new Style<View>({
// Touch control
touchEnabled: true, // boolean
// Gesture states (disabled flags)
onTapDisabled: false, // boolean
onDoubleTapDisabled: false, // boolean
onLongPressDisabled: false, // boolean
onDragDisabled: false, // boolean
onPinchDisabled: false, // boolean
onRotateDisabled: false, // boolean
// Gesture timing
onTouchDelayDuration: 0, // number (seconds)
longPressDuration: 0.5, // number (seconds)
// Touch area extension
touchAreaExtension: 10, // number (all sides)
touchAreaExtensionTop: 10, // number
touchAreaExtensionRight: 10, // number
touchAreaExtensionBottom: 10,// number
touchAreaExtensionLeft: 10, // number
})
Transform Attributes
new Style<View>({
// Scale
scaleX: 1.0, // number
scaleY: 1.0, // number
// Rotation
rotation: 0, // number (radians)
// Translation
translationX: 0, // number (points) or percent string of own width, flipped in RTL
translationY: 0, // number (points) or percent string of own height
// Transform origin
transformOrigin: 'center', // keywords, "50px 70px", or "25% 75%" (2D only)
})
Mask Attributes
new Style<View>({
maskOpacity: 1.0, // number 0.0-1.0
// Note: maskPath is GeometricPath, not styleable
})
Platform-Specific Attributes
new Style<View>({
// Accessibility
accessibilityId: 'my-button', // string (for testing)
// Scroll behavior
canAlwaysScrollHorizontal: false, // boolean
canAlwaysScrollVertical: false, // boolean
// Android-specific
filterTouchesWhenObscured: false, // boolean
})
View Lifecycle & Behavior
new Style<View>({
// View reuse
allowReuse: true, // boolean
})
Element-Specific Styles
Layout Styles
Style<Layout> can contain only layout-related attributes (size, position, spacing, flexbox, accessibility, lifecycle).
import { Layout } from 'valdi_tsx/src/NativeTemplateElements';
const layoutStyle = new Style<Layout>({
width: '100%',
height: 'auto',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
padding: 16,
// Cannot use: backgroundColor, borderRadius, etc. (View-only)
});
Available Attribute Groups:
- ✅ Size Attributes
- ✅ Position Attributes
- ✅ Spacing Attributes
- ✅ Flexbox Layout Attributes
- ✅ Visibility & Performance Attributes
- ✅ Accessibility Attributes
- ❌ Appearance Attributes (View only)
- ❌ Gesture Attributes (View only)
- ❌ Transform Attributes (View only)
View Styles
Style<View> can contain all Layout attributes plus View-specific attributes (appearance, gestures, transforms).
import { View } from 'valdi_tsx/src/NativeTemplateElements';
const viewStyle = new Style<View>({
// All Layout attributes
width: 200,
height: 200,
padding: 16,
flexDirection: 'column',
// View-specific attributes
backgroundColor: '#ffffff',
borderRadius: 8,
borderWidth: 1,
borderColor: '#dddddd',
boxShadow: '0 2 10 rgba(0,0,0,0.1)',
opacity: 0.9,
// Gestures
touchEnabled: true,
onTapDisabled: false,
// Transforms
scaleX: 1.0,
scaleY: 1.0,
rotation: 0,
});
Available Attribute Groups:
- ✅ All Layout attributes
- ✅ Appearance Attributes
- ✅ Gesture Attributes
- ✅ Transform Attributes
- ✅ Mask Attributes
- ✅ Platform-Specific Attributes
ScrollView Styles
Style<ScrollView> can contain all View attributes plus ScrollView-specific attributes.
import { ScrollView } from 'valdi_tsx/src/NativeTemplateElements';
const scrollStyle = new Style<ScrollView>({
// All View attributes
backgroundColor: '#f5f5f5',
padding: 16,
// ScrollView-specific attributes
horizontal: false,
bounces: true,
bouncesFromDragAtStart: true,
bouncesFromDragAtEnd: true,
bouncesVerticalWithSmallContent: false,
bouncesHorizontalWithSmallContent: false,
pagingEnabled: false,
scrollEnabled: true,
showsVerticalScrollIndicator: true,
showsHorizontalScrollIndicator: true,
cancelsTouchesOnScroll: true,
dismissKeyboardOnDrag: false,
dismissKeyboardOnDragMode: 'immediate',
fadingEdgeLength: 0,
decelerationRate: 'normal',
viewportExtensionTop: 0,
viewportExtensionRight: 0,
viewportExtensionBottom: 0,
viewportExtensionLeft: 0,
circularRatio: 0,
// Note: flexDirection is NOT available (use horizontal instead)
});
Available Attribute Groups:
- ✅ All View attributes
- ✅ Scroll Behavior Attributes
- ✅ Bounce/Overscroll Attributes
- ✅ Touch/Gesture Behavior Attributes
- ✅ Visual Indicators Attributes
- ✅ Viewport Extensions Attributes
- ❌
flexDirection(usehorizontalinstead)
Note: Programmatic properties like contentOffsetX, contentOffsetY, contentOffsetAnimated cannot be used in styles.
ImageView Styles
Style<ImageView> can contain all Layout and View attributes plus ImageView-specific attributes.
import { ImageView } from 'valdi_tsx/src/NativeTemplateElements';
const imageStyle = new Style<ImageView>({
// Layout attributes
width: 200,
height: 200,
// View attributes
backgroundColor: '#f5f5f5',
borderRadius: 8,
// ImageView-specific attributes
objectFit: 'cover', // 'fill' | 'contain' | 'cover' | 'none'
tint: '#007AFF', // color string
flipOnRtl: false, // boolean
// Content transform
contentScaleX: 1.0, // number
contentScaleY: 1.0, // number
contentRotation: 0, // number (radians)
// Note: src, filter, callbacks cannot be used in styles
});
Available Attribute Groups:
- ✅ All Layout attributes
- ✅ All View attributes
- ✅ Image Display Attributes
- ✅ Content Transform Attributes
- ❌
src(dynamic, use inline) - ❌
filter(complex object) - ❌ Callbacks (functions)
VideoView Styles
Style<VideoView> can contain all Layout and View attributes plus VideoView-specific attributes.
import { VideoView } from 'valdi_tsx/src/NativeTemplateElements';
const videoStyle = new Style<VideoView>({
// Layout attributes
width: 400,
height: 300,
// View attributes
backgroundColor: '#000000',
borderRadius: 8,
// VideoView-specific attributes
volume: 1.0, // number 0.0-1.0
playbackRate: 1, // 0=paused, 1=playing
// Note: src, seekToTime, callbacks cannot be used in styles
});
Available Attribute Groups:
- ✅ All Layout attributes
- ✅ All View attributes
- ✅ Volume and playback rate
- ❌
src(dynamic, use inline) - ❌
seekToTime(dynamic control) - ❌ Callbacks (functions)
Label Styles
Style<Label> can contain all Layout and View attributes plus Label-specific text attributes.
import { Label } from 'valdi_tsx/src/NativeTemplateElements';
const labelStyle = new Style<Label>({
// Layout attributes
width: 200,
padding: 8,
// View attributes
backgroundColor: '#ffffff',
borderRadius: 4,
// Text styling
font: 'Montserrat-Bold 16 unscaled 20',
color: '#000000',
textGradient: 'linear-gradient(#ff0000, #0000ff)',
textShadow: 'rgba(0,0,0,0.1) 1 1 1 1',
// Text layout
numberOfLines: 2, // number (0=unlimited)
textAlign: 'left', // 'left' | 'right' | 'center' | 'justified'
textDecoration: 'none', // 'none' | 'strikethrough' | 'underline' | 'dashed-underline' | 'dotted-underline'
lineHeight: 24, // number (points)
lineHeightMultiple: 1.2, // number (ratio)
letterSpacing: 0, // number (points)
textOverflow: 'ellipsis',// 'ellipsis' | 'clip'
// Auto-sizing
adjustsFontSizeToFitWidth: false, // boolean
minimumScaleFactor: 0.5, // number
// Note: value, selection, callbacks cannot be used in styles (dynamic)
});
Available Attribute Groups:
- ✅ All Layout attributes
- ✅ All View attributes
- ✅ Text Styling Attributes