Skip to content

Commit

Permalink
Fix reanimated regression (#1948)
Browse files Browse the repository at this point in the history
  • Loading branch information
wcandillon authored Nov 1, 2023
1 parent c3b3f90 commit 05d692c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 12 additions & 3 deletions package/src/external/reanimated/renderHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ import {

const _bindings = new WeakMap<Node<unknown>, unknown>();

export const unbindReanimatedNode = (node: Node<unknown>) => {
const previousMapperId = _bindings.get(node);
if (previousMapperId !== undefined) {
stopMapper(previousMapperId as number);
}
};

export function extractReanimatedProps(props: AnimatedProps<any>) {
if (!HAS_REANIMATED3 && !HAS_REANIMATED2) {
return [props, {}];
Expand Down Expand Up @@ -76,7 +83,7 @@ export function bindReanimatedProps(
node: Node<any>,
reanimatedProps: AnimatedProps<any>
) {
if (HAS_REANIMATED2) {
if (HAS_REANIMATED2 && !HAS_REANIMATED3) {
return bindReanimatedProps2(container, node, reanimatedProps);
}
if (!HAS_REANIMATED3) {
Expand All @@ -92,8 +99,10 @@ export function bindReanimatedProps(
const { SkiaViewApi } = global;
const mapperId = startMapper(() => {
"worklet";
for (const propName in reanimatedProps) {
node && node.setProp(propName, reanimatedProps[propName].value);
if (node) {
for (const propName in reanimatedProps) {
node.setProp(propName, reanimatedProps[propName].value);
}
}
// On React Native we use the SkiaViewApi to redraw because it can
// run on the worklet thread (container.redraw can't)
Expand Down
2 changes: 2 additions & 0 deletions package/src/renderer/HostConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { SkiaValue } from "../values";
import {
bindReanimatedProps,
extractReanimatedProps,
unbindReanimatedNode,
} from "../external/reanimated/renderHelpers";

import type { Container } from "./Container";
Expand Down Expand Up @@ -56,6 +57,7 @@ const appendNode = (parent: Node<unknown>, child: Node<unknown>) => {
};

const removeNode = (parent: Node<unknown>, child: Node<unknown>) => {
unbindReanimatedNode(child);
return parent.removeChild(child);
};

Expand Down

0 comments on commit 05d692c

Please sign in to comment.