Skip to content

Commit 5f35e8e

Browse files
committed
Implement review comments
1 parent 46f3361 commit 5f35e8e

File tree

12 files changed

+26
-29
lines changed

12 files changed

+26
-29
lines changed

example/src/Examples/Performance/PerformanceRects.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Rect,
55
Skia,
66
SkiaView,
7+
usePaint,
78
PaintStyle,
89
usePaintRef,
910
} from "@shopify/react-native-skia";
@@ -20,22 +21,22 @@ import {
2021

2122
// Load font
2223
const Size = 15;
23-
const paint1 = Skia.Paint();
24-
paint1.setAntiAlias(true);
25-
paint1.setColor(Skia.Color("#A2AE6A"));
26-
27-
const paint2 = Skia.Paint();
28-
paint2.setAntiAlias(true);
29-
paint2.setColor(Skia.Color("#4060A3"));
30-
paint2.setStyle(PaintStyle.Stroke);
31-
paint2.setStrokeWidth(2);
3224

3325
export const PerformanceDrawingTest: React.FC = () => {
3426
const [isDeclarative, setIsDeclarative] = useState(false);
3527
const [numberOfBoxes, setNumberOfBoxes] = useState(300);
3628

3729
const { width } = useWindowDimensions();
38-
30+
const paint1 = usePaint((p) => {
31+
p.setAntiAlias(true);
32+
p.setColor(Skia.Color("#A2AE6A"));
33+
});
34+
const paint2 = usePaint((p) => {
35+
p.setAntiAlias(true);
36+
p.setColor(Skia.Color("#4060A3"));
37+
p.setStyle(PaintStyle.Stroke);
38+
p.setStrokeWidth(2);
39+
});
3940
const rects = useMemo(
4041
() =>
4142
new Array(numberOfBoxes)
@@ -58,7 +59,7 @@ export const PerformanceDrawingTest: React.FC = () => {
5859
canvas.drawRect(rects[i], paint2);
5960
}
6061
},
61-
[rects]
62+
[paint1, paint2, rects]
6263
);
6364
const paint1Ref = usePaintRef();
6465
const paint2Ref = usePaintRef();

package/cpp/api/JsiSkPaint.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,11 @@ Returns the underlying object from a host object of this type
215215
static const jsi::HostFunctionType
216216
createCtor(std::shared_ptr<RNSkPlatformContext> context) {
217217
return JSI_HOST_FUNCTION_LAMBDA {
218+
auto paint = SkPaint();
219+
paint.setAntiAlias(true);
218220
// Return the newly constructed object
219221
return jsi::Object::createFromHostObject(
220-
runtime, std::make_shared<JsiSkPaint>(std::move(context), SkPaint()));
222+
runtime, std::make_shared<JsiSkPaint>(std::move(context), paint));
221223
};
222224
}
223225
};
831 Bytes
Loading
1.11 KB
Loading
0 Bytes
Loading
791 Bytes
Loading

package/src/renderer/Canvas.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import ReactReconciler from "react-reconciler";
1818

1919
import { SkiaView, useDrawCallback } from "../views";
2020
import type { TouchHandler } from "../views";
21-
import { defaultSkiaPaint } from "../skia/types";
2221
import type { FontMgr } from "../skia/types";
2322
import { useValue } from "../values/hooks/useValue";
2423
import { Skia } from "../skia/Skia";
@@ -97,7 +96,7 @@ export const Canvas = forwardRef<SkiaView, CanvasProps>(
9796
) {
9897
canvasCtx.size.current = { width, height };
9998
}
100-
const paint = defaultSkiaPaint(Skia.Paint());
99+
const paint = Skia.Paint();
101100
const ctx = {
102101
width,
103102
height,

package/src/renderer/components/Mask.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ReactNode } from "react";
22
import React, { useMemo } from "react";
33

4-
import { BlendMode, defaultSkiaPaint } from "../../skia/types";
4+
import { BlendMode } from "../../skia/types";
55
import { useCanvas } from "../useCanvas";
66

77
import { Group } from "./Group";
@@ -16,15 +16,15 @@ interface MaskProps {
1616
export const Mask = ({ children, mask, mode, clip }: MaskProps) => {
1717
const { Skia } = useCanvas();
1818
const maskPaint = useMemo(() => {
19-
const paint = defaultSkiaPaint(Skia.Paint());
19+
const paint = Skia.Paint();
2020
paint.setBlendMode(BlendMode.Src);
2121
if (mode === "luminance") {
2222
paint.setColorFilter(Skia.ColorFilter.MakeLumaColorFilter());
2323
}
2424
return paint;
2525
}, [Skia, mode]);
2626
const clippingPaint = useMemo(() => {
27-
const paint = defaultSkiaPaint(Skia.Paint());
27+
const paint = Skia.Paint();
2828
paint.setBlendMode(BlendMode.DstIn);
2929
return paint;
3030
}, [Skia]);

package/src/renderer/components/Paint.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type { CustomPaintProps, AnimatedProps } from "../processors";
66
import { processPaint } from "../processors";
77
import { createDeclaration } from "../nodes";
88
import { useCanvas } from "../useCanvas";
9-
import { defaultSkiaPaint } from "../../skia/types";
109

1110
export const usePaintRef = () => useRef<SkPaint>(null);
1211

@@ -17,7 +16,7 @@ export interface PaintProps extends Omit<CustomPaintProps, "paint"> {
1716
export const Paint = forwardRef<SkPaint, AnimatedProps<PaintProps>>(
1817
(props, ref) => {
1918
const { Skia } = useCanvas();
20-
const paint = useMemo(() => defaultSkiaPaint(Skia.Paint()), [Skia]);
19+
const paint = useMemo(() => Skia.Paint(), [Skia]);
2120
useImperativeHandle(ref, () => paint, [paint]);
2221
const onDeclare = useMemo(
2322
() =>

package/src/skia/core/Paint.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import { useMemo } from "react";
33

44
import { Skia } from "../Skia";
55
import type { SkPaint } from "../types";
6-
import { defaultSkiaPaint } from "../types/Paint/Paint";
7-
8-
export const SkiaPaint = () => defaultSkiaPaint(Skia.Paint());
96

107
/**
118
* Returns a Skia Paint object
@@ -15,7 +12,7 @@ export const usePaint = (
1512
deps?: DependencyList
1613
) =>
1714
useMemo(() => {
18-
const p = SkiaPaint();
15+
const p = Skia.Paint();
1916
if (initializer) {
2017
initializer(p);
2118
}

0 commit comments

Comments
 (0)