Skip to content

Commit c406cf0

Browse files
authored
Merge pull request #1086 from Shopify/remove/use-picture
Remove usePicture deprecation
2 parents 56d7ff0 + 66c6017 commit c406cf0

File tree

4 files changed

+20
-40
lines changed

4 files changed

+20
-40
lines changed

docs/docs/Picture.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ A Picture renders a previously recorded list of drawing operations on the canvas
1616
```tsx twoslash
1717
import React, { useMemo } from "react";
1818
import {
19-
usePicture,
19+
createPicture,
2020
Canvas,
2121
Picture,
2222
Skia,
@@ -25,7 +25,7 @@ import {
2525

2626
export const PictureExample = () => {
2727
// Create picture
28-
const picture = usePicture(
28+
const picture = useMemo(() => createPicture(
2929
{ x: 0, y: 0, width: 100, height: 100 },
3030
(canvas) => {
3131
const paint = Skia.Paint();
@@ -36,7 +36,7 @@ export const PictureExample = () => {
3636
circlePaint.setColor(Skia.Color("orange"));
3737
canvas.drawCircle(50, 50, 50, circlePaint);
3838
}
39-
);
39+
), []);
4040

4141
// Serialize the picture
4242
const serialized = useMemo(() => picture.serialize(), [picture]);

example/src/Examples/API/PictureView.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
import React from "react";
1+
import React, { useMemo } from "react";
22
import { StyleSheet } from "react-native";
3-
import { usePicture, Skia, SkiaPictureView } from "@shopify/react-native-skia";
3+
import {
4+
createPicture,
5+
Skia,
6+
SkiaPictureView,
7+
} from "@shopify/react-native-skia";
48

59
export const PictureViewExample = () => {
610
// Create picture
7-
const picture = usePicture(
8-
{ x: 0, y: 0, width: 100, height: 100 },
9-
(canvas) => {
10-
const paint = Skia.Paint();
11-
paint.setColor(Skia.Color("pink"));
12-
canvas.drawRect({ x: 0, y: 0, width: 100, height: 100 }, paint);
11+
const picture = useMemo(
12+
() =>
13+
createPicture({ x: 0, y: 0, width: 100, height: 100 }, (canvas) => {
14+
const paint = Skia.Paint();
15+
paint.setColor(Skia.Color("pink"));
16+
canvas.drawRect({ x: 0, y: 0, width: 100, height: 100 }, paint);
1317

14-
const circlePaint = Skia.Paint();
15-
circlePaint.setColor(Skia.Color("orange"));
16-
canvas.drawCircle(50, 50, 50, circlePaint);
17-
}
18+
const circlePaint = Skia.Paint();
19+
circlePaint.setColor(Skia.Color("orange"));
20+
canvas.drawCircle(50, 50, 50, circlePaint);
21+
}),
22+
[]
1823
);
1924

2025
return <SkiaPictureView style={styles.container} picture={picture} debug />;

package/src/mock/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export const Mock: typeof SkiaExports &
5353
useTypeface: Noop,
5454
useImage: Noop,
5555
useSVG: Noop,
56-
usePicture: Noop,
5756
createPicture: Noop,
5857
// 3. Point/Rect/Transform utilities
5958
vec,

package/src/skia/core/Picture.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
1-
import type { DependencyList } from "react";
2-
import { useMemo } from "react";
3-
41
import { Skia } from "../Skia";
52
import type { SkCanvas, SkRect } from "../types";
63

7-
/**
8-
* Memoizes and returns an SkPicture that can be drawn to another canvas.
9-
* @param rect Picture bounds
10-
* @param cb Callback for drawing to the canvas
11-
* @returns SkPicture
12-
*/
13-
export const usePicture = (
14-
rect: SkRect,
15-
cb: (canvas: SkCanvas) => void,
16-
deps: DependencyList = []
17-
) => {
18-
console.warn("usePicture() is deprecated. Use createPicture() instead.");
19-
return useMemo(() => {
20-
const recorder = Skia.PictureRecorder();
21-
const canvas = recorder.beginRecording(rect);
22-
cb(canvas);
23-
return recorder.finishRecordingAsPicture();
24-
// eslint-disable-next-line react-hooks/exhaustive-deps
25-
}, deps);
26-
};
27-
284
/**
295
* Memoizes and returns an SkPicture that can be drawn to another canvas.
306
* @param rect Picture bounds

0 commit comments

Comments
 (0)