Skip to content

Commit

Permalink
Fix animated refs on Fabric (#3822)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
kmagiera authored Nov 30, 2022
1 parent 99573c3 commit ef6e0f2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/reanimated2/hook/useAnimatedRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends Component>(): RefObjectFunction<T> {
Expand Down

0 comments on commit ef6e0f2

Please sign in to comment.