From bccb18efb261c61cc9362f52341de09ea1af6404 Mon Sep 17 00:00:00 2001 From: William Candillon Date: Mon, 9 Sep 2024 22:10:11 +0200 Subject: [PATCH 1/2] Improve unmount behavior --- packages/skia/src/renderer/Container.tsx | 1 + packages/skia/src/renderer/HostConfig.ts | 10 +++++++--- packages/skia/src/renderer/Reconciler.tsx | 1 + packages/skia/src/views/SkiaDomView.tsx | 8 -------- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/skia/src/renderer/Container.tsx b/packages/skia/src/renderer/Container.tsx index 110b952539..e0582bdd4f 100644 --- a/packages/skia/src/renderer/Container.tsx +++ b/packages/skia/src/renderer/Container.tsx @@ -10,6 +10,7 @@ import type { Skia } from "../skia/types"; export class Container { private _root: RenderNode; public Sk: SkDOM; + public unmounted = false; constructor( Skia: Skia, public redraw: () => void = () => {}, diff --git a/packages/skia/src/renderer/HostConfig.ts b/packages/skia/src/renderer/HostConfig.ts index 4ad489431c..6ea1e19be5 100644 --- a/packages/skia/src/renderer/HostConfig.ts +++ b/packages/skia/src/renderer/HostConfig.ts @@ -53,9 +53,13 @@ const appendNode = (parent: Node, child: Node) => { parent.addChild(child); }; -const removeNode = (parent: Node, child: Node) => { +const removeNode = (parent: Node, child: Node, unmounted = false) => { + // If the drawing is unmounted we don't want to update it. + // We can just stop the reanimated mappers unbindReanimatedNode(child); - return parent.removeChild(child); + if (!unmounted) { + parent.removeChild(child); + } }; const insertBefore = ( @@ -224,7 +228,7 @@ export const skHostConfig: SkiaHostConfig = { }, removeChildFromContainer: (container, child) => { - removeNode(container.root, child); + removeNode(container.root, child, container.unmounted); }, insertInContainerBefore: (container, child, before) => { diff --git a/packages/skia/src/renderer/Reconciler.tsx b/packages/skia/src/renderer/Reconciler.tsx index 7dfecf612c..65a79fa905 100644 --- a/packages/skia/src/renderer/Reconciler.tsx +++ b/packages/skia/src/renderer/Reconciler.tsx @@ -46,6 +46,7 @@ export class SkiaRoot { } unmount() { + this.container.unmounted = true; skiaReconciler.updateContainer(null, this.root, null, () => { hostDebug("unmountContainer"); }); diff --git a/packages/skia/src/views/SkiaDomView.tsx b/packages/skia/src/views/SkiaDomView.tsx index 25d07873a0..3f740e42e8 100644 --- a/packages/skia/src/views/SkiaDomView.tsx +++ b/packages/skia/src/views/SkiaDomView.tsx @@ -88,14 +88,6 @@ See: https://shopify.github.io/react-native-skia/docs/animations/gestures` SkiaViewApi.requestRedraw(this._nativeId); } - /** - * Clear up the dom node when unmounting to release resources. - */ - componentWillUnmount(): void { - assertSkiaViewApi(); - SkiaViewApi.setJsiProperty(this._nativeId, "root", null); - } - render() { const { mode, debug = false, ...viewProps } = this.props; return ( From 75e821b24bbb8e41176502f3918ccf192289d5fd Mon Sep 17 00:00:00 2001 From: William Candillon Date: Mon, 9 Sep 2024 22:41:32 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=92=9A=20fix=20typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- turbo.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/turbo.json b/turbo.json index ca99a5aa16..0b7af13567 100644 --- a/turbo.json +++ b/turbo.json @@ -17,7 +17,7 @@ "!apps/*/src/app/build" ], "outputs": [ - "apps/*/ios/android/**" + "apps/*/android/**" ] }, "build:ios": {