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