UNPKG

react-native-reanimated

Version:

More powerful alternative to Animated library for React Native.

53 lines (39 loc) 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useAnimatedRef = useAnimatedRef; var _react = require("react"); var _useSharedValue = require("./useSharedValue"); var _NativeMethods = require("../NativeMethods"); var _fabricUtils = require("../fabricUtils"); var _shareables = require("../shareables"); function getShareableShadowNodeFromComponent(component) { return (0, _fabricUtils.getShadowNodeWrapperFromHostInstance)(component); } const getTagValueFunction = global._IS_FABRIC ? getShareableShadowNodeFromComponent : _NativeMethods.getTag; function useAnimatedRef() { const tag = (0, _useSharedValue.useSharedValue)(-1); const ref = (0, _react.useRef)(); if (!ref.current) { const fun = component => { // enters when ref is set by attaching to a component if (component) { tag.value = getTagValueFunction(component); fun.current = component; } return tag.value; }; fun.current = null; const remoteRef = (0, _shareables.makeShareableCloneRecursive)({ __init: () => { 'worklet'; return () => tag.value; } }); (0, _shareables.registerShareableMapping)(fun, remoteRef); ref.current = fun; } return ref.current; } //# sourceMappingURL=useAnimatedRef.js.map