Skip to content

Commit 59c08cb

Browse files
authored
fix(🌎): fix major regression on RN Web (#3276)
1 parent 3fb0359 commit 59c08cb

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

‎packages/skia/src/sksg/Container.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ class ReanimatedContainer extends Container {
170170
drawOnscreen(Skia, nativeId, recording!);
171171
}, Array.from(animationValues));
172172
}
173-
Rea.runOnUI(() => {
173+
Rea.runOnUI((onSize?: SharedValue<SkSize>) => {
174174
"worklet";
175-
drawOnscreen(Skia, nativeId, recording!, this.onSize);
176-
})();
175+
drawOnscreen(Skia, nativeId, recording!, onSize);
176+
})(this.onSize);
177177
}
178178
}
179179

‎packages/skia/src/specs/NativeSkiaModule.web.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ global.SkiaViewApi = {
3030
}
3131
}
3232
},
33+
size(nativeId: number) {
34+
if (this.views[`${nativeId}`]) {
35+
return this.views[`${nativeId}`].getSize();
36+
} else {
37+
return { width: 0, height: 0 };
38+
}
39+
},
3340
requestRedraw(nativeId: number) {
3441
this.views[`${nativeId}`].redraw();
3542
},

‎packages/skia/src/specs/SkiaPictureViewNativeComponent.web.ts‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import type { ViewProps } from "react-native";
2-
import { createElement, useEffect, useRef } from "react";
2+
import { createElement } from "react";
33

44
import { SkiaPictureView } from "../views/SkiaPictureView.web";
55

6-
import type { ISkiaViewApiWeb } from "./NativeSkiaModule.web";
7-
86
export interface NativeProps extends ViewProps {
97
debug?: boolean;
108
opaque?: boolean;
@@ -18,17 +16,8 @@ const SkiaPictureViewNativeComponent = ({
1816
onLayout,
1917
...viewProps
2018
}: NativeProps) => {
21-
const ref = useRef(null);
22-
useEffect(() => {
23-
if (ref.current) {
24-
(global.SkiaViewApi as ISkiaViewApiWeb).registerView(
25-
nativeID,
26-
ref.current
27-
);
28-
}
29-
}, [nativeID]);
3019
return createElement(SkiaPictureView, {
31-
ref,
20+
nativeID,
3221
debug,
3322
opaque,
3423
onLayout,

‎packages/skia/src/views/SkiaBaseWebView.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export abstract class SkiaBaseWebView<
5959
}
6060
}
6161

62-
protected getSize() {
62+
getSize() {
6363
return { width: this.width, height: this.height };
6464
}
6565

‎packages/skia/src/views/SkiaPictureView.web.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { SkCanvas, SkPicture } from "../skia/types";
2+
import type { ISkiaViewApiWeb } from "../specs/NativeSkiaModule.web";
23

34
import type { SkiaPictureViewNativeProps } from "./types";
45
import { SkiaBaseWebView } from "./SkiaBaseWebView";
@@ -8,6 +9,11 @@ export class SkiaPictureView extends SkiaBaseWebView<SkiaPictureViewNativeProps>
89

910
constructor(props: SkiaPictureViewNativeProps) {
1011
super(props);
12+
const { nativeID } = props;
13+
if (!nativeID) {
14+
throw new Error("SkiaPictureView requires a nativeID prop");
15+
}
16+
(global.SkiaViewApi as ISkiaViewApiWeb).registerView(nativeID, this);
1117
}
1218

1319
public setPicture(picture: SkPicture) {

0 commit comments

Comments
 (0)