import {forwardRef, useEffect, useState} from 'react' import {cn} from '../../lib/utils' export interface PullToRefreshIndicatorProps { pullDistance: number threshold: number isRefreshing: boolean canRefresh: boolean className?: string } export const RefreshIndicator = forwardRef< HTMLDivElement, PullToRefreshIndicatorProps >(({pullDistance, threshold, isRefreshing, canRefresh, className}, ref) => { const [showBumpAnimation, setShowBumpAnimation] = useState(false) const progress = Math.min(pullDistance / threshold, 1) const spinnerProgress = 0.54 + progress * (1 - 0.54) const scale = isRefreshing ? 1 : 0.5 + progress * 0.5 const opacity = isRefreshing ? 1 : Math.min(progress * 1.5, 1) const translateY = isRefreshing ? 0 : progress * 3 useEffect(() => { if (isRefreshing && !showBumpAnimation) { setShowBumpAnimation(true) const timer = setTimeout(() => setShowBumpAnimation(false), 360) return () => clearTimeout(timer) } return undefined }, [isRefreshing, showBumpAnimation]) return (
) }) RefreshIndicator.displayName = 'RefreshIndicator'