MCPcopy Create free account
hub / github.com/ionic-team/ionic-framework / calcGestureData

Function calcGestureData

core/src/utils/gesture/index.ts:233–256  ·  view source on GitHub ↗
(detail: GestureDetail, ev: UIEvent | undefined)

Source from the content-addressed store, hash-verified

231};
232
233const calcGestureData = (detail: GestureDetail, ev: UIEvent | undefined) => {
234 if (!ev) {
235 return;
236 }
237 const prevX = detail.currentX;
238 const prevY = detail.currentY;
239 const prevT = detail.currentTime;
240
241 updateDetail(ev, detail);
242
243 const currentX = detail.currentX;
244 const currentY = detail.currentY;
245 const timestamp = (detail.currentTime = now(ev));
246 const timeDelta = timestamp - prevT;
247 if (timeDelta > 0 && timeDelta < 100) {
248 const velocityX = (currentX - prevX) / timeDelta;
249 const velocityY = (currentY - prevY) / timeDelta;
250 detail.velocityX = velocityX * 0.7 + detail.velocityX * 0.3;
251 detail.velocityY = velocityY * 0.7 + detail.velocityY * 0.3;
252 }
253 detail.deltaX = currentX - detail.startX;
254 detail.deltaY = currentY - detail.startY;
255 detail.event = ev;
256};
257
258const updateDetail = (ev: any, detail: GestureDetail) => {
259 // get X coordinates for either a mouse click

Callers 2

pointerMoveFunction · 0.85
pointerUpFunction · 0.85

Calls 2

updateDetailFunction · 0.85
nowFunction · 0.70

Tested by

no test coverage detected