Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions packages/vant/src/pull-refresh/PullRefresh.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const pullRefreshProps = {
pullDistance: numericProp,
successDuration: makeNumericProp(500),
animationDuration: makeNumericProp(300),
maxPullDistance: numericProp,
};

export type PullRefreshProps = ExtractPropTypes<typeof pullRefreshProps>;
Expand Down Expand Up @@ -88,6 +89,15 @@ export default defineComponent({
const ease = (distance: number) => {
const pullDistance = +(props.pullDistance || props.headHeight);

if (props.maxPullDistance) {
const maxDistance = +props.maxPullDistance;
const ratio = distance / maxDistance;
if (ratio > 0.618) {
const dampingFactor = 1 - Math.pow(ratio - 0.618, 2) * 2.5;
distance *= dampingFactor;
}
}

if (distance > pullDistance) {
if (distance < pullDistance * 2) {
distance = pullDistance + (distance - pullDistance) / 2;
Expand Down Expand Up @@ -184,8 +194,15 @@ export default defineComponent({
touch.move(event);

if (reachTop && deltaY.value >= 0 && touch.isVertical()) {
preventDefault(event);
setStatus(ease(deltaY.value));
const maxPullDistance = +(props.maxPullDistance || Infinity);

if (deltaY.value > maxPullDistance) {
setStatus(0);
// to enable default scroll behavior in this case
} else {
preventDefault(event);
setStatus(ease(deltaY.value));
}
}
}
};
Expand All @@ -194,6 +211,12 @@ export default defineComponent({
if (reachTop && touch.deltaY.value && isTouchable()) {
state.duration = +props.animationDuration;

const maxPullDistance = +(props.maxPullDistance || Infinity);
if (touch.deltaY.value > maxPullDistance) {
setStatus(0);
return;
}

if (state.status === 'loosing') {
setStatus(+props.headHeight, true);
emit('update:modelValue', true);
Expand Down