Skip to content

Commit 61fc91a

Browse files
committed
Add documentation
1 parent b434968 commit 61fc91a

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed
-1.78 KB
Binary file not shown.

docs/docs/shapes/polygons.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,37 @@ const RectDemo = () => {
5959
};
6060
```
6161

62-
![Rounded Rectangle](assets/polygons/rect.png)
62+
<img src={require("/static/img/rrect/uniform.png").default} width="256" height="256" />
63+
64+
### Using Custom Radii
65+
66+
You can set a different corner radius for each corner.
67+
68+
```tsx twoslash
69+
import { Canvas, RoundedRect } from "@shopify/react-native-skia";
70+
71+
const RectDemo = () => {
72+
const size = 256;
73+
const r = size * 0.2;
74+
const rrct = {
75+
rect: { x: 0, y: 0, width: size, height: size },
76+
topLeft: { x: 0, y: 0 },
77+
topRight: { x: r, y: r },
78+
bottomRight: { x: 0, y: 0 },
79+
bottomLeft: { x: r, y: r },
80+
};
81+
return (
82+
<Canvas style={{ width: size, height: size }}>
83+
<RoundedRect
84+
rect={rrct}
85+
color="lightblue"
86+
/>
87+
</Canvas>
88+
);
89+
};
90+
```
91+
92+
<img src={require("/static/img/rrect/nonuniform.png").default} width="256" height="256" />
6393

6494
## DiffRect
6595

package/src/renderer/__tests__/e2e/Rect.spec.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22

33
import { checkImage, docPath } from "../../../__tests__/setup";
4-
import { RoundedRect } from "../../components";
4+
import { Path, RoundedRect } from "../../components";
55
import { importSkia, surface } from "../setup";
66

77
describe("Rects and rounded rects", () => {
@@ -70,7 +70,17 @@ describe("Rects and rounded rects", () => {
7070
);
7171
checkImage(image, docPath("rrect/uniform.png"));
7272
});
73-
it("Should draw a rounded rect with non-uniform values", async () => {
73+
it("Should draw a rounded rect with uniform values (4)", async () => {
74+
const { width } = surface;
75+
const r = width * 0.2;
76+
const { Skia } = importSkia();
77+
const rrct = Skia.RRectXY(Skia.XYWHRect(0, 0, width, width), r, r);
78+
const path = Skia.Path.Make();
79+
path.addRRect(rrct);
80+
const image = await surface.draw(<Path path={path} color="lightblue" />);
81+
checkImage(image, docPath("rrect/uniform.png"));
82+
});
83+
it("Should draw a rounded rect with non-uniform values (1)", async () => {
7484
const { width } = surface;
7585
const r = width * 0.2;
7686
const rrct = {
@@ -85,4 +95,20 @@ describe("Rects and rounded rects", () => {
8595
);
8696
checkImage(image, docPath("rrect/nonuniform.png"));
8797
});
98+
it("Should draw a rounded rect with non-uniform values (2)", async () => {
99+
const { Skia } = importSkia();
100+
const { width } = surface;
101+
const r = width * 0.2;
102+
const rrct = {
103+
rect: { x: 0, y: 0, width, height: width },
104+
topLeft: { x: 0, y: 0 },
105+
topRight: { x: r, y: r },
106+
bottomRight: { x: 0, y: 0 },
107+
bottomLeft: { x: r, y: r },
108+
};
109+
const path = Skia.Path.Make();
110+
path.addRRect(rrct);
111+
const image = await surface.draw(<Path path={path} color="lightblue" />);
112+
checkImage(image, docPath("rrect/nonuniform.png"));
113+
});
88114
});

0 commit comments

Comments
 (0)