Skip to content

Commit 8becd56

Browse files
authored
Merge pull request #2143 from Shopify/fix-pathtransform
Web support: fix minor regressions
2 parents 71161bd + 394f3c4 commit 8becd56

File tree

9 files changed

+63
-10
lines changed

9 files changed

+63
-10
lines changed
1.55 KB
Loading
-498 Bytes
Loading

package/src/external/reanimated/interpolators.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useCallback, useMemo } from "react";
88
import type { SkPath, SkPoint } from "../../skia/types";
99
import { interpolatePaths, interpolateVector } from "../../animation";
1010
import { Skia } from "../../skia";
11+
import { Platform } from "../../Platform";
1112

1213
import {
1314
useAnimatedReaction,
@@ -18,7 +19,7 @@ import {
1819

1920
export const notifyChange = (value: SharedValue<unknown>) => {
2021
"worklet";
21-
if (_WORKLET) {
22+
if (_WORKLET || Platform.OS === "web") {
2223
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2324
(value as any)._value = value.value;
2425
}

package/src/renderer/Canvas.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import type { LayoutChangeEvent } from "react-native";
1717
import { SkiaDomView } from "../views";
1818
import { Skia } from "../skia/Skia";
1919
import type { TouchHandler, SkiaBaseViewProps } from "../views";
20-
import { SkiaDomView2 } from "../views/SkiaDomView2";
21-
import { Platform } from "../Platform";
20+
import { SkiaJSDomView } from "../views/SkiaJSDomView";
2221

2322
import { SkiaRoot } from "./Reconciler";
2423
import { NATIVE_DOM } from "./HostComponents";
@@ -91,7 +90,7 @@ export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
9190
};
9291
}, [root]);
9392

94-
if (NATIVE_DOM || Platform.OS === "web") {
93+
if (NATIVE_DOM) {
9594
return (
9695
<SkiaDomView
9796
ref={ref}
@@ -106,7 +105,7 @@ export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
106105
);
107106
} else {
108107
return (
109-
<SkiaDomView2
108+
<SkiaJSDomView
110109
Skia={Skia}
111110
// eslint-disable-next-line @typescript-eslint/no-explicit-any
112111
ref={ref as any}

package/src/renderer/__tests__/Data.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const CheckTogglingImage = ({}: EmptyProps) => {
4545
if (oslo && zurich) {
4646
h.current = setTimeout(() => {
4747
setIdx(1);
48-
}, 20);
48+
}, 200);
4949
}
5050
return () => {
5151
clearTimeout(h.current);

package/src/renderer/__tests__/e2e/Matrix4.spec.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,38 @@ describe("Matrix4", () => {
227227
0.1
228228
);
229229
});
230+
231+
it("Path.transform() should accept 4x4 (1)", async () => {
232+
let result = await surface.eval((Skia) => {
233+
const path = Skia.Path.MakeFromSVGString("M150 0L75 200L225 200L150 0Z")!;
234+
path.transform([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
235+
return path.toSVGString();
236+
});
237+
expect(result).toEqual("M150 0L75 200L225 200L150 0Z");
238+
239+
result = await surface.eval((Skia) => {
240+
const path = Skia.Path.MakeFromSVGString("M150 0L75 200L225 200L150 0Z")!;
241+
path.transform([1, 0, 0, 0, 0, 1, 0, 0, 0]);
242+
return path.toSVGString();
243+
});
244+
expect(result).not.toEqual("M150 0L75 200L225 200L150 0Z");
245+
});
246+
it("Path.transform() should accept 4x4 (2)", async () => {
247+
let result = await surface.eval((Skia) => {
248+
const path = Skia.Path.MakeFromSVGString("M150 0L75 200L225 200L150 0Z")!;
249+
const m = [1, 0, 0, 100, 0, 1, 0, 100, 0, 0, 1, 0, 0, 0, 0, 1];
250+
path.transform([m[0], m[1], m[3], m[4], m[5], m[7], m[12], m[13], m[15]]);
251+
return path.toSVGString();
252+
});
253+
expect(result).toEqual("M250 100L175 300L325 300L250 100Z");
254+
255+
result = await surface.eval((Skia) => {
256+
const path = Skia.Path.MakeFromSVGString("M150 0L75 200L225 200L150 0Z")!;
257+
path.transform([1, 0, 0, 100, 0, 1, 0, 100, 0, 0, 1, 0, 0, 0, 0, 1]);
258+
return path.toSVGString();
259+
});
260+
expect(result).toEqual("M250 100L175 300L325 300L250 100Z");
261+
});
230262
it("should correctly transform a point with an identity matrix", () => {
231263
const identityMatrix = Matrix4();
232264
const point = [100, -100, 200] as const; // Define some test point

package/src/skia/web/JsiSkPath.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CanvasKit, Path } from "canvaskit-wasm";
1+
import type { CanvasKit, Matrix3x3, Path } from "canvaskit-wasm";
22

33
import { PathVerb } from "../types";
44
import type {
@@ -11,6 +11,7 @@ import type {
1111
SkRect,
1212
InputRRect,
1313
StrokeOpts,
14+
InputMatrix,
1415
} from "../types";
1516

1617
import { getEnum, HostObject, optEnum } from "./Host";
@@ -339,8 +340,27 @@ export class JsiSkPath extends HostObject<Path, "Path"> implements SkPath {
339340
return result === null ? result : this;
340341
}
341342

342-
transform(m3: SkMatrix) {
343-
this.ref.transform(Array.isArray(m3) ? m3 : JsiSkMatrix.fromValue(m3));
343+
transform(m: InputMatrix) {
344+
let matrix =
345+
m instanceof JsiSkMatrix
346+
? Array.from(JsiSkMatrix.fromValue<Matrix3x3>(m))
347+
: (m as Exclude<InputMatrix, SkMatrix>);
348+
if (matrix.length === 16) {
349+
matrix = [
350+
matrix[0],
351+
matrix[1],
352+
matrix[3],
353+
matrix[4],
354+
matrix[5],
355+
matrix[7],
356+
matrix[12],
357+
matrix[13],
358+
matrix[15],
359+
];
360+
} else if (matrix.length !== 9) {
361+
throw new Error(`Invalid matrix length: ${matrix.length}`);
362+
}
363+
this.ref.transform(matrix);
344364
return this;
345365
}
346366

package/src/views/SkiaDomView2.tsx renamed to package/src/views/SkiaJSDomView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const NativeSkiaPictureView: HostComponent<SkiaPictureViewProps> =
1616
: // eslint-disable-next-line @typescript-eslint/no-explicit-any
1717
(null as any);
1818

19-
export class SkiaDomView2 extends React.Component<
19+
export class SkiaJSDomView extends React.Component<
2020
SkiaDomViewProps & { Skia: Skia }
2121
> {
2222
constructor(props: SkiaDomViewProps & { Skia: Skia }) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { SkiaDomView as SkiaJSDomView } from "./SkiaDomView";

0 commit comments

Comments
 (0)