import { IconSymbol } from "@/components/ui/icon-symbol"; // biểu tượng giống dự án bạn import React, { useRef, useState } from "react"; import { Animated, Platform, Text, TouchableOpacity, UIManager, View, } from "react-native"; import styles from "./style/FishingToolsTable.styles"; // --------------------------- // 🧩 Interface // --------------------------- interface ToolItem { id: string; ten: string; soLuong: number; } // --------------------------- // 🎣 Dữ liệu mẫu // --------------------------- const data: ToolItem[] = [ { id: "1", ten: "Lưới kéo", soLuong: 1 }, { id: "2", ten: "Cần câu", soLuong: 1 }, { id: "3", ten: "Mồi câu", soLuong: 5 }, ]; const FishingToolsTable: React.FC = () => { // Bật animation trên 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 tongSoLuong = data.reduce((sum, item) => sum + item.soLuong, 0); const handleToggle = () => { const toValue = collapsed ? contentHeight : 0; Animated.timing(animatedHeight, { toValue, duration: 300, useNativeDriver: false, }).start(); setCollapsed((prev) => !prev); }; return ( {/* Header / Toggle */} Danh sách ngư cụ {collapsed && {tongSoLuong}} {/* Nội dung ẩn để đo chiều cao */} { const height = event.nativeEvent.layout.height; if (height > 0 && contentHeight === 0) { setContentHeight(height); } }} > {/* Table Header */} Tên Số lượng {/* Body */} {data.map((item) => ( {item.ten} {item.soLuong} ))} {/* Footer */} Tổng cộng {tongSoLuong} {/* Nội dung mở/đóng */} {/* Table Header */} Tên Số lượng {/* Body */} {data.map((item) => ( {item.ten} {item.soLuong} ))} {/* Footer */} Tổng cộng {tongSoLuong} ); }; export default FishingToolsTable;