Shared types
View properties, data types and code examples.
ViewContent
Renderable children: Views, primitive values or nested arrays. null/undefined contribute no content.
type ViewContent =
View | string | number | boolean | null | undefined | ViewContent[];
Example
const example: ViewContent = ['Speed', 78, null];
TextContent
Text values are converted with toString(); null/undefined become empty. Compose icons with other Views.
type TextContent =
| string
| number
| bigint
| boolean
| symbol
| { toString(): string }
| null
| undefined;
Example
const example: TextContent = {
toString() {
return '78 km/h';
},
};
HDRColor
HDR color data for drawing colors and gradients.
type HDRColor = { readonly $type: 'CapDrive.HDR'; readonly color: string };
Example
const example: HDRColor = HDR('white');
RGBColor
RGB components r/g/b and optional alpha a in 0–1. space selects srgb or displayP3.
type RGBColor = {
space?: 'srgb' | 'displayP3';
r: number;
g: number;
b: number;
a?: number;
};
Example
const example: RGBColor = {
space: 'displayP3',
r: 0.2,
g: 0.7,
b: 0.6,
a: 0.8,
};
Color
Color name/hex string, RGBColor or an HDR() color.
type Color = string | RGBColor | HDRColor;
Example
const example: Color = '#30B3A2';
ViewPoint
Local x/y coordinates in screen points, not geographic coordinates.
type ViewPoint = { x: number; y: number };
Example
const example: ViewPoint = { x: 20, y: 40 };
ChartDataPoint
Line-chart sample: value.x/y position the point; label.x/y provide text. null y breaks the line.
type ChartDataPoint = {
value: { x: number; y: number | null };
label: { x: string; y: string };
};
Example
const example: ChartDataPoint = {
value: { x: 12, y: null },
label: { x: '12s', y: '' },
};
ChartRange
Numeric domain [min, max], not item indexes or labels.
type ChartRange = readonly [min: number, max: number];
Example
const example: ChartRange = [-20, 100];
MapCoordinate
Geographic latitude and longitude in degrees.
type MapCoordinate = { latitude: number; longitude: number };
Example
const example: MapCoordinate = { latitude: 31.2304, longitude: 121.4737 };
MapPathStyle
Native route style: Color stroke, width, cap, join, dash, outline and optional endpoint markers. Gradients are unsupported.
type MapPathStyle = {
stroke?: Color;
lineWidth?: number;
lineCap?: 'round' | 'butt' | 'square';
lineJoin?: 'round' | 'miter' | 'bevel';
dash?: readonly number[];
dashPhase?: number;
outlineStroke?: Color;
outlineWidth?: number;
showEndpoints?: boolean;
};
Example
const example: MapPathStyle = {
stroke: '#30B3A2',
lineWidth: 4,
outlineStroke: 'white',
outlineWidth: 1,
showEndpoints: true,
};
ChartAxisStyle
Axis stroke paint, width, cap and dash settings. A clear stroke hides the axis line while labels remain separately controlled.
type ChartAxisStyle = {
stroke?: Paint;
lineWidth?: number;
lineCap?: 'round' | 'butt' | 'square';
dash?: readonly number[];
dashPhase?: number;
};
Example
const example: ChartAxisStyle = {
stroke: '#888888',
lineWidth: 1,
dash: [4, 3],
};
BarChartDataPoint
One bar’s numeric value and optional category label. Array order determines placement.
type BarChartDataPoint = { value: number; label?: string };
Example
const example: BarChartDataPoint = { value: -25, label: 'B' };
PathCommand
Path operations: move, line, quad, cubic, arc and close. Coordinates/radii use points; arc angles use degrees.
type PathCommand =
| { op: 'move'; x: number; y: number }
| { op: 'line'; x: number; y: number }
| { op: 'quad'; x: number; y: number; cx: number; cy: number }
| {
op: 'cubic';
x: number;
y: number;
c1x: number;
c1y: number;
c2x: number;
c2y: number;
}
| {
op: 'arc';
x: number;
y: number;
radius: number;
startAngle: number;
sweepAngle: number;
}
| { op: 'close' };
Example
const example: PathCommand = {
op: 'cubic',
x: 100,
y: 60,
c1x: 20,
c1y: 0,
c2x: 80,
c2y: 100,
};
GradientStop
A color, or a color plus location along the gradient in 0–1.
type GradientStop = Color | { color: Color; location: number };
Example
const example: GradientStop = { color: '#30B3A2', location: 0.7 };
GradientColors
Ordered gradient colors/stops. Plain colors are spaced evenly.
type GradientColors = ReadonlyArray<GradientStop>;
Example
const example: GradientColors = [
{ color: 'red', location: 0 },
{ color: 'blue', location: 1 },
];
LinearGradientOptions
Linear gradient angle in degrees and normalized center; center (0.5, 0.5) is the middle.
type LinearGradientOptions = { angle?: number; center?: ViewPoint };
Example
const example: LinearGradientOptions = {
angle: 90,
center: { x: 0.5, y: 0.5 },
};
RadialGradientOptions
Radial gradient start/end radii in points and a normalized center.
type RadialGradientOptions = {
startRadius?: number;
endRadius?: number;
center?: ViewPoint;
};
Example
const example: RadialGradientOptions = {
startRadius: 0,
endRadius: 60,
center: { x: 0.5, y: 0.5 },
};
AngularGradientOptions
Angular gradient angle in degrees and normalized center.
type AngularGradientOptions = { angle?: number; center?: ViewPoint };
Example
const example: AngularGradientOptions = {
angle: -90,
center: { x: 0.5, y: 0.5 },
};
Gradient
Gradient paint produced by LinearGradient, RadialGradient or AngularGradient; each can be called with or without new.
type Gradient = {
readonly type: 'linear' | 'radial' | 'angular';
readonly angle?: number;
readonly startRadius?: number;
readonly endRadius?: number;
readonly center?: ViewPoint;
readonly colors: GradientColors;
};
Example
const example: Gradient = LinearGradient(['red', 'blue'], { angle: 90 });
Paint
Drawing paint: a Color or Gradient.
type Paint = Color | Gradient;
Example
const example: Paint = RadialGradient(['white', '#30B3A2'], {
endRadius: 60,
});
DrawingEffect
Effect color, opacity, blur radius and x/y offset. Distances are in points.
type DrawingEffect = {
color?: Color;
opacity?: number;
radius?: number;
x?: number;
y?: number;
};
Example
const example: DrawingEffect = {
color: 'cyan',
opacity: 0.6,
radius: 8,
x: 0,
y: 2,
};
ViewTransform
Transform the whole View without changing layout. Translation uses points; rotation/skew use degrees; scale 1 is unchanged; anchors use 0–1.
type ViewTransform = {
translateX?: number;
translateY?: number;
scaleX?: number;
scaleY?: number;
rotation?: number;
skewX?: number;
skewY?: number;
anchorX?: number;
anchorY?: number;
};
Example
const example: ViewTransform = {
rotation: 30,
scaleX: 1.2,
scaleY: 1.2,
anchorX: 0.5,
anchorY: 0.5,
};
RepeatAxisValue
A number for the active axes, or separate x/y numbers for each axis.
type RepeatAxisValue = number | { x?: number; y?: number };
Example
const example: RepeatAxisValue = { x: 120, y: 80 };
AnimationProperty
Animatable property name or nested path. Each View supports only its listed subset.
type AnimationProperty =
| 'width'
| 'height'
| 'padding'
| 'x'
| 'y'
| 'opacity'
| 'cornerRadius'
| 'blur'
| 'shadowOpacity'
| 'shadowRadius'
| 'shadowX'
| 'shadowY'
| 'fontSize'
| 'letterSpacing'
| 'minimumScaleFactor'
| 'spacing'
| 'radius'
| 'radiusX'
| 'radiusY'
| 'startAngle'
| 'sweepAngle'
| 'lineWidth'
| 'dashPhase'
| 'trimStart'
| 'trimEnd'
| 'barThickness'
| 'value'
| 'offset'
| 'anchor'
| 'period'
| 'minLength'
| 'color'
| 'stroke'
| 'background'
| 'shadowColor'
| 'transform.translateX'
| 'transform.translateY'
| 'transform.scaleX'
| 'transform.scaleY'
| 'transform.rotation'
| 'transform.skewX'
| 'transform.skewY'
| 'transform.anchorX'
| 'transform.anchorY'
| 'period.x'
| 'period.y'
| 'value.x'
| 'value.y'
| 'anchor.x'
| 'anchor.y'
| 'offset.x'
| 'offset.y'
| 'start.x'
| 'start.y'
| 'end.x'
| 'end.y'
| 'rangeX.0'
| 'rangeX.1'
| 'rangeY.0'
| 'rangeY.1'
| 'xAxis.lineWidth'
| 'xAxis.dashPhase'
| 'yAxis.lineWidth'
| 'yAxis.dashPhase'
| 'xAxis.stroke'
| 'yAxis.stroke'
| 'regionOffset.x'
| 'regionOffset.y'
| 'pathStyle.lineWidth'
| 'pathStyle.outlineWidth'
| 'pathStyle.dashPhase'
| 'pathStyle.stroke'
| 'pathStyle.outlineStroke';
Example
const example: AnimationProperty = 'transform.rotation';
Animation
Animate a supported property when it changes. duration/delay use seconds; from/to set endpoints; repeat and autoreverse control repetition; wrap sets a periodic range.
type Animation = {
property: AnimationProperty;
duration?: number;
delay?: number;
curve?: string;
from?: number | Color;
to?: number | Color;
repeat?: number | 'forever';
autoreverse?: boolean;
wrap?: number;
};
Example
const example: Animation = {
property: 'opacity',
duration: 0.25,
curve: 'easeOut',
};
CircleAnimation
Animations for this curved layout/shape. sweepAngle uses numeric endpoints and does not support wrap; startAngle can use wrap: 360.
type CircleAnimation =
| (Omit<Animation, 'property'> & {
property:
| 'width'
| 'height'
| 'x'
| 'y'
| 'opacity'
| 'background'
| 'blur'
| 'shadowColor'
| 'shadowOpacity'
| 'shadowRadius'
| 'shadowX'
| 'shadowY'
| 'dashPhase'
| 'stroke'
| 'lineWidth'
| 'startAngle'
| 'transform.translateX'
| 'transform.translateY'
| 'transform.scaleX'
| 'transform.scaleY'
| 'transform.rotation'
| 'transform.skewX'
| 'transform.skewY'
| 'transform.anchorX'
| 'transform.anchorY';
})
| (Omit<Animation, 'property' | 'wrap' | 'from' | 'to'> & {
property: 'sweepAngle';
from?: number;
to?: number;
wrap?: never;
});
Example
const example: CircleAnimation = {
property: 'sweepAngle',
duration: 0.3,
from: 0,
to: 270,
};
EllipseAnimation
Animations for this curved layout/shape. sweepAngle uses numeric endpoints and does not support wrap; startAngle can use wrap: 360.
type EllipseAnimation =
| (Omit<Animation, 'property'> & {
property:
| 'width'
| 'height'
| 'x'
| 'y'
| 'opacity'
| 'background'
| 'blur'
| 'shadowColor'
| 'shadowOpacity'
| 'shadowRadius'
| 'shadowX'
| 'shadowY'
| 'dashPhase'
| 'stroke'
| 'lineWidth'
| 'startAngle'
| 'transform.translateX'
| 'transform.translateY'
| 'transform.scaleX'
| 'transform.scaleY'
| 'transform.rotation'
| 'transform.skewX'
| 'transform.skewY'
| 'transform.anchorX'
| 'transform.anchorY';
})
| (Omit<Animation, 'property' | 'wrap' | 'from' | 'to'> & {
property: 'sweepAngle';
from?: number;
to?: number;
wrap?: never;
});
Example
const example: EllipseAnimation = {
property: 'startAngle',
duration: 0.3,
wrap: 360,
};
ArcAnimation
Animations for this curved layout/shape. sweepAngle uses numeric endpoints and does not support wrap; startAngle can use wrap: 360.
type ArcAnimation =
| (Omit<Animation, 'property'> & {
property:
| 'width'
| 'height'
| 'x'
| 'y'
| 'opacity'
| 'background'
| 'blur'
| 'shadowColor'
| 'shadowOpacity'
| 'shadowRadius'
| 'shadowX'
| 'shadowY'
| 'dashPhase'
| 'stroke'
| 'lineWidth'
| 'startAngle'
| 'transform.translateX'
| 'transform.translateY'
| 'transform.scaleX'
| 'transform.scaleY'
| 'transform.rotation'
| 'transform.skewX'
| 'transform.skewY'
| 'transform.anchorX'
| 'transform.anchorY';
})
| (Omit<Animation, 'property' | 'wrap' | 'from' | 'to'> & {
property: 'sweepAngle';
from?: number;
to?: number;
wrap?: never;
});
Example
const example: ArcAnimation = {
property: 'sweepAngle',
duration: 0.3,
from: 0,
to: -180,
};
MapAnimation
Map animations apply to supported View and route-style properties. Native camera changes use cameraAnimation separately.
type MapAnimation =
| (Omit<Animation, 'property' | 'from' | 'to'> & {
property:
| 'width'
| 'height'
| 'x'
| 'y'
| 'opacity'
| 'cornerRadius'
| 'transform.translateX'
| 'transform.translateY'
| 'transform.scaleX'
| 'transform.scaleY'
| 'transform.rotation'
| 'transform.skewX'
| 'transform.skewY'
| 'transform.anchorX'
| 'transform.anchorY'
| 'regionOffset.x'
| 'regionOffset.y'
| 'pathStyle.lineWidth'
| 'pathStyle.outlineWidth'
| 'pathStyle.dashPhase';
from?: number;
to?: number;
})
| (Omit<Animation, 'property' | 'from' | 'to' | 'wrap'> & {
property: 'pathStyle.stroke' | 'pathStyle.outlineStroke';
from?: Color;
to?: Color;
wrap?: never;
});
Example
const example: MapAnimation = {
property: 'pathStyle.stroke',
duration: 0.25,
from: 'red',
to: 'blue',
};
LineChartAnimation
Chart animations also support numeric ranges and axis styles. Range changes do not use wrap; color paths accept colors.
type LineChartAnimation =
| (Omit<Animation, 'property'> & {
property:
| 'width'
| 'height'
| 'x'
| 'y'
| 'opacity'
| 'blur'
| 'shadowColor'
| 'shadowOpacity'
| 'shadowRadius'
| 'shadowX'
| 'shadowY'
| 'stroke'
| 'lineWidth'
| 'dashPhase'
| 'transform.translateX'
| 'transform.translateY'
| 'transform.scaleX'
| 'transform.scaleY'
| 'transform.rotation'
| 'transform.skewX'
| 'transform.skewY'
| 'transform.anchorX'
| 'transform.anchorY';
})
| (Omit<Animation, 'property' | 'wrap' | 'from' | 'to'> & {
property: 'rangeX.0' | 'rangeX.1' | 'rangeY.0' | 'rangeY.1';
from?: number;
to?: number;
wrap?: never;
})
| (Omit<Animation, 'property' | 'from' | 'to'> & {
property:
| 'xAxis.lineWidth'
| 'xAxis.dashPhase'
| 'yAxis.lineWidth'
| 'yAxis.dashPhase';
from?: number;
to?: number;
})
| (Omit<Animation, 'property' | 'from' | 'to' | 'wrap'> & {
property: 'xAxis.stroke' | 'yAxis.stroke';
from?: Color;
to?: Color;
wrap?: never;
});
Example
const example: LineChartAnimation = { property: 'rangeX.1', duration: 0.25 };
BarChartAnimation
Chart animations also support numeric ranges and axis styles. Range changes do not use wrap; color paths accept colors.
type BarChartAnimation =
| (Omit<Animation, 'property'> & {
property:
| 'width'
| 'height'
| 'x'
| 'y'
| 'opacity'
| 'background'
| 'cornerRadius'
| 'blur'
| 'shadowColor'
| 'shadowOpacity'
| 'shadowRadius'
| 'shadowX'
| 'shadowY'
| 'barThickness'
| 'stroke'
| 'lineWidth'
| 'dashPhase'
| 'transform.translateX'
| 'transform.translateY'
| 'transform.scaleX'
| 'transform.scaleY'
| 'transform.rotation'
| 'transform.skewX'
| 'transform.skewY'
| 'transform.anchorX'
| 'transform.anchorY';
})
| (Omit<Animation, 'property' | 'wrap' | 'from' | 'to'> & {
property: 'rangeY.0' | 'rangeY.1';
from?: number;
to?: number;
wrap?: never;
})
| (Omit<Animation, 'property' | 'from' | 'to'> & {
property:
| 'xAxis.lineWidth'
| 'xAxis.dashPhase'
| 'yAxis.lineWidth'
| 'yAxis.dashPhase';
from?: number;
to?: number;
})
| (Omit<Animation, 'property' | 'from' | 'to' | 'wrap'> & {
property: 'xAxis.stroke' | 'yAxis.stroke';
from?: Color;
to?: Color;
wrap?: never;
});
Example
const example: BarChartAnimation = { property: 'rangeY.1', duration: 0.25 };
RadialLayoutAnimation
Animations for this curved layout/shape. sweepAngle uses numeric endpoints and does not support wrap; startAngle can use wrap: 360.
type RadialLayoutAnimation =
| (Omit<Animation, 'property'> & {
property:
| 'width'
| 'height'
| 'padding'
| 'x'
| 'y'
| 'opacity'
| 'background'
| 'cornerRadius'
| 'blur'
| 'shadowColor'
| 'shadowOpacity'
| 'shadowRadius'
| 'shadowX'
| 'shadowY'
| 'radius'
| 'radiusX'
| 'radiusY'
| 'startAngle'
| 'transform.translateX'
| 'transform.translateY'
| 'transform.scaleX'
| 'transform.scaleY'
| 'transform.rotation'
| 'transform.skewX'
| 'transform.skewY'
| 'transform.anchorX'
| 'transform.anchorY';
})
| (Omit<Animation, 'property' | 'wrap' | 'from' | 'to'> & {
property: 'sweepAngle';
from?: number;
to?: number;
wrap?: never;
});
Example
const example: RadialLayoutAnimation = {
property: 'startAngle',
duration: 0.25,
wrap: 360,
};
SpacerAnimation
Spacer animates only width, height and minLength; it has no visual effects.
type SpacerAnimation = {
property: 'width' | 'height' | 'minLength';
duration?: number;
delay?: number;
curve?: string;
from?: number;
to?: number;
repeat?: number | 'forever';
autoreverse?: boolean;
wrap?: number;
};
Example
const example: SpacerAnimation = {
property: 'minLength',
duration: 0.25,
from: 8,
to: 24,
};
ContentAnimation
Transition when content changes. Choose the type supported by this View; duration/delay use seconds.
type ContentAnimation = {
type: 'fade' | 'slide' | 'scale' | 'numericText' | 'interpolate';
duration?: number;
delay?: number;
curve?: string;
direction?: string;
distance?: number;
scale?: number;
};
Example
const example: ContentAnimation = { type: 'numericText', duration: 0.18 };
ViewSize
Measured width and height in screen points.
type ViewSize = { width: number; height: number };
Example
const example: ViewSize = { width: 240, height: 140 };
ViewInsets
Insets in points: top, leading, bottom and trailing.
type ViewInsets = {
top: number;
leading: number;
bottom: number;
trailing: number;
};
Example
const example: ViewInsets = {
top: 24,
leading: 12,
bottom: 12,
trailing: 12,
};
CardContentMetrics
Measured card size, contentSize, headerSize and safeInsets passed to renderer. Use these to size content around the header.
type CardContentMetrics = {
size: ViewSize;
contentSize: ViewSize;
headerSize: ViewSize;
safeInsets: ViewInsets;
};
Example
const example: CardContentMetrics = {
size: { width: 240, height: 160 },
contentSize: { width: 216, height: 124 },
headerSize: { width: 216, height: 24 },
safeInsets: { top: 24, leading: 12, bottom: 12, trailing: 12 },
};