Улучшить pull-to-refresh: чувствительность, дистанция, анимация

- Порог увеличен 64 → 130px, чувствительность снижена 0.45 → 0.16
- Rubber-band: сопротивление нарастает по мере приближения к порогу
- Иконка вращается 0–270° пропорционально прогрессу тяги
- Цвет плавно переходит от muted к accent через color-mix
- При достижении порога — accent glow на border-bottom
- Snap-back с cubic-bezier только при отпускании (pullReleasing)
- Игнорирование trackpad-шума (delta < 4px)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
vodyanoysh 2026-03-31 22:48:02 +07:00
parent cbf80e1fc5
commit 4c5afdd3a4

View file

@ -42,24 +42,35 @@ onMounted(restartAutoCheck)
onUnmounted(() => { if (autoCheckTimer) clearInterval(autoCheckTimer) }) onUnmounted(() => { if (autoCheckTimer) clearInterval(autoCheckTimer) })
// ── Pull-to-refresh ─────────────────────────────────────── // ── Pull-to-refresh ───────────────────────────────────────
const PULL_THRESHOLD = 64 const PULL_THRESHOLD = 130 // расстояние для срабатывания
const pullY = ref(0) const PULL_FACTOR = 0.16 // базовая чувствительность
const PULL_RUBBER = 0.55 // rubber-band: сопротивление у порога
const pullY = ref(0)
const pullRefreshing = ref(false) const pullRefreshing = ref(false)
const pullReleasing = ref(false)
const indicatorProgress = computed(() => const indicatorProgress = computed(() =>
pullRefreshing.value ? 1 : Math.min(1, pullY.value / PULL_THRESHOLD) pullRefreshing.value ? 1 : Math.min(1, pullY.value / PULL_THRESHOLD)
) )
const iconRotate = computed(() => indicatorProgress.value * 270)
let pullDecayTimer: ReturnType<typeof setTimeout> | null = null let pullDecayTimer: ReturnType<typeof setTimeout> | null = null
function onWheel(event: WheelEvent): void { function onWheel(event: WheelEvent): void {
const el = event.currentTarget as HTMLElement const el = event.currentTarget as HTMLElement
if (el.scrollTop > 2) { if (el.scrollTop > 2) {
if (pullY.value > 0) pullY.value = 0 if (pullY.value > 0) { pullY.value = 0 }
return return
} }
const delta = Math.abs(event.deltaY)
if (delta < 4) return // trackpad-шум
if (event.deltaY < 0 && !pullRefreshing.value && !messagesStore.loading) { if (event.deltaY < 0 && !pullRefreshing.value && !messagesStore.loading) {
if (pullDecayTimer) { clearTimeout(pullDecayTimer); pullDecayTimer = null } if (pullDecayTimer) { clearTimeout(pullDecayTimer); pullDecayTimer = null }
pullY.value = Math.min(PULL_THRESHOLD, pullY.value + Math.abs(event.deltaY) * 0.45) // rubber-band: чем ближе к порогу — тем тяжелее тянуть
const resistance = 1 - (pullY.value / PULL_THRESHOLD) * PULL_RUBBER
pullY.value = Math.min(PULL_THRESHOLD, pullY.value + delta * PULL_FACTOR * resistance)
if (pullY.value >= PULL_THRESHOLD) triggerPullRefresh() if (pullY.value >= PULL_THRESHOLD) triggerPullRefresh()
} else if (event.deltaY > 0 && pullY.value > 0) { } else if (event.deltaY > 0 && pullY.value > 0) {
schedulePullDecay() schedulePullDecay()
@ -68,7 +79,11 @@ function onWheel(event: WheelEvent): void {
function schedulePullDecay(): void { function schedulePullDecay(): void {
if (pullDecayTimer) clearTimeout(pullDecayTimer) if (pullDecayTimer) clearTimeout(pullDecayTimer)
pullDecayTimer = setTimeout(() => { pullY.value = 0 }, 180) pullDecayTimer = setTimeout(() => {
pullReleasing.value = true
pullY.value = 0
setTimeout(() => { pullReleasing.value = false }, 320)
}, 250)
} }
async function triggerPullRefresh(): Promise<void> { async function triggerPullRefresh(): Promise<void> {
@ -76,8 +91,10 @@ async function triggerPullRefresh(): Promise<void> {
pullRefreshing.value = true pullRefreshing.value = true
pullY.value = PULL_THRESHOLD pullY.value = PULL_THRESHOLD
await refresh() await refresh()
pullReleasing.value = true
pullRefreshing.value = false pullRefreshing.value = false
pullY.value = 0 pullY.value = 0
setTimeout(() => { pullReleasing.value = false }, 320)
} }
// ── Scroll (infinite load) ──────────────────────────────── // ── Scroll (infinite load) ────────────────────────────────
@ -178,10 +195,21 @@ async function handleSwipeAction(action: SwipeAction, messageId: string): Promis
<!-- Pull-to-refresh индикатор (всегда в DOM, высота = 0 в обычном состоянии) --> <!-- Pull-to-refresh индикатор (всегда в DOM, высота = 0 в обычном состоянии) -->
<div <div
class="pull-indicator-wrap" class="pull-indicator-wrap"
:class="{ releasing: pullReleasing }"
:style="{ '--progress': indicatorProgress }" :style="{ '--progress': indicatorProgress }"
> >
<div class="pull-indicator" :class="{ refreshing: pullRefreshing }"> <div
<AppIcon name="refresh" :size="13" :class="{ spinning: pullRefreshing }" /> class="pull-indicator"
:class="{ ready: indicatorProgress >= 1 && !pullRefreshing, refreshing: pullRefreshing }"
:style="{ '--pull-progress': indicatorProgress }"
>
<div
class="pull-icon-outer"
:class="{ spinning: pullRefreshing }"
:style="{ transform: pullRefreshing ? '' : `rotate(${iconRotate}deg)` }"
>
<AppIcon name="refresh" :size="14" />
</div>
<span>{{ pullRefreshing ? 'Обновление...' : indicatorProgress >= 1 ? 'Отпустите для обновления' : 'Потяните для обновления' }}</span> <span>{{ pullRefreshing ? 'Обновление...' : indicatorProgress >= 1 ? 'Отпустите для обновления' : 'Потяните для обновления' }}</span>
</div> </div>
</div> </div>
@ -603,38 +631,59 @@ async function handleSwipeAction(action: SwipeAction, messageId: string): Promis
/* Pull-to-refresh */ /* Pull-to-refresh */
.pull-indicator-wrap { .pull-indicator-wrap {
height: calc(var(--progress, 0) * 44px); height: calc(var(--progress, 0) * 56px);
overflow: hidden; overflow: hidden;
flex-shrink: 0; flex-shrink: 0;
transition: height 0.12s ease; }
.pull-indicator-wrap.releasing {
transition: height 0.32s cubic-bezier(0.25, 0.46, 0.45, 0.94);
} }
.pull-indicator { .pull-indicator {
height: 44px; height: 56px;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
gap: 7px; gap: 8px;
font-size: 11px; font-size: 11.5px;
font-weight: 500; font-weight: 500;
color: var(--text-muted); /* цвет интерполируется от muted к accent по мере тяги */
color: color-mix(in srgb, var(--accent) calc(var(--pull-progress, 0) * 100%), var(--text-muted));
background: background:
linear-gradient(180deg, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0.01) 100%), linear-gradient(180deg, rgba(255,255,255,0.045) 0%, rgba(255,255,255,0.012) 100%),
rgba(12, 12, 20, 0.5); rgba(10, 10, 18, 0.65);
backdrop-filter: blur(12px); backdrop-filter: blur(20px) saturate(1.5);
-webkit-backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(20px) saturate(1.5);
border-bottom: 1px solid rgba(255, 255, 255, 0.06); border-bottom: 1px solid rgba(255, 255, 255, 0.06);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
letter-spacing: 0.2px; letter-spacing: 0.2px;
transition: color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
} }
.pull-indicator svg { /* Достигнут порог — accent-подсветка */
transition: transform 0.2s ease; .pull-indicator.ready {
color: var(--text-muted); border-bottom-color: color-mix(in srgb, var(--accent) 35%, transparent);
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.09),
0 2px 16px color-mix(in srgb, var(--accent) 10%, transparent);
} }
.pull-indicator.refreshing svg { .pull-indicator.refreshing {
color: var(--accent); color: var(--accent);
border-bottom-color: color-mix(in srgb, var(--accent) 25%, transparent);
}
/* Обёртка иконки: вращение по прогрессу */
.pull-icon-outer {
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
transition: transform 0.06s linear;
}
.pull-icon-outer.spinning {
animation: spin 0.7s linear infinite;
transition: none;
} }
@keyframes spin { @keyframes spin {