import { IconSymbol } from "@/components/ui/icon-symbol"; import React, { useRef, useState } from "react"; import { Animated, Platform, Text, TouchableOpacity, UIManager, View, } from "react-native"; import styles from "./style/TripCostTable.styles"; // --------------------------- // 🧩 Interface // --------------------------- interface CostItem { id: string; loai: string; soLuong: number; donVi: string; chiPhi: number; tongChiPhi: number; } // --------------------------- // 📊 Dữ liệu mẫu // --------------------------- const data: CostItem[] = [ { id: "1", loai: "Nhiên liệu", soLuong: 1000, donVi: "liters", chiPhi: 20000, tongChiPhi: 20000000, }, { id: "2", loai: "Lương thực", soLuong: 500, donVi: "kg", chiPhi: 30000, tongChiPhi: 15000000, }, { id: "3", loai: "Lương thuyền viên", soLuong: 10, donVi: "people", chiPhi: 5000000, tongChiPhi: 50000000, }, { id: "4", loai: "Muối đá", soLuong: 100, donVi: "kg", chiPhi: 20000, tongChiPhi: 2000000, }, ]; // --------------------------- // 💰 Component chính // --------------------------- const TripCostTable: React.FC = () => { // Enable LayoutAnimation for Android if ( Platform.OS === "android" && UIManager.setLayoutAnimationEnabledExperimental ) { UIManager.setLayoutAnimationEnabledExperimental(true); } const [collapsed, setCollapsed] = useState(true); const [contentHeight, setContentHeight] = useState(0); const animatedHeight = useRef(new Animated.Value(0)).current; const tongCong = data.reduce((sum, item) => sum + item.tongChiPhi, 0); const handleToggle = () => { const toValue = collapsed ? contentHeight : 0; Animated.timing(animatedHeight, { toValue, duration: 300, useNativeDriver: false, }).start(); setCollapsed((prev) => !prev); }; return ( Chi phí chuyến đi {collapsed && ( {tongCong.toLocaleString()} )} {/* Nội dung ẩn để đo chiều cao */} { const height = event.nativeEvent.layout.height; if (height > 0 && contentHeight === 0) { setContentHeight(height); } }} > {/* Header */} Loại Tổng chi phí {/* Body */} {data.map((item) => ( {item.loai} {item.tongChiPhi.toLocaleString()} ))} {/* Footer */} Tổng cộng {tongCong.toLocaleString()} {/* Header */} Loại Tổng chi phí {/* Body */} {data.map((item) => ( {item.loai} {item.tongChiPhi.toLocaleString()} ))} {/* Footer */} Tổng cộng {tongCong.toLocaleString()} ); }; export default TripCostTable;