Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve unmount behavior #2619

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/skia/src/renderer/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { Skia } from "../skia/types";
export class Container {
private _root: RenderNode<GroupProps>;
public Sk: SkDOM;
public unmounted = false;
constructor(
Skia: Skia,
public redraw: () => void = () => {},
Expand Down
10 changes: 7 additions & 3 deletions packages/skia/src/renderer/HostConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ const appendNode = (parent: Node<unknown>, child: Node<unknown>) => {
parent.addChild(child);
};

const removeNode = (parent: Node<unknown>, child: Node<unknown>) => {
const removeNode = (parent: Node<unknown>, child: Node<unknown>, 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 = (
Expand Down Expand Up @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions packages/skia/src/renderer/Reconciler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class SkiaRoot {
}

unmount() {
this.container.unmounted = true;
skiaReconciler.updateContainer(null, this.root, null, () => {
hostDebug("unmountContainer");
});
Expand Down
8 changes: 0 additions & 8 deletions packages/skia/src/views/SkiaDomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"!apps/*/src/app/build"
],
"outputs": [
"apps/*/ios/android/**"
"apps/*/android/**"
]
},
"build:ios": {
Expand Down
Loading