MCPcopy Create free account
hub / github.com/angular/components / _updatePointerDirectionDelta

Method _updatePointerDirectionDelta

src/cdk/drag-drop/drag-ref.ts:1340–1364  ·  view source on GitHub ↗

Updates the current drag delta, based on the user's current pointer position on the page.

(pointerPositionOnPage: Point)

Source from the content-addressed store, hash-verified

1338
1339 /** Updates the current drag delta, based on the user's current pointer position on the page. */
1340 private _updatePointerDirectionDelta(pointerPositionOnPage: Point) {
1341 const {x, y} = pointerPositionOnPage;
1342 const delta = this._pointerDirectionDelta;
1343 const positionSinceLastChange = this._pointerPositionAtLastDirectionChange;
1344
1345 // Amount of pixels the user has dragged since the last time the direction changed.
1346 const changeX = Math.abs(x - positionSinceLastChange.x);
1347 const changeY = Math.abs(y - positionSinceLastChange.y);
1348
1349 // Because we handle pointer events on a per-pixel basis, we don't want the delta
1350 // to change for every pixel, otherwise anything that depends on it can look erratic.
1351 // To make the delta more consistent, we track how much the user has moved since the last
1352 // delta change and we only update it after it has reached a certain threshold.
1353 if (changeX > this._config.pointerDirectionChangeThreshold) {
1354 delta.x = x > positionSinceLastChange.x ? 1 : -1;
1355 positionSinceLastChange.x = x;
1356 }
1357
1358 if (changeY > this._config.pointerDirectionChangeThreshold) {
1359 delta.y = y > positionSinceLastChange.y ? 1 : -1;
1360 positionSinceLastChange.y = y;
1361 }
1362
1363 return delta;
1364 }
1365
1366 /** Toggles the native drag interactions, based on how many handles are registered. */
1367 private _toggleNativeDragInteractions() {

Callers 1

DragRefClass · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected