Skip to content

Commit 399d86b

Browse files
committed
🧪 convert new group tests to declarative; savelayer is passing, backdrop filtering is not
1 parent 5263be9 commit 399d86b

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed

‎packages/skia/src/dom/types/Common.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
InputRRect,
88
PaintStyle,
99
SaveLayerFlag,
10+
SkImageFilter,
1011
SkPaint,
1112
SkPath,
1213
SkRect,
@@ -72,6 +73,7 @@ export interface TransformProps {
7273
}
7374

7475
export interface SaveLayerProps {
76+
backdropFilter?: SkImageFilter;
7577
saveLayerFlags?: SaveLayerFlag;
7678
}
7779

‎packages/skia/src/renderer/__tests__/e2e/Group.spec.tsx‎

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

33
import { checkImage, docPath } from "../../../__tests__/setup";
4-
import { Image, Group, Fill, FitBox, Path } from "../../components";
4+
import {
5+
Image,
6+
Group,
7+
Fill,
8+
FitBox,
9+
Path,
10+
Rect,
11+
Circle,
12+
Paint,
13+
Blur,
14+
} from "../../components";
515
import { images, importSkia, PIXEL_RATIO, surface } from "../setup";
616

717
describe("Group", () => {
@@ -164,6 +174,48 @@ describe("Group", () => {
164174
);
165175
checkImage(img, docPath("group/bloom.png"));
166176
});
177+
it("Copies a layer and adds new content to it (decl)", async () => {
178+
const { width, height } = surface;
179+
const centreY = height / 2;
180+
const { SaveLayerFlag, rect } = importSkia();
181+
const img = await surface.draw(
182+
<>
183+
<Fill color="black" />
184+
<Rect
185+
x={0}
186+
y={centreY - 0.1 * height}
187+
width={width}
188+
height={0.2 * height}
189+
color={[0, 0, 0.6, 1]}
190+
/>
191+
<Circle
192+
cx={0.25 * width}
193+
cy={centreY}
194+
r={0.2 * width}
195+
color={[0.8, 0, 0, 1]}
196+
/>
197+
<Group clip={rect(0, 0, width, centreY)}>
198+
<Group
199+
saveLayerFlags={SaveLayerFlag.SaveLayerInitWithPrevious}
200+
layer={
201+
<Paint blendMode={"screen"}>
202+
<Blur blur={width * 0.05} mode={"decal"} />
203+
</Paint>
204+
}
205+
>
206+
<Circle
207+
cx={0.75 * width}
208+
cy={centreY}
209+
r={0.2 * width}
210+
color={[0.8, 0, 0, 1]}
211+
/>
212+
</Group>
213+
</Group>
214+
</>
215+
);
216+
217+
checkImage(img, docPath("group/bloom.png"));
218+
});
167219
it("Copies a layer through a backdrop filter and adds new content to it", async () => {
168220
const { width, height } = surface;
169221
const centreY = height / 2;
@@ -200,4 +252,46 @@ describe("Group", () => {
200252
);
201253
checkImage(img, docPath("group/bloom2.png"));
202254
});
255+
it("Copies a layer through a backdrop filter and adds new content to it (decl)", async () => {
256+
const { width, height } = surface;
257+
const centreY = height / 2;
258+
const { TileMode, rect, Skia } = importSkia();
259+
const img = await surface.draw(
260+
<>
261+
<Fill color="black" />
262+
<Rect
263+
x={0}
264+
y={centreY - 0.1 * height}
265+
width={width}
266+
height={0.2 * height}
267+
color={[0, 0, 0.6, 1]}
268+
/>
269+
<Circle
270+
cx={0.25 * width}
271+
cy={centreY}
272+
r={0.2 * width}
273+
color={[0.8, 0, 0, 1]}
274+
/>
275+
<Group clip={rect(0, 0, width, centreY)}>
276+
<Group
277+
layer={<Paint blendMode={"screen"} />}
278+
backdropFilter={Skia.ImageFilter.MakeBlur(
279+
width * 0.05,
280+
width * 0.05,
281+
TileMode.Decal
282+
)}
283+
>
284+
<Circle
285+
cx={0.75 * width}
286+
cy={centreY}
287+
r={0.2 * width}
288+
color={[0.8, 0, 0, 1]}
289+
/>
290+
</Group>
291+
</Group>
292+
</>
293+
);
294+
295+
checkImage(img, docPath("group/bloom2.png"));
296+
});
203297
});

0 commit comments

Comments
 (0)