enhance(frontend): 中クリックでPullToRefreshするように

Close #15931
This commit is contained in:
syuilo 2025-05-04 11:04:51 +09:00
parent 3eaa05a5d9
commit 5aeedf59ff
4 changed files with 35 additions and 30 deletions

4
locales/index.d.ts vendored
View File

@ -5713,6 +5713,10 @@ export interface Locale extends ILocale {
* *
*/ */
"enablePullToRefresh": string; "enablePullToRefresh": string;
/**
*
*/
"enablePullToRefresh_description": string;
"_chat": { "_chat": {
/** /**
* *

View File

@ -1428,6 +1428,7 @@ _settings:
ifOff: "オフのとき" ifOff: "オフのとき"
enableSyncThemesBetweenDevices: "デバイス間でインストールしたテーマを同期" enableSyncThemesBetweenDevices: "デバイス間でインストールしたテーマを同期"
enablePullToRefresh: "ひっぱって更新" enablePullToRefresh: "ひっぱって更新"
enablePullToRefresh_description: "マウスでは、ホイールを押し込みながらドラッグします。"
_chat: _chat:
showSenderName: "送信者の名前を表示" showSenderName: "送信者の名前を表示"

View File

@ -77,31 +77,37 @@ function unlockDownScroll() {
} }
function moveStart(event: PointerEvent) { function moveStart(event: PointerEvent) {
const scrollPos = scrollEl!.scrollTop; if (event.pointerType === 'mouse' && event.button !== 1) return;
if (scrollPos === 0) { if (isRefreshing.value) return;
lockDownScroll();
if (!isPulling.value && !isRefreshing.value) {
isPulling.value = true;
startScreenY = getScreenY(event);
pullDistance.value = 0;
// PointerEvent使TouchEventMouseEvent使 const scrollPos = scrollEl!.scrollTop;
if (event.pointerType === 'mouse') { if (scrollPos !== 0) {
window.addEventListener('mousemove', moving, { passive: true });
window.addEventListener('mouseup', () => {
window.removeEventListener('mousemove', moving);
onPullRelease();
}, { passive: true, once: true });
} else {
window.addEventListener('touchmove', moving, { passive: true });
window.addEventListener('touchend', () => {
window.removeEventListener('touchmove', moving);
onPullRelease();
}, { passive: true, once: true });
}
}
} else {
unlockDownScroll(); unlockDownScroll();
return;
}
lockDownScroll();
// pull
window.document.body.setAttribute('inert', 'true');
isPulling.value = true;
startScreenY = getScreenY(event);
pullDistance.value = 0;
// PointerEvent使TouchEventMouseEvent使
if (event.pointerType === 'mouse') {
window.addEventListener('mousemove', moving, { passive: true });
window.addEventListener('mouseup', () => {
window.removeEventListener('mousemove', moving);
onPullRelease();
}, { passive: true, once: true });
} else {
window.addEventListener('touchmove', moving, { passive: true });
window.addEventListener('touchend', () => {
window.removeEventListener('touchmove', moving);
onPullRelease();
}, { passive: true, once: true });
} }
} }
@ -168,8 +174,6 @@ function toggleScrollLockOnTouchEnd() {
} }
function moving(event: MouseEvent | TouchEvent) { function moving(event: MouseEvent | TouchEvent) {
if (!isPulling.value || isRefreshing.value) return;
if ((scrollEl?.scrollTop ?? 0) > SCROLL_STOP + pullDistance.value || isHorizontalSwipeSwiping.value) { if ((scrollEl?.scrollTop ?? 0) > SCROLL_STOP + pullDistance.value || isHorizontalSwipeSwiping.value) {
pullDistance.value = 0; pullDistance.value = 0;
isPulledEnough.value = false; isPulledEnough.value = false;
@ -185,11 +189,6 @@ function moving(event: MouseEvent | TouchEvent) {
const moveHeight = moveScreenY - startScreenY!; const moveHeight = moveScreenY - startScreenY!;
pullDistance.value = Math.min(Math.max(moveHeight, 0), MAX_PULL_DISTANCE); pullDistance.value = Math.min(Math.max(moveHeight, 0), MAX_PULL_DISTANCE);
// pull
if (pullDistance.value > 3) { //
window.document.body.setAttribute('inert', 'true');
}
isPulledEnough.value = pullDistance.value >= FIRE_THRESHOLD; isPulledEnough.value = pullDistance.value >= FIRE_THRESHOLD;
} }

View File

@ -475,6 +475,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkPreferenceContainer k="enablePullToRefresh"> <MkPreferenceContainer k="enablePullToRefresh">
<MkSwitch v-model="enablePullToRefresh"> <MkSwitch v-model="enablePullToRefresh">
<template #label><SearchLabel>{{ i18n.ts._settings.enablePullToRefresh }}</SearchLabel></template> <template #label><SearchLabel>{{ i18n.ts._settings.enablePullToRefresh }}</SearchLabel></template>
<template #caption><SearchKeyword>{{ i18n.ts._settings.enablePullToRefresh_description }}</SearchKeyword></template>
</MkSwitch> </MkSwitch>
</MkPreferenceContainer> </MkPreferenceContainer>
</SearchMarker> </SearchMarker>