import { useRef, useCallback, useEffect } from 'react'; import { Animated } from 'react-native'; export function useHeightAnimation(initialHeight = 0, duration = 300) { const height = useRef(new Animated.Value(initialHeight)).current; const updateHeight = useCallback( (toValue: number) => { Animated.timing(height, { toValue, duration, useNativeDriver: false, }).start(); }, [height, duration], ); useEffect(() => { updateHeight(initialHeight); }, [initialHeight, updateHeight]); const animatedHeightStyle = { height }; return { animatedHeightStyle, height }; }