import { IconSymbol } from "@/components/ui/icon-symbol"; import { useFishes } from "@/state/use-fish"; import { useTrip } from "@/state/use-trip"; import React, { useEffect, useRef, useState } from "react"; import { Animated, Text, TouchableOpacity, View } from "react-native"; import CreateOrUpdateHaulModal from "./modal/CreateOrUpdateHaulModal"; import styles from "./style/NetListTable.styles"; const NetListTable: React.FC = () => { const [collapsed, setCollapsed] = useState(true); const [contentHeight, setContentHeight] = useState(0); const animatedHeight = useRef(new Animated.Value(0)).current; const [modalVisible, setModalVisible] = useState(false); const [selectedNet, setSelectedNet] = useState(null); const { trip } = useTrip(); const { fishSpecies, getFishSpecies } = useFishes(); useEffect(() => { getFishSpecies(); }, []); // useEffect(() => { // console.log("Trip thay đổi: ", trip?.fishing_logs?.length); // }, [trip]); // const data: Model.FishingLog[] = trip?.fishing_logs ?? []; const handleToggle = () => { const toValue = collapsed ? contentHeight : 0; Animated.timing(animatedHeight, { toValue, duration: 300, useNativeDriver: false, }).start(); setCollapsed((prev) => !prev); }; const handleStatusPress = (id: string) => { const net = trip?.fishing_logs?.find((item) => item.fishing_log_id === id); if (net) { setSelectedNet(net); setModalVisible(true); } }; return ( {/* Header toggle */} Danh sách mẻ lưới {collapsed && ( {trip?.fishing_logs?.length} )} {/* Nội dung ẩn để đo chiều cao */} { const height = event.nativeEvent.layout.height; // Update measured content height whenever it actually changes. if (height > 0 && height !== contentHeight) { setContentHeight(height); // If the panel is currently expanded, animate to the new height so // newly added/removed rows become visible immediately. if (!collapsed) { Animated.timing(animatedHeight, { toValue: height, duration: 200, useNativeDriver: false, }).start(); } } }} > {/* Header */} STT Trạng thái {/* Body */} {trip?.fishing_logs?.map((item, index) => ( {/* Cột STT */} Mẻ {index + 1} {/* Cột Trạng thái */} handleStatusPress(item.fishing_log_id)} > {item.status ? "Đã hoàn thành" : "Chưa hoàn thành"} ))} {/* Bảng hiển thị với animation */} {/* Header */} STT Trạng thái {/* Body */} {trip?.fishing_logs?.map((item, index) => ( {/* Cột STT */} Mẻ {index + 1} {/* Cột Trạng thái */} handleStatusPress(item.fishing_log_id)} > {item.status ? "Đã hoàn thành" : "Chưa hoàn thành"} ))} { console.log("OnCLose"); setModalVisible(false); }} fishingLog={selectedNet} fishingLogIndex={ selectedNet ? trip!.fishing_logs!.findIndex( (item) => item.fishing_log_id === selectedNet.fishing_log_id ) + 1 : undefined } /> {/* Modal chi tiết */} {/* { console.log("OnCLose"); setModalVisible(false); }} netData={selectedNet} /> */} ); }; export default NetListTable;