This commit is contained in:
kakkokari-gtyih 2026-01-15 00:23:52 +09:00
parent 630116e37c
commit bd48e5f6e5
2 changed files with 54 additions and 12 deletions

View File

@ -43,6 +43,8 @@ const pullDistance = ref(0);
let startScreenY: number | null = null; let startScreenY: number | null = null;
let moveBySystemCancel: (() => void) | null = null;
const rootEl = useTemplateRef('rootEl'); const rootEl = useTemplateRef('rootEl');
let scrollEl: HTMLElement | null = null; let scrollEl: HTMLElement | null = null;
@ -127,26 +129,60 @@ function moveStartByTouch(event: TouchEvent) {
} }
function moveBySystem(to: number): Promise<void> { function moveBySystem(to: number): Promise<void> {
if (moveBySystemCancel != null) {
moveBySystemCancel();
moveBySystemCancel = null;
}
return new Promise(r => { return new Promise(r => {
const startHeight = pullDistance.value; const startHeight = pullDistance.value;
const overHeight = pullDistance.value - to; const overHeight = startHeight - to;
if (overHeight < 1) { if (Math.abs(overHeight) < 1) {
pullDistance.value = to;
r(); r();
return; return;
} }
const startTime = Date.now();
let intervalId = window.setInterval(() => { let startTime: number | null = null;
const time = Date.now() - startTime; let cancelled = false;
if (time > RELEASE_TRANSITION_DURATION) { moveBySystemCancel = () => {
cancelled = true;
startTime = null;
};
const tick = (now: number) => {
if (cancelled) {
r();
return;
}
if (startTime == null) {
startTime = now;
}
const time = now - startTime;
if (time >= RELEASE_TRANSITION_DURATION) {
pullDistance.value = to; pullDistance.value = to;
window.clearInterval(intervalId); moveBySystemCancel = null;
r(); r();
return; return;
} }
const nextHeight = startHeight - (overHeight / RELEASE_TRANSITION_DURATION) * time; const nextHeight = startHeight - (overHeight / RELEASE_TRANSITION_DURATION) * time;
if (pullDistance.value < nextHeight) return; if (overHeight > 0) {
if (pullDistance.value < nextHeight) {
window.requestAnimationFrame(tick);
return;
}
} else {
if (pullDistance.value > nextHeight) {
window.requestAnimationFrame(tick);
return;
}
}
pullDistance.value = nextHeight; pullDistance.value = nextHeight;
}, 1); window.requestAnimationFrame(tick);
};
window.requestAnimationFrame(tick);
}); });
} }

View File

@ -131,17 +131,23 @@ function animatePullDistanceTo(to: number, duration = RELEASE_TRANSITION_DURATIO
return; return;
} }
const startTime = performance.now(); // DOMHighResTimeStampDate.now()performance.now()使
let startTime: DOMHighResTimeStamp | null = null;
let cancelled = false; let cancelled = false;
releaseAnimationCancel = () => { releaseAnimationCancel = () => {
cancelled = true; cancelled = true;
startTime = null;
}; };
const tick = (now: number) => { const tick = (now: DOMHighResTimeStamp) => {
if (cancelled) { if (cancelled) {
resolve(); resolve();
return; return;
} }
if (startTime == null) {
startTime = now;
}
const t = Math.min((now - startTime) / duration, 1); const t = Math.min((now - startTime) / duration, 1);
// //
const eased = 1 - Math.pow(1 - t, 3); const eased = 1 - Math.pow(1 - t, 3);
@ -297,7 +303,7 @@ function hasSomethingToDoWithXSwipe(el: HTMLElement) {
if (style.overflowX === 'scroll') return true; if (style.overflowX === 'scroll') return true;
if (style.touchAction === 'pan-x') return true; if (style.touchAction === 'pan-x') return true;
if (el.parentElement && el.parentElement !== rootEl.value) { if (el.parentElement != null && el.parentElement !== rootEl.value) {
return hasSomethingToDoWithXSwipe(el.parentElement); return hasSomethingToDoWithXSwipe(el.parentElement);
} else { } else {
return false; return false;