Files
TiktokUI/lib/gestures.ts

13 lines
665 B
TypeScript

/** Positive movement means pulling the previous page down; negative means pushing to the next. */
export function swipeDirection(distance: number, velocity: number, height: number): -1 | 0 | 1 {
if (height <= 0) return 0;
const committed = Math.abs(distance) > height * .19 || (Math.abs(velocity) > .4 && Math.abs(distance) > 20);
return committed ? (distance < 0 ? 1 : -1) : 0;
}
/** Three unique videos are kept mounted and repositioned around the active page. */
export function pagePosition(videoIndex: number, activeIndex: number): -1 | 0 | 1 {
const relative = (videoIndex - activeIndex + 3) % 3;
return relative === 2 ? -1 : relative as 0 | 1;
}