MCPcopy Create free account
hub / github.com/adobe/react-spectrum / onMove

Function onMove

packages/react-aria/src/color/useColorArea.ts:163–204  ·  view source on GitHub ↗
({deltaX, deltaY, pointerType, shiftKey})

Source from the content-addressed store, hash-verified

161 state.setDragging(true);
162 },
163 onMove({deltaX, deltaY, pointerType, shiftKey}) {
164 let {
165 incrementX,
166 decrementX,
167 incrementY,
168 decrementY,
169 xChannelPageStep,
170 xChannelStep,
171 yChannelPageStep,
172 yChannelStep,
173 getThumbPosition,
174 setColorFromPoint
175 } = state;
176 if (currentPosition.current == null) {
177 currentPosition.current = getThumbPosition();
178 }
179 let {width, height} = containerRef.current?.getBoundingClientRect() || {width: 0, height: 0};
180 let valueChanged = deltaX !== 0 || deltaY !== 0;
181 if (pointerType === 'keyboard') {
182 let deltaXValue =
183 shiftKey && xChannelPageStep > xChannelStep ? xChannelPageStep : xChannelStep;
184 let deltaYValue =
185 shiftKey && yChannelPageStep > yChannelStep ? yChannelPageStep : yChannelStep;
186 if ((deltaX > 0 && direction === 'ltr') || (deltaX < 0 && direction === 'rtl')) {
187 incrementX(deltaXValue);
188 } else if ((deltaX < 0 && direction === 'ltr') || (deltaX > 0 && direction === 'rtl')) {
189 decrementX(deltaXValue);
190 } else if (deltaY > 0) {
191 decrementY(deltaYValue);
192 } else if (deltaY < 0) {
193 incrementY(deltaYValue);
194 }
195 setValueChangedViaKeyboard(valueChanged);
196 // set the focused input based on which axis has the greater delta
197 focusedInput = valueChanged && Math.abs(deltaY) > Math.abs(deltaX) ? 'y' : 'x';
198 setFocusedInput(focusedInput);
199 } else {
200 currentPosition.current.x += ((direction === 'rtl' ? -1 : 1) * deltaX) / width;
201 currentPosition.current.y += deltaY / height;
202 setColorFromPoint(currentPosition.current.x, currentPosition.current.y);
203 }
204 },
205 onMoveEnd() {
206 isOnColorArea.current = false;
207 state.setDragging(false);

Callers

nothing calls this directly

Calls 6

incrementXFunction · 0.85
decrementXFunction · 0.85
decrementYFunction · 0.85
incrementYFunction · 0.85
setColorFromPointFunction · 0.85
getThumbPositionFunction · 0.50

Tested by

no test coverage detected