UNPKG

react-native-sortables

Version:

Powerful Sortable Components for Flexible Content Reordering in React Native

36 lines (34 loc) 1.13 kB
"use strict"; import { isWorkletFunction } from 'react-native-reanimated'; import { useStableCallbackValue } from '../../integrations/reanimated'; import { logger } from '../../utils'; export default function useDragEndHandler(onDragEnd, jsParamUpdaters) { let callback; if (isWorkletFunction(onDragEnd)) { const jsParams = Object.keys(jsParamUpdaters); callback = params => { 'worklet'; const proxy = new Proxy(params, { get: (target, prop) => { const key = prop; if (jsParams.includes(key)) { logger.warn(`Accessing \`${key}\` in \`onDragEnd\` callback is not supported in the worklet. Please use a JS callback instead.`); } return target[key]; } }); onDragEnd(proxy); }; } else if (onDragEnd) { callback = params => { const result = params; Object.entries(jsParamUpdaters).forEach(entry => { const [key, update] = entry; result[key] = update(params); }); onDragEnd(result); }; } return useStableCallbackValue(callback); } //# sourceMappingURL=useDragEndHandler.js.map