import React, { useMemo, useState } from 'react'; import { View, Text, FlatList, TouchableOpacity, StyleSheet, Animated, } from 'react-native'; import { Colors } from '../theme/colors'; import { FontSize, FontWeight, Radius, Spacing } from '../theme/layout'; import { useSlideDetailAnimation } from './useSlideDetailAnimation'; import { t } from '../../i18n'; interface LogListItem { id: string; } interface LogListScreenProps { data: T[]; renderRow: (item: T) => React.ReactElement; renderListHeader?: () => React.ReactElement; renderDetailHeader?: (item: T) => React.ReactNode; renderDetailBody: (item: T) => React.ReactElement; emptyText: string; reversed?: boolean; } export function LogListScreen({ data, renderRow, renderListHeader, renderDetailHeader, renderDetailBody, emptyText, reversed = true, }: LogListScreenProps) { const [selected, setSelected] = useState(null); const { detailTranslateX, listTranslateX, listOpacity } = useSlideDetailAnimation(selected); const displayData = useMemo( () => (reversed ? [...data].reverse() : data), [data, reversed], ); return ( {renderListHeader?.()} {displayData.length === 0 ? ( — {emptyText} ) : ( ( setSelected(item)} activeOpacity={0.6} > {renderRow(item)} )} keyExtractor={(item) => item.id} contentContainerStyle={styles.listContent} initialNumToRender={20} maxToRenderPerBatch={10} windowSize={5} removeClippedSubviews={true} /> )} {selected && ( setSelected(null)} style={styles.backBtn} activeOpacity={0.6} > ‹ {t('common.back')} {renderDetailHeader?.(selected)} {renderDetailBody(selected)} )} ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: Colors.background }, listWrap: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }, listContent: { padding: Spacing.SM }, emptyContainer: { flex: 1, alignItems: 'center', justifyContent: 'center' }, emptyIcon: { fontSize: 32, color: Colors.textMuted, marginBottom: Spacing.XS }, empty: { textAlign: 'center', color: Colors.textMuted, fontSize: FontSize.SM }, card: { backgroundColor: Colors.surface, borderRadius: Radius.MD, borderWidth: 1, borderColor: Colors.borderLight, marginBottom: Spacing.SM, overflow: 'hidden', }, detailOverlay: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, backgroundColor: Colors.background, }, detailWrap: { flex: 1, backgroundColor: Colors.background }, detailHeader: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: Spacing.SM, paddingVertical: Spacing.SM, backgroundColor: Colors.surface, borderBottomWidth: 1, borderBottomColor: Colors.panelDivider, gap: Spacing.SM, }, backBtn: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: Spacing.XS, paddingVertical: 2, borderRadius: Radius.SM, }, backIcon: { fontSize: 22, fontWeight: FontWeight.regular, color: Colors.primary, marginTop: -2, marginRight: Spacing.XXS, }, backText: { fontSize: FontSize.LG, color: Colors.primary, fontWeight: FontWeight.medium, }, });