123 lines
3.9 KiB
TypeScript
123 lines
3.9 KiB
TypeScript
import { IconSymbol } from "@/components/ui/icon-symbol";
|
|
import React, { useRef, useState } from "react";
|
|
import { Animated, Text, TouchableOpacity, View } from "react-native";
|
|
import styles from "./style/NetListTable.styles";
|
|
|
|
// ---------------------------
|
|
// 🧩 Interface
|
|
// ---------------------------
|
|
interface NetItem {
|
|
id: string;
|
|
stt: string;
|
|
trangThai: string;
|
|
}
|
|
|
|
// ---------------------------
|
|
// 🧵 Dữ liệu mẫu
|
|
// ---------------------------
|
|
const data: NetItem[] = [
|
|
{ id: "1", stt: "Mẻ 3", trangThai: "Đã hoàn thành" },
|
|
{ id: "2", stt: "Mẻ 2", trangThai: "Đã hoàn thành" },
|
|
{ id: "3", stt: "Mẻ 1", trangThai: "Đã hoàn thành" },
|
|
];
|
|
|
|
const NetListTable: React.FC = () => {
|
|
const [collapsed, setCollapsed] = useState(true);
|
|
const [contentHeight, setContentHeight] = useState<number>(0);
|
|
const animatedHeight = useRef(new Animated.Value(0)).current;
|
|
const tongSoMe = data.length;
|
|
|
|
const handleToggle = () => {
|
|
const toValue = collapsed ? contentHeight : 0;
|
|
Animated.timing(animatedHeight, {
|
|
toValue,
|
|
duration: 300,
|
|
useNativeDriver: false,
|
|
}).start();
|
|
setCollapsed((prev) => !prev);
|
|
};
|
|
|
|
const handleStatusPress = (id: string) => {
|
|
console.log(`ID mẻ lưới: ${id}`);
|
|
};
|
|
|
|
return (
|
|
<View style={styles.container}>
|
|
{/* Header toggle */}
|
|
<TouchableOpacity
|
|
activeOpacity={0.7}
|
|
onPress={handleToggle}
|
|
style={styles.headerRow}
|
|
>
|
|
<Text style={styles.title}>Danh sách mẻ lưới</Text>
|
|
{collapsed && <Text style={styles.totalCollapsed}>{tongSoMe}</Text>}
|
|
<IconSymbol
|
|
name={collapsed ? "arrowshape.down.fill" : "arrowshape.up.fill"}
|
|
size={16}
|
|
color="#000"
|
|
/>
|
|
</TouchableOpacity>
|
|
|
|
{/* Nội dung ẩn để đo chiều cao */}
|
|
<View
|
|
style={{ position: "absolute", opacity: 0, zIndex: -1000 }}
|
|
onLayout={(event) => {
|
|
const height = event.nativeEvent.layout.height;
|
|
if (height > 0 && contentHeight === 0) {
|
|
setContentHeight(height);
|
|
}
|
|
}}
|
|
>
|
|
{/* Header */}
|
|
<View style={[styles.row, styles.tableHeader]}>
|
|
<Text style={[styles.sttCell, styles.headerText]}>STT</Text>
|
|
<Text style={[styles.cell, styles.headerText]}>Trạng thái</Text>
|
|
</View>
|
|
|
|
{/* Body */}
|
|
{data.map((item) => (
|
|
<View key={item.id} style={styles.row}>
|
|
{/* Cột STT */}
|
|
<Text style={styles.sttCell}>{item.stt}</Text>
|
|
|
|
{/* Cột Trạng thái */}
|
|
<View style={[styles.cell, styles.statusContainer]}>
|
|
<View style={styles.statusDot} />
|
|
<TouchableOpacity onPress={() => handleStatusPress(item.id)}>
|
|
<Text style={styles.statusText}>{item.trangThai}</Text>
|
|
</TouchableOpacity>
|
|
</View>
|
|
</View>
|
|
))}
|
|
</View>
|
|
|
|
{/* Bảng hiển thị với animation */}
|
|
<Animated.View style={{ height: animatedHeight, overflow: "hidden" }}>
|
|
{/* Header */}
|
|
<View style={[styles.row, styles.tableHeader]}>
|
|
<Text style={[styles.sttCell, styles.headerText]}>STT</Text>
|
|
<Text style={[styles.cell, styles.headerText]}>Trạng thái</Text>
|
|
</View>
|
|
|
|
{/* Body */}
|
|
{data.map((item) => (
|
|
<View key={item.id} style={styles.row}>
|
|
{/* Cột STT */}
|
|
<Text style={styles.sttCell}>{item.stt}</Text>
|
|
|
|
{/* Cột Trạng thái */}
|
|
<View style={[styles.cell, styles.statusContainer]}>
|
|
<View style={styles.statusDot} />
|
|
<TouchableOpacity onPress={() => handleStatusPress(item.id)}>
|
|
<Text style={styles.statusText}>{item.trangThai}</Text>
|
|
</TouchableOpacity>
|
|
</View>
|
|
</View>
|
|
))}
|
|
</Animated.View>
|
|
</View>
|
|
);
|
|
};
|
|
|
|
export default NetListTable;
|