1b6261296S猫头猫import React, {memo} from 'react'; 2b6261296S猫头猫import {Pressable, StyleSheet, View} from 'react-native'; 3b6261296S猫头猫import rpx from '@/utils/rpx'; 4b6261296S猫头猫import ThemeText from '@/components/base/themeText'; 5b6261296S猫头猫import useTextColor from '@/hooks/useTextColor'; 6e650bfb3S猫头猫import Checkbox from '@/components/base/checkbox'; 7e650bfb3S猫头猫import {TouchableOpacity} from 'react-native-gesture-handler'; 8*5589cdf3S猫头猫import Icon from '@/components/base/icon.tsx'; 9b6261296S猫头猫 10b6261296S猫头猫const ITEM_HEIGHT = rpx(96); 11b6261296S猫头猫 12b6261296S猫头猫interface IProps { 13b6261296S猫头猫 type: 'folder' | 'file'; 14b6261296S猫头猫 path: string; 15b6261296S猫头猫 parentPath: string; 16b6261296S猫头猫 checked?: boolean; 17b6261296S猫头猫 onItemPress: (currentChecked?: boolean) => void; 18b6261296S猫头猫 onCheckedChange: (checked: boolean) => void; 19b6261296S猫头猫} 20b6261296S猫头猫function FileItem(props: IProps) { 21b6261296S猫头猫 const { 22b6261296S猫头猫 type, 23b6261296S猫头猫 path, 24b6261296S猫头猫 parentPath, 25b6261296S猫头猫 checked, 26b6261296S猫头猫 onItemPress, 27b6261296S猫头猫 onCheckedChange: onCheckChange, 28b6261296S猫头猫 } = props; 29b6261296S猫头猫 30b6261296S猫头猫 const textColor = useTextColor(); 31b6261296S猫头猫 32b6261296S猫头猫 // 返回逻辑 33b6261296S猫头猫 34b6261296S猫头猫 return ( 35e650bfb3S猫头猫 <View style={styles.container}> 36b6261296S猫头猫 <Pressable 37b6261296S猫头猫 onPress={() => { 38b6261296S猫头猫 onItemPress(checked); 39b6261296S猫头猫 }} 40e650bfb3S猫头猫 style={styles.pathWrapper}> 41b6261296S猫头猫 <Icon 42*5589cdf3S猫头猫 name={ 43*5589cdf3S猫头猫 type === 'folder' 44*5589cdf3S猫头猫 ? 'folder-outline' 45*5589cdf3S猫头猫 : 'document-outline' 46*5589cdf3S猫头猫 } 47b6261296S猫头猫 color={textColor} 48e650bfb3S猫头猫 style={styles.folderIcon} 49b6261296S猫头猫 /> 50b6261296S猫头猫 <ThemeText 51e650bfb3S猫头猫 style={styles.path} 52b6261296S猫头猫 numberOfLines={1} 53b6261296S猫头猫 ellipsizeMode="tail"> 54b6261296S猫头猫 {path.substring( 55b6261296S猫头猫 parentPath === '/' ? 1 : parentPath.length + 1, 56b6261296S猫头猫 )} 57b6261296S猫头猫 </ThemeText> 58b6261296S猫头猫 </Pressable> 59e650bfb3S猫头猫 <TouchableOpacity 60b6261296S猫头猫 onPress={() => { 61b6261296S猫头猫 onCheckChange(!checked); 62b6261296S猫头猫 }} 63e650bfb3S猫头猫 style={styles.checkIcon}> 64e650bfb3S猫头猫 <Checkbox checked={checked} /> 65e650bfb3S猫头猫 </TouchableOpacity> 66b6261296S猫头猫 </View> 67b6261296S猫头猫 ); 68b6261296S猫头猫} 69b6261296S猫头猫 70b6261296S猫头猫export default memo( 71b6261296S猫头猫 FileItem, 72b6261296S猫头猫 (prev, curr) => 73b6261296S猫头猫 prev.checked === curr.checked && 74b6261296S猫头猫 prev.parentPath === curr.parentPath && 75b6261296S猫头猫 prev.path === curr.path, 76b6261296S猫头猫); 77b6261296S猫头猫 78e650bfb3S猫头猫const styles = StyleSheet.create({ 79e650bfb3S猫头猫 container: { 80e0caea6eS猫头猫 width: '100%', 81b6261296S猫头猫 height: ITEM_HEIGHT, 82b6261296S猫头猫 paddingHorizontal: rpx(24), 83b6261296S猫头猫 flexDirection: 'row', 84b6261296S猫头猫 alignItems: 'center', 85b6261296S猫头猫 justifyContent: 'space-between', 86b6261296S猫头猫 }, 87b6261296S猫头猫 folderIcon: { 88b6261296S猫头猫 fontSize: rpx(32), 89b6261296S猫头猫 marginRight: rpx(14), 90b6261296S猫头猫 }, 91b6261296S猫头猫 pathWrapper: { 92b6261296S猫头猫 flexDirection: 'row', 93b6261296S猫头猫 flex: 1, 94b6261296S猫头猫 alignItems: 'center', 95b6261296S猫头猫 height: '100%', 96b6261296S猫头猫 marginRight: rpx(60), 97b6261296S猫头猫 }, 98b6261296S猫头猫 path: { 99b6261296S猫头猫 height: '100%', 100b6261296S猫头猫 textAlignVertical: 'center', 101b6261296S猫头猫 }, 102e650bfb3S猫头猫 checkIcon: { 103e650bfb3S猫头猫 padding: rpx(14), 104e650bfb3S猫头猫 }, 105b6261296S猫头猫}); 106