UNPKG

@gorhom/bottom-sheet

Version:

A performant interactive bottom sheet with fully configurable options 🚀

55 lines (45 loc) • 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useReactiveSharedValue = void 0; var _react = require("react"); var _reactNativeReanimated = require("react-native-reanimated"); const useReactiveSharedValue = value => { var _valueRef$current; const initialValueRef = (0, _react.useRef)(null); const valueRef = (0, _react.useRef)(null); if (typeof value === 'object' && 'value' in value) { /** * if provided value is a shared value, * then we do not initialize another one. */ } else if (valueRef.current === null) { // @ts-ignore initialValueRef.current = value; /** * if value is an object, then we need to * pass a clone. */ if (typeof value === 'object') { // @ts-ignore valueRef.current = (0, _reactNativeReanimated.makeMutable)({ ...value }); } else { // @ts-ignore valueRef.current = (0, _reactNativeReanimated.makeMutable)(value); } } else if (initialValueRef.current !== value) { valueRef.current.value = value; } (0, _react.useEffect)(() => { return () => { if (valueRef.current) { (0, _reactNativeReanimated.cancelAnimation)(valueRef.current); } }; }, []); // @ts-ignore return (_valueRef$current = valueRef.current) !== null && _valueRef$current !== void 0 ? _valueRef$current : value; }; exports.useReactiveSharedValue = useReactiveSharedValue; //# sourceMappingURL=useReactiveSharedValue.js.map