diff --git a/docs/docs/shapes/polygons.md b/docs/docs/shapes/polygons.md index 42cf8703e7..57153575fd 100644 --- a/docs/docs/shapes/polygons.md +++ b/docs/docs/shapes/polygons.md @@ -9,37 +9,31 @@ slug: /shapes/polygons Draws a rectangle. -| Name | Type | Description | -|:-------|:---------|:--------------------------------------------------------------| -| x | `number` | X coordinate. | -| y | `number` | Y coordinate. | -| width | `number` | Width of the rectangle. | -| height | `number` | Height of the rectangle. | +| Name | Type | Description | +| :----- | :------- | :----------------------- | +| x | `number` | X coordinate. | +| y | `number` | Y coordinate. | +| width | `number` | Width of the rectangle. | +| height | `number` | Height of the rectangle. | ```tsx twoslash -import {Canvas, Rect} from "@shopify/react-native-skia"; +import { Canvas, Rect } from "@shopify/react-native-skia"; const RectDemo = () => { return ( - - + + ); }; ``` -## RRect +## RoundRect Draws a rounded rectangle. -| Name | Type | Description | -|:-------|:---------|:--------------------------------------------------------------| +| Name | Type | Description | +| :----- | :------- | :------------------------------------------------------------ | | x | `number` | X coordinate. | | y | `number` | Y coordinate. | | width | `number` | Width of the rectangle. | @@ -48,12 +42,12 @@ Draws a rounded rectangle. | ry? | `number` | Vertical corner radius. Defaults to `rx` if specified or 0. | ```tsx twoslash -import {Canvas, RRect} from "@shopify/react-native-skia"; +import { Canvas, RoundRect } from "@shopify/react-native-skia"; const RectDemo = () => { return ( - - + { ![Rounded Rectangle](assets/polygons/rect.png) -## DRect +## DiffRect Draws the difference between two rectangles. -| Name | Type | Description | -|:-------|:--------------|:-----------------| -| outer | `RectOrRRect` | Outer rectangle. | -| inner | `RectOrRRect` | Inner rectangle. | +| Name | Type | Description | +| :---- | :------------ | :--------------- | +| outer | `RectOrRRect` | Outer rectangle. | +| inner | `RectOrRRect` | Inner rectangle. | ```tsx twoslash -import {Canvas, DRect, rect, rrect} from "@shopify/react-native-skia"; +import { Canvas, DiffRect, rect, rrect } from "@shopify/react-native-skia"; const DRectDemo = () => { const outer = rrect(rect(0, 0, 256, 256), 25, 25); - const inner = rrect( - rect(50, 50, 256 - 100, 256 - 100), - 50, - 50 - ); + const inner = rrect(rect(50, 50, 256 - 100, 256 - 100), 50, 50); return ( - - + + ); }; @@ -101,17 +91,17 @@ const DRectDemo = () => { Draws a line between two points. -| Name | Type | Description | -|:-----|:--------|:-----------------| -| p1 | `Point` | Start point. | -| p2 | `Point` | End point. | +| Name | Type | Description | +| :--- | :------ | :----------- | +| p1 | `Point` | Start point. | +| p2 | `Point` | End point. | ```tsx twoslash -import {Canvas, Line, vec} from "@shopify/react-native-skia"; +import { Canvas, Line, vec } from "@shopify/react-native-skia"; const LineDemo = () => { return ( - + { Draws points and optionally draws the connection between them. -| Name | Type | Description | -|:-------|:------------|:-----------------| -| points | `Point` | Points to draw. | -| mode | `PointMode` | How should the points be connected. Can be `points` (no connection), `lines` (connect pairs of points), or `polygon` (connect lines). Default is `points`. | +| Name | Type | Description | +| :----- | :---------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- | +| points | `Point` | Points to draw. | +| mode | `PointMode` | How should the points be connected. Can be `points` (no connection), `lines` (connect pairs of points), or `polygon` (connect lines). Default is `points`. | ```tsx twoslash -import {Canvas, Points, vec} from "@shopify/react-native-skia"; +import { Canvas, Points, vec } from "@shopify/react-native-skia"; const PointsDemo = () => { const points = [ diff --git a/example/src/Examples/API/Shapes2.tsx b/example/src/Examples/API/Shapes2.tsx index 78ae7a01bd..8c5855fd69 100644 --- a/example/src/Examples/API/Shapes2.tsx +++ b/example/src/Examples/API/Shapes2.tsx @@ -5,7 +5,7 @@ import { PaintStyle, Canvas, Rect, - DRect, + DiffRect, Group, Oval, Line, @@ -16,7 +16,7 @@ import { rrect, Paint, DashPathEffect, - RRect, + RoundRect, } from "@shopify/react-native-skia"; import { Title } from "./components/Title"; @@ -66,14 +66,14 @@ export const Shapes = () => { - - + Ovals & Circles diff --git a/package/src/renderer/components/shapes/DRect.tsx b/package/src/renderer/components/shapes/DiffRect.tsx similarity index 79% rename from package/src/renderer/components/shapes/DRect.tsx rename to package/src/renderer/components/shapes/DiffRect.tsx index 166b38b433..0545dc05e6 100644 --- a/package/src/renderer/components/shapes/DRect.tsx +++ b/package/src/renderer/components/shapes/DiffRect.tsx @@ -5,12 +5,12 @@ import type { IRRect } from "../../../skia/RRect"; import type { AnimatedProps } from "../../processors/Animations/Animations"; import { useDrawing } from "../../nodes/Drawing"; -export interface DRectProps extends CustomPaintProps { +export interface DiffRectProps extends CustomPaintProps { inner: IRRect; outer: IRRect; } -export const DRect = (props: AnimatedProps) => { +export const DiffRect = (props: AnimatedProps) => { const onDraw = useDrawing(props, ({ canvas, paint }, { inner, outer }) => { canvas.drawDRRect(outer, inner, paint); }); diff --git a/package/src/renderer/components/shapes/Rect.tsx b/package/src/renderer/components/shapes/Rect.tsx index a63ce6d6b6..126d229769 100644 --- a/package/src/renderer/components/shapes/Rect.tsx +++ b/package/src/renderer/components/shapes/Rect.tsx @@ -16,9 +16,9 @@ export const Rect = (props: AnimatedProps) => { return ; }; -export type RRectProps = RRectDef & CustomPaintProps; +export type RoundRectProps = RRectDef & CustomPaintProps; -export const RRect = (props: AnimatedProps) => { +export const RoundRect = (props: AnimatedProps) => { const onDraw = useDrawing(props, ({ canvas, paint }, rectProps) => { const rrect = processRRect(rectProps); canvas.drawRRect(rrect, paint); diff --git a/package/src/renderer/components/shapes/index.ts b/package/src/renderer/components/shapes/index.ts index 4331661805..eff5a399dd 100644 --- a/package/src/renderer/components/shapes/index.ts +++ b/package/src/renderer/components/shapes/index.ts @@ -1,6 +1,6 @@ export * from "./Circle"; export * from "./Rect"; -export * from "./DRect"; +export * from "./DiffRect"; export * from "./Line"; export * from "./Path"; export * from "./Oval";