@shopify/react-native-skia 2.0.0-next.2 → 2.0.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +14 -10
- package/cpp/api/JsiSkCanvas.h +45 -2
- package/cpp/api/recorder/Drawings.h +31 -2
- package/cpp/api/recorder/Shaders.h +40 -0
- package/lib/commonjs/renderer/Canvas.d.ts +1 -2
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Player.d.ts +1 -1
- package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Box.js +2 -2
- package/lib/commonjs/sksg/Recorder/commands/Box.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Drawing.d.ts +1 -3
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js +1 -58
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +1 -2
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/sksg/Recorder/Player.d.ts +1 -1
- package/lib/module/sksg/Recorder/Player.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Box.js +2 -2
- package/lib/module/sksg/Recorder/commands/Box.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Drawing.d.ts +1 -3
- package/lib/module/sksg/Recorder/commands/Drawing.js +2 -58
- package/lib/module/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/typescript/lib/commonjs/sksg/Recorder/commands/Drawing.d.ts +0 -1
- package/lib/typescript/lib/module/sksg/Recorder/commands/Drawing.d.ts +0 -1
- package/lib/typescript/src/renderer/Canvas.d.ts +1 -2
- package/lib/typescript/src/sksg/Recorder/Player.d.ts +1 -1
- package/lib/typescript/src/sksg/Recorder/commands/Drawing.d.ts +1 -3
- package/package.json +3 -3
- package/src/__tests__/snapshots/box/box-shadow-opacity.png +0 -0
- package/src/__tests__/snapshots/platform-buffer.png +0 -0
- package/src/__tests__/snapshots/screens/snapshot2-android-ci.png +0 -0
- package/src/renderer/Canvas.tsx +1 -1
- package/src/renderer/__tests__/e2e/Box.spec.tsx +22 -0
- package/src/renderer/__tests__/e2e/NativeBuffer.spec.tsx +2 -0
- package/src/sksg/Recorder/Player.ts +1 -1
- package/src/sksg/Recorder/commands/Box.ts +2 -2
- package/src/sksg/Recorder/commands/Drawing.ts +0 -65
package/src/renderer/Canvas.tsx
CHANGED
@@ -17,7 +17,7 @@ import { SkiaSGRoot } from "../sksg/Reconciler";
|
|
17
17
|
import { Skia } from "../skia";
|
18
18
|
import type { SkiaBaseViewProps } from "../views";
|
19
19
|
|
20
|
-
interface CanvasRef extends FC<CanvasProps> {
|
20
|
+
export interface CanvasRef extends FC<CanvasProps> {
|
21
21
|
makeImageSnapshot(rect?: SkRect): SkImage;
|
22
22
|
makeImageSnapshotAsync(rect?: SkRect): Promise<SkImage>;
|
23
23
|
redraw(): void;
|
@@ -80,4 +80,26 @@ describe("Box", () => {
|
|
80
80
|
);
|
81
81
|
checkImage(img, "snapshots/box/box-stroke.png");
|
82
82
|
});
|
83
|
+
|
84
|
+
it("should draw a shadow with opacity", async () => {
|
85
|
+
const { rect } = importSkia();
|
86
|
+
const { width } = surface;
|
87
|
+
const size = width / 2;
|
88
|
+
const img = await surface.draw(
|
89
|
+
<>
|
90
|
+
<Fill color="white" />
|
91
|
+
<Box box={rect(size / 2, size / 2, size, size)} color="red">
|
92
|
+
<BoxShadow
|
93
|
+
dx={0}
|
94
|
+
dy={0}
|
95
|
+
blur={5}
|
96
|
+
spread={10}
|
97
|
+
inner
|
98
|
+
color={"rgba(0, 0, 255, 0.5)"}
|
99
|
+
/>
|
100
|
+
</Box>
|
101
|
+
</>
|
102
|
+
);
|
103
|
+
checkImage(img, "snapshots/box/box-shadow-opacity.png");
|
104
|
+
});
|
83
105
|
});
|
@@ -72,6 +72,7 @@ describe("Native Buffers", () => {
|
|
72
72
|
);
|
73
73
|
expect(success).toBe(true);
|
74
74
|
});
|
75
|
+
|
75
76
|
it("creates a native buffer from an image", async () => {
|
76
77
|
if (!shouldNativeBufferTestRun()) {
|
77
78
|
return;
|
@@ -114,6 +115,7 @@ describe("Native Buffers", () => {
|
|
114
115
|
expect(image).not.toBeNull();
|
115
116
|
checkImage(image, "snapshots/cyan-buffer.png");
|
116
117
|
});
|
118
|
+
|
117
119
|
it("creates an image from native color type", async () => {
|
118
120
|
const { Skia: Sk } = setupSkia();
|
119
121
|
// Skip outside iOS and Android
|
@@ -45,8 +45,8 @@ import {
|
|
45
45
|
isDrawCommand,
|
46
46
|
isGroup,
|
47
47
|
materializeCommand,
|
48
|
-
type Command,
|
49
48
|
} from "./Core";
|
49
|
+
import type { Command } from "./Core";
|
50
50
|
import type { DrawingContext } from "./DrawingContext";
|
51
51
|
|
52
52
|
function play(ctx: DrawingContext, _command: Command) {
|
@@ -30,7 +30,7 @@ export const drawBox = (ctx: DrawingContext, command: BoxCommand) => {
|
|
30
30
|
const { color = "black", blur, spread = 0, dx = 0, dy = 0 } = shadow;
|
31
31
|
const lPaint = Skia.Paint();
|
32
32
|
lPaint.setColor(processColor(Skia, color));
|
33
|
-
lPaint.setAlphaf(
|
33
|
+
lPaint.setAlphaf(lPaint.getAlphaf() * opacity);
|
34
34
|
lPaint.setMaskFilter(
|
35
35
|
Skia.MaskFilter.MakeBlur(BlurStyle.Normal, blur, true)
|
36
36
|
);
|
@@ -48,7 +48,7 @@ export const drawBox = (ctx: DrawingContext, command: BoxCommand) => {
|
|
48
48
|
canvas.clipRRect(box, ClipOp.Intersect, false);
|
49
49
|
const lPaint = Skia.Paint();
|
50
50
|
lPaint.setColor(Skia.Color(color));
|
51
|
-
lPaint.setAlphaf(
|
51
|
+
lPaint.setAlphaf(lPaint.getAlphaf() * opacity);
|
52
52
|
|
53
53
|
lPaint.setMaskFilter(
|
54
54
|
Skia.MaskFilter.MakeBlur(BlurStyle.Normal, blur, true)
|
@@ -1,9 +1,6 @@
|
|
1
1
|
import {
|
2
|
-
deflate,
|
3
2
|
enumKey,
|
4
3
|
fitRects,
|
5
|
-
inflate,
|
6
|
-
NodeType,
|
7
4
|
processCircle,
|
8
5
|
processColor,
|
9
6
|
processPath,
|
@@ -12,8 +9,6 @@ import {
|
|
12
9
|
} from "../../../dom/nodes";
|
13
10
|
import type {
|
14
11
|
AtlasProps,
|
15
|
-
BoxProps,
|
16
|
-
BoxShadowProps,
|
17
12
|
CircleProps,
|
18
13
|
DiffRectProps,
|
19
14
|
DrawingNodeProps,
|
@@ -38,18 +33,13 @@ import { saturate } from "../../../renderer/processors";
|
|
38
33
|
import type { SkPoint, SkRSXform } from "../../../skia/types";
|
39
34
|
import {
|
40
35
|
BlendMode,
|
41
|
-
BlurStyle,
|
42
|
-
ClipOp,
|
43
36
|
FillType,
|
44
37
|
FilterMode,
|
45
38
|
isCubicSampling,
|
46
|
-
isRRect,
|
47
39
|
MipmapMode,
|
48
40
|
PointMode,
|
49
41
|
VertexMode,
|
50
42
|
} from "../../../skia/types";
|
51
|
-
import type { Node } from "../../Node";
|
52
|
-
import { materialize } from "../../utils";
|
53
43
|
import type { DrawingContext } from "../DrawingContext";
|
54
44
|
|
55
45
|
export const drawLine = (ctx: DrawingContext, props: LineProps) => {
|
@@ -64,61 +54,6 @@ export const drawOval = (ctx: DrawingContext, props: OvalProps) => {
|
|
64
54
|
ctx.canvas.drawOval(rect, ctx.paint);
|
65
55
|
};
|
66
56
|
|
67
|
-
export const drawBox = (
|
68
|
-
ctx: DrawingContext,
|
69
|
-
props: BoxProps,
|
70
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
71
|
-
children: Node<any>[]
|
72
|
-
) => {
|
73
|
-
"worklet";
|
74
|
-
const { paint, Skia, canvas } = ctx;
|
75
|
-
const { box: defaultBox } = props;
|
76
|
-
const opacity = paint.getAlphaf();
|
77
|
-
const box = isRRect(defaultBox) ? defaultBox : Skia.RRectXY(defaultBox, 0, 0);
|
78
|
-
const shadows = children
|
79
|
-
.map((node) => {
|
80
|
-
if (node.type === NodeType.BoxShadow) {
|
81
|
-
return materialize(node.props);
|
82
|
-
}
|
83
|
-
return null;
|
84
|
-
})
|
85
|
-
.filter((n): n is BoxShadowProps => n !== null);
|
86
|
-
shadows
|
87
|
-
.filter((shadow) => !shadow.inner)
|
88
|
-
.map((shadow) => {
|
89
|
-
const { color = "black", blur, spread = 0, dx = 0, dy = 0 } = shadow;
|
90
|
-
const lPaint = Skia.Paint();
|
91
|
-
lPaint.setColor(processColor(Skia, color));
|
92
|
-
lPaint.setAlphaf(paint.getAlphaf() * opacity);
|
93
|
-
lPaint.setMaskFilter(
|
94
|
-
Skia.MaskFilter.MakeBlur(BlurStyle.Normal, blur, true)
|
95
|
-
);
|
96
|
-
canvas.drawRRect(inflate(Skia, box, spread, spread, dx, dy), lPaint);
|
97
|
-
});
|
98
|
-
|
99
|
-
canvas.drawRRect(box, paint);
|
100
|
-
|
101
|
-
shadows
|
102
|
-
.filter((shadow) => shadow.inner)
|
103
|
-
.map((shadow) => {
|
104
|
-
const { color = "black", blur, spread = 0, dx = 0, dy = 0 } = shadow;
|
105
|
-
const delta = Skia.Point(10 + Math.abs(dx), 10 + Math.abs(dy));
|
106
|
-
canvas.save();
|
107
|
-
canvas.clipRRect(box, ClipOp.Intersect, false);
|
108
|
-
const lPaint = Skia.Paint();
|
109
|
-
lPaint.setColor(processColor(Skia, color));
|
110
|
-
lPaint.setAlphaf(paint.getAlphaf() * opacity);
|
111
|
-
|
112
|
-
lPaint.setMaskFilter(
|
113
|
-
Skia.MaskFilter.MakeBlur(BlurStyle.Normal, blur, true)
|
114
|
-
);
|
115
|
-
const inner = deflate(Skia, box, spread, spread, dx, dy);
|
116
|
-
const outer = inflate(Skia, box, delta.x, delta.y);
|
117
|
-
canvas.drawDRRect(outer, inner, lPaint);
|
118
|
-
canvas.restore();
|
119
|
-
});
|
120
|
-
};
|
121
|
-
|
122
57
|
export const drawImage = (ctx: DrawingContext, props: ImageProps) => {
|
123
58
|
"worklet";
|
124
59
|
const { image, sampling } = props;
|