Kiểu dùng chung
Tra cứu thuộc tính View, kiểu dữ liệu và ví dụ mã.
ViewContent
Views, giá trị cơ bản hoặc mảng lồng nhau; null/undefined không tạo nội dung.
type ViewContent =
View | string | number | boolean | null | undefined | ViewContent[];
Ví dụ
const example: ViewContent = ['Speed', 78, null];
TextContent
Chữ được đổi bằng toString(); null/undefined để trống. Ghép biểu tượng bằng Views khác.
type TextContent =
| string
| number
| bigint
| boolean
| symbol
| { toString(): string }
| null
| undefined;
Ví dụ
const example: TextContent = {
toString() {
return '78 km/h';
},
};
HDRColor
Dữ liệu màu HDR cho màu vẽ và chuyển màu.
type HDRColor = { readonly $type: 'CapDrive.HDR'; readonly color: string };
Ví dụ
const example: HDRColor = HDR('white');
RGBColor
r/g/b và a tùy chọn trong 0–1; space chọn srgb hoặc displayP3.
type RGBColor = {
space?: 'srgb' | 'displayP3';
r: number;
g: number;
b: number;
a?: number;
};
Ví dụ
const example: RGBColor = {
space: 'displayP3',
r: 0.2,
g: 0.7,
b: 0.6,
a: 0.8,
};
Color
Tên màu, chuỗi thập lục phân, RGBColor hoặc màu HDR().
type Color = string | RGBColor | HDRColor;
Ví dụ
const example: Color = '#30B3A2';
ViewPoint
Tọa độ x/y cục bộ theo điểm màn hình, không phải vĩ độ/kinh độ.
type ViewPoint = { x: number; y: number };
Ví dụ
const example: ViewPoint = { x: 20, y: 40 };
ChartDataPoint
value.x/y xác định vị trí, label.x/y là chữ; y null ngắt đường.
type ChartDataPoint = {
value: { x: number; y: number | null };
label: { x: string; y: string };
};
Ví dụ
const example: ChartDataPoint = {
value: { x: 12, y: null },
label: { x: '12s', y: '' },
};
ChartRange
Khoảng số [min, max], không phải chỉ số hay nhãn.
type ChartRange = readonly [min: number, max: number];
Ví dụ
const example: ChartRange = [-20, 100];
MapCoordinate
Vĩ độ latitude và kinh độ longitude theo độ.
type MapCoordinate = { latitude: number; longitude: number };
Ví dụ
const example: MapCoordinate = { latitude: 31.2304, longitude: 121.4737 };
MapPathStyle
Kiểu tuyến đường gốc: Color, độ rộng, đầu nét, nối nét, nét đứt, viền và dấu đầu/cuối tùy chọn. Không hỗ trợ chuyển sắc.
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;
};
Ví dụ
const example: MapPathStyle = {
stroke: '#30B3A2',
lineWidth: 4,
outlineStroke: 'white',
outlineWidth: 1,
showEndpoints: true,
};
ChartAxisStyle
Màu, độ dày, đầu nét và nét đứt của trục. clear ẩn đường; nhãn điều khiển riêng.
type ChartAxisStyle = {
stroke?: Paint;
lineWidth?: number;
lineCap?: 'round' | 'butt' | 'square';
dash?: readonly number[];
dashPhase?: number;
};
Ví dụ
const example: ChartAxisStyle = {
stroke: '#888888',
lineWidth: 1,
dash: [4, 3],
};
BarChartDataPoint
value số và label tùy chọn cho một cột; vị trí theo thứ tự mảng.
type BarChartDataPoint = { value: number; label?: string };
Ví dụ
const example: BarChartDataPoint = { value: -25, label: 'B' };
PathCommand
Lệnh move, line, quad, cubic, arc, close. Tọa độ/bán kính theo điểm, góc theo độ.
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' };
Ví dụ
const example: PathCommand = {
op: 'cubic',
x: 100,
y: 60,
c1x: 20,
c1y: 0,
c2x: 80,
c2y: 100,
};
GradientStop
Màu hoặc màu có location 0–1 trong chuyển màu.
type GradientStop = Color | { color: Color; location: number };
Ví dụ
const example: GradientStop = { color: '#30B3A2', location: 0.7 };
GradientColors
Các màu/điểm dừng có thứ tự; màu không có vị trí được chia đều.
type GradientColors = ReadonlyArray<GradientStop>;
Ví dụ
const example: GradientColors = [
{ color: 'red', location: 0 },
{ color: 'blue', location: 1 },
];
LinearGradientOptions
Chuyển màu tuyến tính: angle theo độ, center chuẩn hóa; (0.5, 0.5) là tâm.
type LinearGradientOptions = { angle?: number; center?: ViewPoint };
Ví dụ
const example: LinearGradientOptions = {
angle: 90,
center: { x: 0.5, y: 0.5 },
};
RadialGradientOptions
Chuyển màu xuyên tâm: startRadius/endRadius theo điểm, center chuẩn hóa.
type RadialGradientOptions = {
startRadius?: number;
endRadius?: number;
center?: ViewPoint;
};
Ví dụ
const example: RadialGradientOptions = {
startRadius: 0,
endRadius: 60,
center: { x: 0.5, y: 0.5 },
};
AngularGradientOptions
Chuyển màu góc: angle theo độ, center chuẩn hóa.
type AngularGradientOptions = { angle?: number; center?: ViewPoint };
Ví dụ
const example: AngularGradientOptions = {
angle: -90,
center: { x: 0.5, y: 0.5 },
};
Gradient
Chuyển màu từ LinearGradient, RadialGradient hoặc AngularGradient, có hoặc không có new.
type Gradient = {
readonly type: 'linear' | 'radial' | 'angular';
readonly angle?: number;
readonly startRadius?: number;
readonly endRadius?: number;
readonly center?: ViewPoint;
readonly colors: GradientColors;
};
Ví dụ
const example: Gradient = LinearGradient(['red', 'blue'], { angle: 90 });
Paint
Màu vẽ là Color hoặc Gradient.
type Paint = Color | Gradient;
Ví dụ
const example: Paint = RadialGradient(['white', '#30B3A2'], {
endRadius: 60,
});
DrawingEffect
Màu, độ đục, bán kính mờ và độ lệch x/y của hiệu ứng; khoảng cách theo điểm.
type DrawingEffect = {
color?: Color;
opacity?: number;
radius?: number;
x?: number;
y?: number;
};
Ví dụ
const example: DrawingEffect = {
color: 'cyan',
opacity: 0.6,
radius: 8,
x: 0,
y: 2,
};
ViewTransform
Biến đổi toàn View không đổi bố cục. Dịch chuyển theo điểm, xoay/nghiêng theo độ, tỷ lệ 1 giữ nguyên, điểm neo 0–1.
type ViewTransform = {
translateX?: number;
translateY?: number;
scaleX?: number;
scaleY?: number;
rotation?: number;
skewX?: number;
skewY?: number;
anchorX?: number;
anchorY?: number;
};
Ví dụ
const example: ViewTransform = {
rotation: 30,
scaleX: 1.2,
scaleY: 1.2,
anchorX: 0.5,
anchorY: 0.5,
};
RepeatAxisValue
Một số cho các trục hoạt động hoặc x/y riêng từng trục.
type RepeatAxisValue = number | { x?: number; y?: number };
Ví dụ
const example: RepeatAxisValue = { x: 120, y: 80 };
AnimationProperty
Tên thuộc tính hoạt ảnh hoặc đường dẫn lồng nhau; mỗi View có tập hỗ trợ riêng.
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';
Ví dụ
const example: AnimationProperty = 'transform.rotation';
Animation
Hoạt ảnh khi thuộc tính đổi. duration/delay theo giây; from/to là đầu cuối; repeat/autoreverse điều khiển lặp, wrap là chu kỳ.
type Animation = {
property: AnimationProperty;
duration?: number;
delay?: number;
curve?: string;
from?: number | Color;
to?: number | Color;
repeat?: number | 'forever';
autoreverse?: boolean;
wrap?: number;
};
Ví dụ
const example: Animation = {
property: 'opacity',
duration: 0.25,
curve: 'easeOut',
};
CircleAnimation
Hoạt ảnh hình cong: sweepAngle không dùng wrap; startAngle cho phép 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;
});
Ví dụ
const example: CircleAnimation = {
property: 'sweepAngle',
duration: 0.3,
from: 0,
to: 270,
};
EllipseAnimation
Hoạt ảnh hình cong: sweepAngle không dùng wrap; startAngle cho phép 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;
});
Ví dụ
const example: EllipseAnimation = {
property: 'startAngle',
duration: 0.3,
wrap: 360,
};
ArcAnimation
Hoạt ảnh hình cong: sweepAngle không dùng wrap; startAngle cho phép 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;
});
Ví dụ
const example: ArcAnimation = {
property: 'sweepAngle',
duration: 0.3,
from: 0,
to: -180,
};
MapAnimation
Hoạt ảnh thuộc tính bản đồ và tuyến đường được hỗ trợ; camera dùng cameraAnimation riêng.
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;
});
Ví dụ
const example: MapAnimation = {
property: 'pathStyle.stroke',
duration: 0.25,
from: 'red',
to: 'blue',
};
LineChartAnimation
Hoạt ảnh khoảng và kiểu trục; khoảng không dùng wrap, đường dẫn màu nhận màu.
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;
});
Ví dụ
const example: LineChartAnimation = { property: 'rangeX.1', duration: 0.25 };
BarChartAnimation
Hoạt ảnh khoảng và kiểu trục; khoảng không dùng wrap, đường dẫn màu nhận màu.
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;
});
Ví dụ
const example: BarChartAnimation = { property: 'rangeY.1', duration: 0.25 };
RadialLayoutAnimation
Hoạt ảnh hình cong: sweepAngle không dùng wrap; startAngle cho phép 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;
});
Ví dụ
const example: RadialLayoutAnimation = {
property: 'startAngle',
duration: 0.25,
wrap: 360,
};
SpacerAnimation
Spacer chỉ tạo hoạt ảnh width, height, minLength, không có hiệu ứng hình ảnh.
type SpacerAnimation = {
property: 'width' | 'height' | 'minLength';
duration?: number;
delay?: number;
curve?: string;
from?: number;
to?: number;
repeat?: number | 'forever';
autoreverse?: boolean;
wrap?: number;
};
Ví dụ
const example: SpacerAnimation = {
property: 'minLength',
duration: 0.25,
from: 8,
to: 24,
};
ContentAnimation
Chuyển tiếp khi nội dung đổi. Chọn type được hỗ trợ; duration/delay theo giây.
type ContentAnimation = {
type: 'fade' | 'slide' | 'scale' | 'numericText' | 'interpolate';
duration?: number;
delay?: number;
curve?: string;
direction?: string;
distance?: number;
scale?: number;
};
Ví dụ
const example: ContentAnimation = { type: 'numericText', duration: 0.18 };
ViewSize
width và height đã đo theo điểm màn hình.
type ViewSize = { width: number; height: number };
Ví dụ
const example: ViewSize = { width: 240, height: 140 };
ViewInsets
Lề top, leading, bottom, trailing theo điểm.
type ViewInsets = {
top: number;
leading: number;
bottom: number;
trailing: number;
};
Ví dụ
const example: ViewInsets = {
top: 24,
leading: 12,
bottom: 12,
trailing: 12,
};
CardContentMetrics
size, contentSize, headerSize, safeInsets truyền vào renderer để đặt nội dung tránh tiêu đề.
type CardContentMetrics = {
size: ViewSize;
contentSize: ViewSize;
headerSize: ViewSize;
safeInsets: ViewInsets;
};
Ví dụ
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 },
};