Skip to content

Commit 3868fe0

Browse files
authored
Remove usePaintRef deprecation (#1005)
1 parent 0eb3f23 commit 3868fe0

File tree

7 files changed

+11
-44
lines changed

7 files changed

+11
-44
lines changed

docs/docs/paint/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,4 @@ export const PaintDemo = () => {
143143
};
144144
```
145145

146-
<img src={require("/static/img/paint/assignement.png").default} width="256" height="256" />
146+
<img src={require("/static/img/paint/assignement.png").default} width="256" height="256" />

package/src/dom/nodes/DrawingNode.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
import type { NodeContext } from "./Node";
1010
import { JsiDeclarationNode } from "./Node";
1111
import { PaintNode } from "./PaintNode";
12-
import { isSkPaint, JsiRenderNode } from "./RenderNode";
12+
import { JsiRenderNode } from "./RenderNode";
1313

1414
export abstract class JsiDrawingNode<P extends DrawingNodeProps, C>
1515
extends JsiRenderNode<P>
@@ -52,10 +52,8 @@ export abstract class JsiDrawingNode<P extends DrawingNodeProps, C>
5252
}
5353

5454
renderNode(ctx: DrawingContext): void {
55-
if (this.props.paint && isSkPaint(this.props.paint)) {
55+
if (this.props.paint) {
5656
this.draw({ ...ctx, paint: this.props.paint });
57-
} else if (this.props.paint && this.props.paint.current != null) {
58-
this.draw({ ...ctx, paint: this.props.paint.current.materialize() });
5957
} else {
6058
this.draw(ctx);
6159
}

package/src/dom/nodes/RenderNode.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { RefObject } from "react";
2-
31
import type {
42
SkMatrix,
53
SkRect,
@@ -21,7 +19,6 @@ import type {
2119
DrawingContext,
2220
NodeType,
2321
Node,
24-
DeclarationNode,
2522
} from "../types";
2623

2724
import { isPathDef, processPath, processTransformProps } from "./datatypes";
@@ -236,17 +233,12 @@ export abstract class JsiRenderNode<P extends GroupProps>
236233
this.clipRRect !== undefined;
237234
const shouldSave = hasTransform || hasClip || !!layer;
238235
const op = invertClip ? ClipOp.Difference : ClipOp.Intersect;
239-
240236
if (shouldSave) {
241237
if (layer) {
242238
if (typeof layer === "boolean") {
243239
canvas.saveLayer();
244-
} else if (isSkPaint(layer)) {
245-
canvas.saveLayer(layer);
246240
} else {
247-
canvas.saveLayer(
248-
layer.current ? layer.current.materialize() : undefined
249-
);
241+
canvas.saveLayer(layer);
250242
}
251243
} else {
252244
canvas.save();
@@ -274,10 +266,6 @@ export abstract class JsiRenderNode<P extends GroupProps>
274266
abstract renderNode(ctx: DrawingContext): void;
275267
}
276268

277-
export const isSkPaint = (
278-
obj: RefObject<DeclarationNode<unknown, SkPaint>> | SkPaint
279-
): obj is SkPaint => "__typename__" in obj && obj.__typename__ === "Paint";
280-
281269
const concatPaint = (
282270
parent: SkPaint,
283271
{

package/src/dom/types/Common.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ReactNode, RefObject } from "react";
1+
import type { ReactNode } from "react";
22

33
import type {
44
BlendMode,
@@ -15,8 +15,6 @@ import type {
1515
Vector,
1616
} from "../../skia/types";
1717

18-
import type { DeclarationNode } from "./Node";
19-
2018
export type SkEnum<T> = Uncapitalize<keyof T extends string ? keyof T : never>;
2119

2220
export type PathDef = string | SkPath;
@@ -86,5 +84,5 @@ export interface PaintProps extends ChildrenProps {
8684
export interface GroupProps extends PaintProps, TransformProps {
8785
clip?: ClipDef;
8886
invertClip?: boolean;
89-
layer?: RefObject<DeclarationNode<unknown, SkPaint>> | SkPaint | boolean;
87+
layer?: SkPaint | boolean;
9088
}

package/src/dom/types/Drawings.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { RefObject } from "react";
2-
31
import type {
42
FillType,
53
SkImage,
@@ -29,10 +27,9 @@ import type {
2927
SkEnum,
3028
} from "./Common";
3129
import type { DrawingContext } from "./DrawingContext";
32-
import type { DeclarationNode } from "./Node";
3330

3431
export interface DrawingNodeProps extends GroupProps {
35-
paint?: SkPaint | RefObject<DeclarationNode<unknown, SkPaint>>;
32+
paint?: SkPaint;
3633
}
3734

3835
export type ImageProps = DrawingNodeProps &

package/src/renderer/HostComponents.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { ForwardedRef } from "react";
2-
31
import { NodeType } from "../dom/types";
42
import type {
53
CircleProps,
@@ -55,7 +53,6 @@ import type {
5553
BlendProps,
5654
MorphologyImageFilterProps,
5755
} from "../dom/types/ImageFilters";
58-
import type { PaintNode } from "../dom/nodes/PaintNode";
5956

6057
import type { Container } from "./Container";
6158
import { exhaustiveCheck } from "./typeddash";
@@ -67,7 +64,7 @@ declare global {
6764
interface IntrinsicElements {
6865
skGroup: SkiaProps<GroupProps>;
6966
skLayer: SkiaProps<ChildrenProps>;
70-
skPaint: SkiaProps<PaintProps> & { ref: ForwardedRef<PaintNode> };
67+
skPaint: SkiaProps<PaintProps>;
7168

7269
// Drawings
7370
skFill: SkiaProps<DrawingNodeProps>;
Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
/* eslint-disable max-len */
2-
import React, { useRef, forwardRef } from "react";
1+
import React from "react";
32

43
import type { SkiaProps } from "../processors";
54
import type { DrawingNodeProps } from "../../dom/types";
6-
import type { PaintNode } from "../../dom/nodes/PaintNode";
75

8-
export const usePaintRef = () => {
9-
console.log(`usePaintRef() is now deprecated.
10-
If you are using the layer property, simply pass the component directly: https://shopify.github.io/react-native-skia/docs/group#layer-effects.
11-
If you are using the paint property, please the following paint properties directly: https://shopify.github.io/react-native-skia/docs/paint/overview`);
12-
return useRef<PaintNode>(null);
6+
export const Paint = (props: SkiaProps<DrawingNodeProps>) => {
7+
return <skPaint {...props} />;
138
};
14-
15-
export const Paint = forwardRef<PaintNode, SkiaProps<DrawingNodeProps>>(
16-
(props, ref) => {
17-
return <skPaint ref={ref} {...props} />;
18-
}
19-
);

0 commit comments

Comments
 (0)