UNPKG

@gorhom/bottom-sheet

Version:

A performant interactive bottom sheet with fully configurable options 🚀

51 lines (43 loc) • 1.25 kB
import { type AnimationCallback, ReduceMotion, type WithSpringConfig, type WithTimingConfig, withSpring, withTiming, } from 'react-native-reanimated'; import { ANIMATION_CONFIGS, ANIMATION_METHOD } from '../constants'; interface AnimateParams { point: number; velocity?: number; configs?: WithSpringConfig | WithTimingConfig; onComplete?: AnimationCallback; } export const animate = ({ point, configs, velocity = 0, onComplete, }: AnimateParams) => { 'worklet'; if (!configs) { configs = ANIMATION_CONFIGS; } // Users might have an accessibility setting to reduce motion turned on. // This prevents the animation from running when presenting the sheet, which results in // the bottom sheet not even appearing so we need to override it to ensure the animation runs. configs.reduceMotion = ReduceMotion.Never; // detect animation type const type = 'duration' in configs || 'easing' in configs ? ANIMATION_METHOD.TIMING : ANIMATION_METHOD.SPRING; if (type === ANIMATION_METHOD.TIMING) { return withTiming(point, configs as WithTimingConfig, onComplete); } return withSpring( point, Object.assign({ velocity }, configs) as WithSpringConfig, onComplete ); };