import { colors } from '@/assets/styles/colors'; import { Passageiro } from '@/assets/types'; import styles from '@/styles/screens/reserva/detail.styles'; import { FontAwesome } from '@expo/vector-icons'; import { useEffect, useState } from 'react'; import { Pressable, Text, View } from 'react-native'; import Animated, { Easing, useAnimatedStyle, useSharedValue, withTiming, } from 'react-native-reanimated'; import { DashedDivider } from './DashedDivider'; import { FieldBox } from './FieldBox'; type Props = { passageiro: Passageiro; index: number; isOpen: boolean; isFirst: boolean; onToggle: () => void; }; const ANIM_DURATION = 280; export function PassageiroCard({ passageiro, index, isOpen, onToggle }: Props) { const progress = useSharedValue(isOpen ? 1 : 0); const contentHeight = useSharedValue(0); const [measuredHeight, setMeasuredHeight] = useState(0); useEffect(() => { if (measuredHeight > 0) { contentHeight.value = measuredHeight; } }, [measuredHeight, contentHeight]); useEffect(() => { progress.value = withTiming(isOpen ? 1 : 0, { duration: ANIM_DURATION, easing: Easing.out(Easing.cubic), }); }, [isOpen, progress]); const bodyAnimatedStyle = useAnimatedStyle(() => ({ height: contentHeight.value * progress.value, opacity: progress.value, })); const chevronAnimatedStyle = useAnimatedStyle(() => ({ transform: [{ rotate: `${progress.value * 180}deg` }], })); return ( Passageiro {index + 1} {passageiro.nome} {passageiro.sobrenome} { const h = Math.ceil(e.nativeEvent.layout.height); if (h > 0) setMeasuredHeight(h); }}> ); }