react-native-sortables
Version:
Powerful Sortable Components for Flexible Content Reordering in React Native
85 lines (82 loc) • 2.46 kB
JavaScript
;
import { useCallback } from 'react';
import { useDebugContext } from '../../../debug';
const TRIGGER_COLORS = {
backgroundColor: '#CE00B5',
borderColor: '#4E0044'
};
const OVERSCROLL_COLORS = {
backgroundColor: '#0078CE',
borderColor: '#004466'
};
export default function useDebugHelpers(isVertical, [startActivationOffset, endActivationOffset], contentBounds, [maxStartOverscroll, maxEndOverscroll]) {
const debugContext = useDebugContext();
const debugRects = debugContext?.useDebugRects(['startOverscroll', 'endOverscroll', 'start', 'end']);
const hideDebugViews = useCallback(() => {
'worklet';
debugRects?.startOverscroll.hide();
debugRects?.endOverscroll.hide();
debugRects?.start.hide();
debugRects?.end.hide();
}, [debugRects]);
const updateDebugRects = useCallback((containerPos, scrollableSize) => {
'worklet';
const startTriggerProps = isVertical ? {
height: startActivationOffset,
y: -containerPos
} : {
width: startActivationOffset,
x: -containerPos
};
const endTriggerProps = isVertical ? {
height: endActivationOffset,
positionOrigin: 'bottom',
y: -containerPos + scrollableSize
} : {
positionOrigin: 'right',
width: endActivationOffset,
x: -containerPos + scrollableSize
};
debugRects?.start.set({
...TRIGGER_COLORS,
...startTriggerProps
});
debugRects?.end.set({
...TRIGGER_COLORS,
...endTriggerProps
});
if (!contentBounds.value) {
return;
}
const [startBound, endBound] = contentBounds.value;
const startOverscrollProps = isVertical ? {
height: maxStartOverscroll,
positionOrigin: 'bottom',
y: startBound
} : {
positionOrigin: 'right',
width: maxStartOverscroll,
x: startBound
};
const endOverscrollProps = isVertical ? {
height: maxEndOverscroll,
y: endBound
} : {
width: maxEndOverscroll,
x: endBound
};
debugRects?.startOverscroll.set({
...OVERSCROLL_COLORS,
...startOverscrollProps
});
debugRects?.endOverscroll.set({
...OVERSCROLL_COLORS,
...endOverscrollProps
});
}, [debugRects, isVertical, contentBounds, maxStartOverscroll, maxEndOverscroll, startActivationOffset, endActivationOffset]);
return debugContext ? {
hideDebugViews,
updateDebugRects
} : {};
}
//# sourceMappingURL=useDebugHelpers.js.map