MCPcopy Index your code
hub / github.com/adobe/react-spectrum / useMove

Function useMove

packages/react-aria/src/interactions/useMove.ts:38–278  ·  view source on GitHub ↗
(props: MoveEvents)

Source from the content-addressed store, hash-verified

36 * platforms, and ignores emulated mouse events on touch devices.
37 */
38export function useMove(props: MoveEvents): MoveResult {
39 let {onMoveStart, onMove, onMoveEnd} = props;
40
41 let state = useRef<{
42 didMove: boolean;
43 lastPosition: {pageX: number; pageY: number} | null;
44 id: number | null;
45 }>({didMove: false, lastPosition: null, id: null});
46
47 let {addGlobalListener, removeGlobalListener} = useGlobalListeners();
48
49 let move = useCallback(
50 (originalEvent: EventBase, pointerType: PointerType, deltaX: number, deltaY: number) => {
51 if (deltaX === 0 && deltaY === 0) {
52 return;
53 }
54
55 if (!state.current.didMove) {
56 state.current.didMove = true;
57 onMoveStart?.({
58 type: 'movestart',
59 pointerType,
60 shiftKey: originalEvent.shiftKey,
61 metaKey: originalEvent.metaKey,
62 ctrlKey: originalEvent.ctrlKey,
63 altKey: originalEvent.altKey
64 });
65 }
66 onMove?.({
67 type: 'move',
68 pointerType,
69 deltaX: deltaX,
70 deltaY: deltaY,
71 shiftKey: originalEvent.shiftKey,
72 metaKey: originalEvent.metaKey,
73 ctrlKey: originalEvent.ctrlKey,
74 altKey: originalEvent.altKey
75 });
76 },
77 [onMoveStart, onMove, state]
78 );
79 let moveEvent = useEffectEvent(move);
80
81 let end = useCallback(
82 (originalEvent: EventBase, pointerType: PointerType) => {
83 restoreTextSelection();
84 if (state.current.didMove) {
85 onMoveEnd?.({
86 type: 'moveend',
87 pointerType,
88 shiftKey: originalEvent.shiftKey,
89 metaKey: originalEvent.metaKey,
90 ctrlKey: originalEvent.ctrlKey,
91 altKey: originalEvent.altKey
92 });
93 }
94 },
95 [onMoveEnd, state]

Callers 10

ExampleFunction · 0.90
useTableColumnResizeFunction · 0.90
useSliderFunction · 0.90
useSliderThumbFunction · 0.90
useColorWheelFunction · 0.90
useColorAreaFunction · 0.90
useClampedMoveFunction · 0.90
LogRenderFunction · 0.90
BallNestedStoryFunction · 0.90
ResizableFunction · 0.90

Calls 10

useGlobalListenersFunction · 0.90
useEffectEventFunction · 0.90
restoreTextSelectionFunction · 0.90
getOwnerWindowFunction · 0.90
getEventTargetFunction · 0.90
triggerKeyboardMoveFunction · 0.85
startFunction · 0.70
onMoveStartFunction · 0.50
onMoveFunction · 0.50
onMoveEndFunction · 0.50

Tested by 1

ExampleFunction · 0.72