ชนิดข้อมูลทั่วไป

ดูคุณสมบัติของ View ชนิดข้อมูล และตัวอย่างโค้ด

ViewContent

View ค่าพื้นฐานหรืออาร์เรย์ซ้อนที่วาดได้ null/undefined ไม่มีเนื้อหา

type ViewContent =
  View | string | number | boolean | null | undefined | ViewContent[];

ตัวอย่าง

const example: ViewContent = ['Speed', 78, null];

TextContent

แปลงข้อความด้วย toString(); null/undefined เป็นว่าง ใช้ View อื่นประกอบไอคอน

type TextContent =
  | string
  | number
  | bigint
  | boolean
  | symbol
  | { toString(): string }
  | null
  | undefined;

ตัวอย่าง

const example: TextContent = {
  toString() {
    return '78 km/h';
  },
};

HDRColor

ข้อมูลสี HDR สำหรับสีและการไล่ระดับสี

type HDRColor = { readonly $type: 'CapDrive.HDR'; readonly color: string };

ตัวอย่าง

const example: HDRColor = HDR('white');

RGBColor

r/g/b และ a ที่ไม่บังคับอยู่ใน 0–1; space เลือก srgb หรือ displayP3

type RGBColor = {
  space?: 'srgb' | 'displayP3';
  r: number;
  g: number;
  b: number;
  a?: number;
};

ตัวอย่าง

const example: RGBColor = {
  space: 'displayP3',
  r: 0.2,
  g: 0.7,
  b: 0.6,
  a: 0.8,
};

Color

ชื่อสี สตริงฐานสิบหก RGBColor หรือสี HDR()

type Color = string | RGBColor | HDRColor;

ตัวอย่าง

const example: Color = '#30B3A2';

ViewPoint

พิกัด x/y ภายในเป็นพอยต์หน้าจอ ไม่ใช่ละติจูด/ลองจิจูด

type ViewPoint = { x: number; y: number };

ตัวอย่าง

const example: ViewPoint = { x: 20, y: 40 };

ChartDataPoint

value.x/y กำหนดตำแหน่ง label.x/y กำหนดข้อความ y null ทำให้เส้นขาด

type ChartDataPoint = {
  value: { x: number; y: number | null };
  label: { x: string; y: string };
};

ตัวอย่าง

const example: ChartDataPoint = {
  value: { x: 12, y: null },
  label: { x: '12s', y: '' },
};

ChartRange

ช่วงตัวเลข [min, max] ไม่ใช่ดัชนีหรือป้าย

type ChartRange = readonly [min: number, max: number];

ตัวอย่าง

const example: ChartRange = [-20, 100];

MapCoordinate

พิกัด latitude และ longitude เป็นองศา

type MapCoordinate = { latitude: number; longitude: number };

ตัวอย่าง

const example: MapCoordinate = { latitude: 31.2304, longitude: 121.4737 };

MapPathStyle

รูปแบบเส้นทางเนทีฟ: Color ความหนา ปลาย จุดเชื่อม เส้นประ เส้นขอบ และเครื่องหมายเริ่ม/จบ ไม่รองรับไล่สี

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;
};

ตัวอย่าง

const example: MapPathStyle = {
  stroke: '#30B3A2',
  lineWidth: 4,
  outlineStroke: 'white',
  outlineWidth: 1,
  showEndpoints: true,
};

ChartAxisStyle

สี ความหนา ปลายและลายเส้นแกน clear ซ่อนเส้น ป้ายควบคุมแยก

type ChartAxisStyle = {
  stroke?: Paint;
  lineWidth?: number;
  lineCap?: 'round' | 'butt' | 'square';
  dash?: readonly number[];
  dashPhase?: number;
};

ตัวอย่าง

const example: ChartAxisStyle = {
  stroke: '#888888',
  lineWidth: 1,
  dash: [4, 3],
};

BarChartDataPoint

value ของแท่งและ label ที่ไม่บังคับ วางตามลำดับอาร์เรย์

type BarChartDataPoint = { value: number; label?: string };

ตัวอย่าง

const example: BarChartDataPoint = { value: -25, label: 'B' };

PathCommand

คำสั่ง move, line, quad, cubic, arc, close พิกัด/รัศมีเป็นพอยต์ มุมเป็นองศา

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' };

ตัวอย่าง

const example: PathCommand = {
  op: 'cubic',
  x: 100,
  y: 60,
  c1x: 20,
  c1y: 0,
  c2x: 80,
  c2y: 100,
};

GradientStop

สีหรือสีพร้อม location ตั้งแต่ 0 ถึง 1 ในการไล่สี

type GradientStop = Color | { color: Color; location: number };

ตัวอย่าง

const example: GradientStop = { color: '#30B3A2', location: 0.7 };

GradientColors

สีหรือจุดหยุดเรียงลำดับ ถ้าเป็นสีอย่างเดียวจะเว้นเท่ากัน

type GradientColors = ReadonlyArray<GradientStop>;

ตัวอย่าง

const example: GradientColors = [
  { color: 'red', location: 0 },
  { color: 'blue', location: 1 },
];

LinearGradientOptions

ไล่สีเชิงเส้น angle เป็นองศา center เป็นพิกัดสัดส่วน (0.5, 0.5) คือกลาง

type LinearGradientOptions = { angle?: number; center?: ViewPoint };

ตัวอย่าง

const example: LinearGradientOptions = {
  angle: 90,
  center: { x: 0.5, y: 0.5 },
};

RadialGradientOptions

ไล่สีรัศมี startRadius/endRadius เป็นพอยต์ center เป็นพิกัดสัดส่วน

type RadialGradientOptions = {
  startRadius?: number;
  endRadius?: number;
  center?: ViewPoint;
};

ตัวอย่าง

const example: RadialGradientOptions = {
  startRadius: 0,
  endRadius: 60,
  center: { x: 0.5, y: 0.5 },
};

AngularGradientOptions

ไล่สีเชิงมุม angle เป็นองศา center เป็นพิกัดสัดส่วน

type AngularGradientOptions = { angle?: number; center?: ViewPoint };

ตัวอย่าง

const example: AngularGradientOptions = {
  angle: -90,
  center: { x: 0.5, y: 0.5 },
};

Gradient

ไล่สีที่สร้างด้วย LinearGradient, RadialGradient หรือ AngularGradient ใช้หรือไม่ใช้ new ก็ได้

type Gradient = {
  readonly type: 'linear' | 'radial' | 'angular';
  readonly angle?: number;
  readonly startRadius?: number;
  readonly endRadius?: number;
  readonly center?: ViewPoint;
  readonly colors: GradientColors;
};

ตัวอย่าง

const example: Gradient = LinearGradient(['red', 'blue'], { angle: 90 });

Paint

สีสำหรับวาดเป็น Color หรือ Gradient

type Paint = Color | Gradient;

ตัวอย่าง

const example: Paint = RadialGradient(['white', '#30B3A2'], {
  endRadius: 60,
});

DrawingEffect

สี ความทึบ รัศมีเบลอ และระยะ x/y ของเอฟเฟกต์ ระยะเป็นพอยต์

type DrawingEffect = {
  color?: Color;
  opacity?: number;
  radius?: number;
  x?: number;
  y?: number;
};

ตัวอย่าง

const example: DrawingEffect = {
  color: 'cyan',
  opacity: 0.6,
  radius: 8,
  x: 0,
  y: 2,
};

ViewTransform

แปลงทั้ง View โดยไม่เปลี่ยนเลย์เอาต์ ระยะเลื่อนเป็นพอยต์ หมุน/เอียงเป็นองศา สเกล 1 ไม่เปลี่ยน จุดยึด 0–1

type ViewTransform = {
  translateX?: number;
  translateY?: number;
  scaleX?: number;
  scaleY?: number;
  rotation?: number;
  skewX?: number;
  skewY?: number;
  anchorX?: number;
  anchorY?: number;
};

ตัวอย่าง

const example: ViewTransform = {
  rotation: 30,
  scaleX: 1.2,
  scaleY: 1.2,
  anchorX: 0.5,
  anchorY: 0.5,
};

RepeatAxisValue

ตัวเลขใช้กับแกนที่เปิดอยู่ หรือระบุ x/y แยกกัน

type RepeatAxisValue = number | { x?: number; y?: number };

ตัวอย่าง

const example: RepeatAxisValue = { x: 120, y: 80 };

AnimationProperty

ชื่อคุณสมบัติหรือเส้นทางซ้อนที่ทำแอนิเมชันได้ แต่ละ View รองรับต่างกัน

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';

ตัวอย่าง

const example: AnimationProperty = 'transform.rotation';

Animation

แอนิเมชันเมื่อคุณสมบัติเปลี่ยน duration/delay เป็นวินาที from/to เป็นปลายทาง repeat/autoreverse ควบคุมการซ้ำ wrap เป็นคาบ

type Animation = {
  property: AnimationProperty;
  duration?: number;
  delay?: number;
  curve?: string;
  from?: number | Color;
  to?: number | Color;
  repeat?: number | 'forever';
  autoreverse?: boolean;
  wrap?: number;
};

ตัวอย่าง

const example: Animation = {
  property: 'opacity',
  duration: 0.25,
  curve: 'easeOut',
};

CircleAnimation

แอนิเมชันรูปโค้ง sweepAngle ไม่รองรับ wrap; startAngle ใช้ 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;
    });

ตัวอย่าง

const example: CircleAnimation = {
  property: 'sweepAngle',
  duration: 0.3,
  from: 0,
  to: 270,
};

EllipseAnimation

แอนิเมชันรูปโค้ง sweepAngle ไม่รองรับ wrap; startAngle ใช้ 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;
    });

ตัวอย่าง

const example: EllipseAnimation = {
  property: 'startAngle',
  duration: 0.3,
  wrap: 360,
};

ArcAnimation

แอนิเมชันรูปโค้ง sweepAngle ไม่รองรับ wrap; startAngle ใช้ 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;
    });

ตัวอย่าง

const example: ArcAnimation = {
  property: 'sweepAngle',
  duration: 0.3,
  from: 0,
  to: -180,
};

MapAnimation

แอนิเมชันคุณสมบัติแผนที่และเส้นทางที่รองรับ กล้องใช้ cameraAnimation แยก

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;
    });

ตัวอย่าง

const example: MapAnimation = {
  property: 'pathStyle.stroke',
  duration: 0.25,
  from: 'red',
  to: 'blue',
};

LineChartAnimation

แอนิเมชันช่วงและรูปแบบแกน ช่วงไม่ใช้ wrap เส้นทางสีใช้ค่าสี

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;
    });

ตัวอย่าง

const example: LineChartAnimation = { property: 'rangeX.1', duration: 0.25 };

BarChartAnimation

แอนิเมชันช่วงและรูปแบบแกน ช่วงไม่ใช้ wrap เส้นทางสีใช้ค่าสี

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;
    });

ตัวอย่าง

const example: BarChartAnimation = { property: 'rangeY.1', duration: 0.25 };

RadialLayoutAnimation

แอนิเมชันรูปโค้ง sweepAngle ไม่รองรับ wrap; startAngle ใช้ 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;
    });

ตัวอย่าง

const example: RadialLayoutAnimation = {
  property: 'startAngle',
  duration: 0.25,
  wrap: 360,
};

SpacerAnimation

Spacer ทำแอนิเมชันเฉพาะ width, height, minLength ไม่มีเอฟเฟกต์ภาพ

type SpacerAnimation = {
  property: 'width' | 'height' | 'minLength';
  duration?: number;
  delay?: number;
  curve?: string;
  from?: number;
  to?: number;
  repeat?: number | 'forever';
  autoreverse?: boolean;
  wrap?: number;
};

ตัวอย่าง

const example: SpacerAnimation = {
  property: 'minLength',
  duration: 0.25,
  from: 8,
  to: 24,
};

ContentAnimation

เอฟเฟกต์เมื่อเนื้อหาเปลี่ยน ใช้ type ที่ View รองรับ duration/delay เป็นวินาที

type ContentAnimation = {
  type: 'fade' | 'slide' | 'scale' | 'numericText' | 'interpolate';
  duration?: number;
  delay?: number;
  curve?: string;
  direction?: string;
  distance?: number;
  scale?: number;
};

ตัวอย่าง

const example: ContentAnimation = { type: 'numericText', duration: 0.18 };

ViewSize

width และ height ที่วัดได้เป็นพอยต์หน้าจอ

type ViewSize = { width: number; height: number };

ตัวอย่าง

const example: ViewSize = { width: 240, height: 140 };

ViewInsets

ระยะขอบ top, leading, bottom, trailing เป็นพอยต์

type ViewInsets = {
  top: number;
  leading: number;
  bottom: number;
  trailing: number;
};

ตัวอย่าง

const example: ViewInsets = {
  top: 24,
  leading: 12,
  bottom: 12,
  trailing: 12,
};

CardContentMetrics

size, contentSize, headerSize และ safeInsets ที่ส่งให้ renderer ใช้จัดเนื้อหาหลบหัวเรื่อง

type CardContentMetrics = {
  size: ViewSize;
  contentSize: ViewSize;
  headerSize: ViewSize;
  safeInsets: ViewInsets;
};

ตัวอย่าง

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 },
};