From bf2f1fe72727fe07e11bc7e8e2c126e5de35c3f4 Mon Sep 17 00:00:00 2001 From: Krzysztof Magiera Date: Wed, 30 Nov 2022 17:03:40 +0100 Subject: [PATCH] Fix animated refs on Fabric (#3822) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary This PR fixes crash on Fabric when using synchronous measure/scrollTo etc – this error was a regression introduced in #3722. The issue was that did not transform shadow node wrapper ref into shareable ref. Shareable ref was necessary for the UI side to recognize and extract the shadow node wrapper that was needed for the sync calls to execute. ## Test plan Run FabricExample, use "Measure on UI" on the "Measure Example" screen and "ScrollTo on UI" button on the "ScrollTo Example" screen. --- src/reanimated2/hook/useAnimatedRef.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/reanimated2/hook/useAnimatedRef.ts b/src/reanimated2/hook/useAnimatedRef.ts index f76dc01ec7f..c698d1daf06 100644 --- a/src/reanimated2/hook/useAnimatedRef.ts +++ b/src/reanimated2/hook/useAnimatedRef.ts @@ -6,11 +6,20 @@ import { getTag } from '../NativeMethods'; import { getShadowNodeWrapperFromHostInstance } from '../fabricUtils'; import { makeShareableCloneRecursive, + makeShareableShadowNodeWrapper, registerShareableMapping, } from '../shareables'; +function getShareableShadowNodeFromComponent( + component: Component +): ShadowNodeWrapper { + return makeShareableShadowNodeWrapper( + getShadowNodeWrapperFromHostInstance(component) + ); +} + const getTagValueFunction = global._IS_FABRIC - ? getShadowNodeWrapperFromHostInstance + ? getShareableShadowNodeFromComponent : getTag; export function useAnimatedRef(): RefObjectFunction {