Used with a component · PullToRefresh
usePullToRefresh
The gesture engine and state machine behind <PullToRefresh>. A downward drag at scroll top pulls a distance you render, then a release past threshold runs onRefresh. Its state goes from idle to pulling, ready, loading and done, then back to idle. Touch drives it through a non-passive touchmove, the one way to hold back the browser's own scroll and bounce. A mouse drags it through pointer events. <PullToRefresh> adds the pull zone, the arrow and loader indicator and the #indicator slot.
Install
import { usePullToRefresh } from 'vael-ui'Examples
<script setup lang="ts">
import { useTemplateRef } from 'vue'
import { usePullToRefresh } from 'vael-ui'
const scrollEl = useTemplateRef<HTMLElement>('scroller')
const { state, pullDistance } = usePullToRefresh({
scrollEl,
onRefresh: () => fetchInbox(),
})
</script>
<template>
<div ref="scroller" class="inbox">
<div class="pull-zone" :style="{ blockSize: `${pullDistance}px` }">
{{ state === 'loading' ? 'Refreshing' : state === 'ready' ? 'Release to refresh' : '' }}
</div>
<ul>...</ul>
</div>
</template>