Skip to content

Commit d51beb3

Browse files
authored
fix(🐛): improve Canvas unmounting (#2619)
So far Canvas unmounting was treated as a regular SkiaDOM update where the drawing is simply empty. But we want to keep the last frame visible until the view is destroyed.
1 parent 5938d7b commit d51beb3

File tree

5 files changed

+10
-12
lines changed

5 files changed

+10
-12
lines changed

packages/skia/src/renderer/Container.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { Skia } from "../skia/types";
1010
export class Container {
1111
private _root: RenderNode<GroupProps>;
1212
public Sk: SkDOM;
13+
public unmounted = false;
1314
constructor(
1415
Skia: Skia,
1516
public redraw: () => void = () => {},

packages/skia/src/renderer/HostConfig.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,13 @@ const appendNode = (parent: Node<unknown>, child: Node<unknown>) => {
5353
parent.addChild(child);
5454
};
5555

56-
const removeNode = (parent: Node<unknown>, child: Node<unknown>) => {
56+
const removeNode = (parent: Node<unknown>, child: Node<unknown>, unmounted = false) => {
57+
// If the drawing is unmounted we don't want to update it.
58+
// We can just stop the reanimated mappers
5759
unbindReanimatedNode(child);
58-
return parent.removeChild(child);
60+
if (!unmounted) {
61+
parent.removeChild(child);
62+
}
5963
};
6064

6165
const insertBefore = (
@@ -224,7 +228,7 @@ export const skHostConfig: SkiaHostConfig = {
224228
},
225229

226230
removeChildFromContainer: (container, child) => {
227-
removeNode(container.root, child);
231+
removeNode(container.root, child, container.unmounted);
228232
},
229233

230234
insertInContainerBefore: (container, child, before) => {

packages/skia/src/renderer/Reconciler.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class SkiaRoot {
4646
}
4747

4848
unmount() {
49+
this.container.unmounted = true;
4950
skiaReconciler.updateContainer(null, this.root, null, () => {
5051
hostDebug("unmountContainer");
5152
});

packages/skia/src/views/SkiaDomView.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,6 @@ See: https://shopify.github.io/react-native-skia/docs/animations/gestures`
8888
SkiaViewApi.requestRedraw(this._nativeId);
8989
}
9090

91-
/**
92-
* Clear up the dom node when unmounting to release resources.
93-
*/
94-
componentWillUnmount(): void {
95-
assertSkiaViewApi();
96-
SkiaViewApi.setJsiProperty(this._nativeId, "root", null);
97-
}
98-
9991
render() {
10092
const { mode, debug = false, ...viewProps } = this.props;
10193
return (

turbo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"!apps/*/src/app/build"
1818
],
1919
"outputs": [
20-
"apps/*/ios/android/**"
20+
"apps/*/android/**"
2121
]
2222
},
2323
"build:ios": {

0 commit comments

Comments
 (0)