Tipi comuni
Consulta le proprietà delle View, i tipi di dati e gli esempi di codice.
ViewContent
Views, valori semplici o array annidati; null/undefined non producono contenuto.
type ViewContent =
View | string | number | boolean | null | undefined | ViewContent[];
Esempio
const example: ViewContent = ['Speed', 78, null];
TextContent
Conversione del testo con toString(); null/undefined restano vuoti. Componi le icone con altri Views.
type TextContent =
| string
| number
| bigint
| boolean
| symbol
| { toString(): string }
| null
| undefined;
Esempio
const example: TextContent = {
toString() {
return '78 km/h';
},
};
HDRColor
Dati di colore HDR per colori di disegno e sfumature.
type HDRColor = { readonly $type: 'CapDrive.HDR'; readonly color: string };
Esempio
const example: HDRColor = HDR('white');
RGBColor
r/g/b e a facoltativo tra 0 e 1; space sceglie srgb o displayP3.
type RGBColor = {
space?: 'srgb' | 'displayP3';
r: number;
g: number;
b: number;
a?: number;
};
Esempio
const example: RGBColor = {
space: 'displayP3',
r: 0.2,
g: 0.7,
b: 0.6,
a: 0.8,
};
Color
Nome colore, stringa esadecimale, RGBColor o colore HDR().
type Color = string | RGBColor | HDRColor;
Esempio
const example: Color = '#30B3A2';
ViewPoint
Coordinate locali x/y in punti schermo, non latitudine/longitudine.
type ViewPoint = { x: number; y: number };
Esempio
const example: ViewPoint = { x: 20, y: 40 };
ChartDataPoint
value.x/y posizionano il punto; label.x/y danno il testo; y null interrompe la linea.
type ChartDataPoint = {
value: { x: number; y: number | null };
label: { x: string; y: string };
};
Esempio
const example: ChartDataPoint = {
value: { x: 12, y: null },
label: { x: '12s', y: '' },
};
ChartRange
Intervallo numerico [min, max], non indici o etichette.
type ChartRange = readonly [min: number, max: number];
Esempio
const example: ChartRange = [-20, 100];
MapCoordinate
Latitudine latitude e longitudine longitude in gradi.
type MapCoordinate = { latitude: number; longitude: number };
Esempio
const example: MapCoordinate = { latitude: 31.2304, longitude: 121.4737 };
MapPathStyle
Stile nativo: Color, spessore, estremità, giunzioni, tratteggio, contorno e marcatori facoltativi. Sfumature non supportate.
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;
};
Esempio
const example: MapPathStyle = {
stroke: '#30B3A2',
lineWidth: 4,
outlineStroke: 'white',
outlineWidth: 1,
showEndpoints: true,
};
ChartAxisStyle
Colore, spessore, estremità e tratteggio dell’asse. clear nasconde la linea; etichette controllate separatamente.
type ChartAxisStyle = {
stroke?: Paint;
lineWidth?: number;
lineCap?: 'round' | 'butt' | 'square';
dash?: readonly number[];
dashPhase?: number;
};
Esempio
const example: ChartAxisStyle = {
stroke: '#888888',
lineWidth: 1,
dash: [4, 3],
};
BarChartDataPoint
value numerico e label facoltativo di una barra; disposizione nell’ordine dell’array.
type BarChartDataPoint = { value: number; label?: string };
Esempio
const example: BarChartDataPoint = { value: -25, label: 'B' };
PathCommand
Comandi move, line, quad, cubic, arc, close. Coordinate/raggi in punti, angoli in gradi.
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' };
Esempio
const example: PathCommand = {
op: 'cubic',
x: 100,
y: 60,
c1x: 20,
c1y: 0,
c2x: 80,
c2y: 100,
};
GradientStop
Colore oppure colore con location da 0 a 1 nel gradiente.
type GradientStop = Color | { color: Color; location: number };
Esempio
const example: GradientStop = { color: '#30B3A2', location: 0.7 };
GradientColors
Colori o stop ordinati; i colori senza posizione sono equidistanti.
type GradientColors = ReadonlyArray<GradientStop>;
Esempio
const example: GradientColors = [
{ color: 'red', location: 0 },
{ color: 'blue', location: 1 },
];
LinearGradientOptions
Gradiente lineare: angle in gradi e center normalizzato; (0.5, 0.5) è il centro.
type LinearGradientOptions = { angle?: number; center?: ViewPoint };
Esempio
const example: LinearGradientOptions = {
angle: 90,
center: { x: 0.5, y: 0.5 },
};
RadialGradientOptions
Gradiente radiale: startRadius/endRadius in punti e center normalizzato.
type RadialGradientOptions = {
startRadius?: number;
endRadius?: number;
center?: ViewPoint;
};
Esempio
const example: RadialGradientOptions = {
startRadius: 0,
endRadius: 60,
center: { x: 0.5, y: 0.5 },
};
AngularGradientOptions
Gradiente angolare: angle in gradi e center normalizzato.
type AngularGradientOptions = { angle?: number; center?: ViewPoint };
Esempio
const example: AngularGradientOptions = {
angle: -90,
center: { x: 0.5, y: 0.5 },
};
Gradient
Gradiente creato da LinearGradient, RadialGradient o AngularGradient, con o senza new.
type Gradient = {
readonly type: 'linear' | 'radial' | 'angular';
readonly angle?: number;
readonly startRadius?: number;
readonly endRadius?: number;
readonly center?: ViewPoint;
readonly colors: GradientColors;
};
Esempio
const example: Gradient = LinearGradient(['red', 'blue'], { angle: 90 });
Paint
Colore di disegno: Color oppure Gradient.
type Paint = Color | Gradient;
Esempio
const example: Paint = RadialGradient(['white', '#30B3A2'], {
endRadius: 60,
});
DrawingEffect
Colore, opacità, raggio di sfocatura e offset x/y dell’effetto; distanze in punti.
type DrawingEffect = {
color?: Color;
opacity?: number;
radius?: number;
x?: number;
y?: number;
};
Esempio
const example: DrawingEffect = {
color: 'cyan',
opacity: 0.6,
radius: 8,
x: 0,
y: 2,
};
ViewTransform
Trasformazione globale senza cambiare il layout. Traslazione in punti, rotazione/inclinazione in gradi, scala 1 invariata, ancoraggi 0–1.
type ViewTransform = {
translateX?: number;
translateY?: number;
scaleX?: number;
scaleY?: number;
rotation?: number;
skewX?: number;
skewY?: number;
anchorX?: number;
anchorY?: number;
};
Esempio
const example: ViewTransform = {
rotation: 30,
scaleX: 1.2,
scaleY: 1.2,
anchorX: 0.5,
anchorY: 0.5,
};
RepeatAxisValue
Numero per gli assi attivi o valori x/y separati.
type RepeatAxisValue = number | { x?: number; y?: number };
Esempio
const example: RepeatAxisValue = { x: 120, y: 80 };
AnimationProperty
Nome di proprietà animabile o percorso annidato; ogni View supporta il proprio sottoinsieme.
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';
Esempio
const example: AnimationProperty = 'transform.rotation';
Animation
Anima le modifiche alle proprietà. duration/delay in secondi; from/to sono estremi; repeat/autoreverse controllano le ripetizioni, wrap il periodo.
type Animation = {
property: AnimationProperty;
duration?: number;
delay?: number;
curve?: string;
from?: number | Color;
to?: number | Color;
repeat?: number | 'forever';
autoreverse?: boolean;
wrap?: number;
};
Esempio
const example: Animation = {
property: 'opacity',
duration: 0.25,
curve: 'easeOut',
};
CircleAnimation
Animazioni curve: sweepAngle senza wrap; startAngle ammette 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;
});
Esempio
const example: CircleAnimation = {
property: 'sweepAngle',
duration: 0.3,
from: 0,
to: 270,
};
EllipseAnimation
Animazioni curve: sweepAngle senza wrap; startAngle ammette 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;
});
Esempio
const example: EllipseAnimation = {
property: 'startAngle',
duration: 0.3,
wrap: 360,
};
ArcAnimation
Animazioni curve: sweepAngle senza wrap; startAngle ammette 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;
});
Esempio
const example: ArcAnimation = {
property: 'sweepAngle',
duration: 0.3,
from: 0,
to: -180,
};
MapAnimation
Anima proprietà supportate di mappa e percorso; la fotocamera usa cameraAnimation separatamente.
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;
});
Esempio
const example: MapAnimation = {
property: 'pathStyle.stroke',
duration: 0.25,
from: 'red',
to: 'blue',
};
LineChartAnimation
Anima intervalli e stili degli assi; intervalli senza wrap, percorsi colore con valori colore.
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;
});
Esempio
const example: LineChartAnimation = { property: 'rangeX.1', duration: 0.25 };
BarChartAnimation
Anima intervalli e stili degli assi; intervalli senza wrap, percorsi colore con valori colore.
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;
});
Esempio
const example: BarChartAnimation = { property: 'rangeY.1', duration: 0.25 };
RadialLayoutAnimation
Animazioni curve: sweepAngle senza wrap; startAngle ammette 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;
});
Esempio
const example: RadialLayoutAnimation = {
property: 'startAngle',
duration: 0.25,
wrap: 360,
};
SpacerAnimation
Spacer anima solo width, height e minLength, senza effetti visivi.
type SpacerAnimation = {
property: 'width' | 'height' | 'minLength';
duration?: number;
delay?: number;
curve?: string;
from?: number;
to?: number;
repeat?: number | 'forever';
autoreverse?: boolean;
wrap?: number;
};
Esempio
const example: SpacerAnimation = {
property: 'minLength',
duration: 0.25,
from: 8,
to: 24,
};
ContentAnimation
Transizione al cambio di contenuto. Scegli un type supportato; duration/delay in secondi.
type ContentAnimation = {
type: 'fade' | 'slide' | 'scale' | 'numericText' | 'interpolate';
duration?: number;
delay?: number;
curve?: string;
direction?: string;
distance?: number;
scale?: number;
};
Esempio
const example: ContentAnimation = { type: 'numericText', duration: 0.18 };
ViewSize
width e height misurati in punti schermo.
type ViewSize = { width: number; height: number };
Esempio
const example: ViewSize = { width: 240, height: 140 };
ViewInsets
Margini top, leading, bottom e trailing in punti.
type ViewInsets = {
top: number;
leading: number;
bottom: number;
trailing: number;
};
Esempio
const example: ViewInsets = {
top: 24,
leading: 12,
bottom: 12,
trailing: 12,
};
CardContentMetrics
size, contentSize, headerSize e safeInsets passati a renderer per collocare il contenuto evitando l’intestazione.
type CardContentMetrics = {
size: ViewSize;
contentSize: ViewSize;
headerSize: ViewSize;
safeInsets: ViewInsets;
};
Esempio
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 },
};