Path
通過 move、line、quad、cubic、arc 和 close 等命令構建路徑。適合自定義指針、曲線和組合輪廓,可設定填充規則與描邊。
範例
function main() {
return (
<Path
commands={[
{ op: 'move', x: 10, y: 80 },
{ op: 'line', x: 60, y: 10 },
{ op: 'line', x: 110, y: 80 },
{ op: 'close' },
]}
background={$env.accent}
stroke={$env.foreground}
lineWidth={2}
/>
);
}
使用說明
- commands 依序執行:move 開子路徑,line/quad/cubic/arc 加線段,close 閉合。arc 的 x/y 是圓心;evenOdd 可在巢狀輪廓挖孔。回到起點不等同 close。
- contentAnimation 過渡文字、圖片或結構資料。interpolate 要求 Polyline 點數/closed、Path 命令序列或圖表結構相容;結構變動時直接更新。
屬性
commandsReadonlyArray<PathCommand>局部路徑命令,單位為 pt。空陣列不繪製。
[{op: "move", x: 0, y: 0}, {op: "line", x: 100, y: 80}]fillRule?"nonZero" | "evenOdd"路徑填滿規則:nonZero 或 evenOdd。
"nonZero"background?Paint路徑內部的填滿筆刷,預設透明。
"clear"stroke?Paint描邊可用顏色或漸層;clear 隱藏描邊。
HDR($env.dark ? "white" : "black")lineWidth?number描邊寬度,單位為點;0 不繪製。
2lineCap?"round" | "butt" | "square"線端:butt 截斷、square 延伸方頭、round 圓頭。
"round"lineJoin?"round" | "miter" | "bevel"線段接點:miter 尖角、round 圓角、bevel 斜角。
"round"dash?number[]交替實線及空白的長度,單位為點;空陣列為實線。
[]dashPhase?number虛線樣式沿路徑的位移,單位為點。
0trimStart?numbertrimStart 至 trimEnd 控制 0–1 的可見路徑;Circle/Ellipse/Arc 使用角度。
0trimEnd?numbertrimStart 至 trimEnd 控制 0–1 的可見路徑;Circle/Ellipse/Arc 使用角度。
1contentAnimation?ContentAnimation可選內容過渡。interpolate 要求命令數量和操作順序相同,否則直接更新。
{type: "interpolate", duration: 0.25}通用屬性
width?number | "auto" | "fill"寬度:點數、自動測量或填滿父區域。
"fill"height?number | "auto" | "fill"高度:點數、自動測量或填滿父區域。
"fill"x?number視覺位移,單位為點:x 向右、y 向下,不改變版面佔位。
0y?number視覺位移,單位為點:x 向右、y 向下,不改變版面佔位。
0transform?ViewTransform整體視覺變換不改變版面。平移用點,旋轉及傾斜用度,縮放 1 不變,錨點用 0–1。
{rotation: 0}opacity?number整個 View 的不透明度:0 完全透明,1 完全不透明。
1clipped?boolean是否裁切超出 View 邊界的內容。
falseclip?"rectangle" | "ellipse"裁切形狀:rectangle 矩形或 ellipse 橢圓;Material 另可用 false 停用。
"rectangle"mask?View | null透明度遮罩 View,置中顯示且不影響佈局;null 表示不使用遮罩。
<Circle width="fill" height="fill" background="white"/>zIndex?number同層 View 的繪製順序,數值越大越靠前。
0blur?number模糊半徑,單位為點;0 不模糊。
4innerShadow?DrawingEffect特效的顏色、不透明度、模糊半徑及 x/y 位移;距離用點。
{color: HDR("black"), opacity: 0.5, radius: 4, x: 0, y: 2}glow?DrawingEffect特效的顏色、不透明度、模糊半徑及 x/y 位移;距離用點。
{color: HDR("cyan"), radius: 8, opacity: 0.8}shadowColor?Color外部陰影顏色。
HDR("black")shadowOpacity?number外部陰影不透明度 0–1;0 隱藏陰影。
0shadowRadius?number外部陰影模糊半徑,單位為點。
4shadowX?number外部陰影位移,單位為點:x 向右、y 向下。
0shadowY?number外部陰影位移,單位為點:x 向右、y 向下。
2animations?Animation[]屬性改變時播放動畫。duration/delay 用秒,from/to 設端點,repeat/autoreverse 控制重複,wrap 設週期。
[{property: "opacity", duration: 0.25, curve: "easeInOut"}]key?string | number兄弟節點中的穩定識別碼。
組合範例
function main() {
return (
<Path
width={140}
height={100}
fillRule="evenOdd"
background={$env.accent}
commands={[
{ op: 'move', x: 0, y: 0 },
{ op: 'line', x: 140, y: 0 },
{ op: 'line', x: 140, y: 100 },
{ op: 'line', x: 0, y: 100 },
{ op: 'close' },
{ op: 'move', x: 35, y: 25 },
{ op: 'line', x: 105, y: 25 },
{ op: 'line', x: 105, y: 75 },
{ op: 'line', x: 35, y: 75 },
{ op: 'close' },
]}
/>
);
}
動畫
widthheightxyopacitybackgroundblurshadowColorshadowOpacityshadowRadiusshadowXshadowYtrimStarttrimEnddashPhasestrokelineWidthtransform.translateXtransform.translateYtransform.scaleXtransform.scaleYtransform.rotationtransform.skewXtransform.skewYtransform.anchorXtransform.anchorY省略時的行為
下表是經實作核對的省略行為;屬性範例不是預設值。固定效果應明確傳值,尺寸和主題色等依環境變動,不能視為常數。
| 屬性 | 省略時的行為 |
|---|---|
commands | [] |
fillRule | "nonZero" |
background | "clear" |
lineWidth | 2 |
stroke | HDR($env.dark ? 'white' : 'black') |