diff --git a/src/reanimated2/hook/useAnimatedRef.ts b/src/reanimated2/hook/useAnimatedRef.ts index d7739ac396e..a11a3d29de9 100644 --- a/src/reanimated2/hook/useAnimatedRef.ts +++ b/src/reanimated2/hook/useAnimatedRef.ts @@ -10,6 +10,7 @@ import { } from '../shareables'; interface ComponentRef extends Component { + getNativeScrollRef?: () => ComponentRef; getScrollableNode?: () => ComponentRef; } @@ -19,6 +20,15 @@ function getShareableShadowNodeFromComponent( return getShadowNodeWrapperFromHostInstance(component); } +function getComponentOrScrollableRef(component: ComponentRef): ComponentRef { + if (global._IS_FABRIC && component.getNativeScrollRef) { + return component.getNativeScrollRef(); + } else if (!global._IS_FABRIC && component.getScrollableNode) { + return component.getScrollableNode(); + } + return component; +} + const getTagValueFunction = global._IS_FABRIC ? getShareableShadowNodeFromComponent : getTag; @@ -31,11 +41,7 @@ export function useAnimatedRef(): RefObjectFunction { const fun: RefObjectFunction = >((component) => { // enters when ref is set by attaching to a component if (component) { - tag.value = getTagValueFunction( - component.getScrollableNode - ? component.getScrollableNode() - : component - ); + tag.value = getTagValueFunction(getComponentOrScrollableRef(component)); fun.current = component; } return tag.value; @@ -50,7 +56,6 @@ export function useAnimatedRef(): RefObjectFunction { }, }); registerShareableMapping(fun, remoteRef); - ref.current = fun; }