import CancelSvg from '@/assets/icons/svg/cancel.svg'; import DownloadSvg from '@/assets/icons/svg/download.svg'; import FolderSvg from "@/assets/icons/svg/folder.svg"; import ReturnArrow from "@/assets/icons/svg/returnArrow.svg"; import YesSvg from "@/assets/icons/svg/yes.svg"; import { TFunction } from "i18next"; import React from "react"; import { FlatList, Image, Modal, StyleSheet, TouchableOpacity, View } from "react-native"; import ContextMenu from "../gusture/contextMenu"; import { ThemedText } from "../ThemedText"; import { mergeArrays, saveMediaToGallery } from "./utils"; interface SelectModelProps { modalDetailsVisible: { visible: boolean, content: any }; setModalDetailsVisible: React.Dispatch>; insets: { top: number }; setSelectedImages: React.Dispatch>; selectedImages: string[]; t: TFunction; cancel: boolean; setCancel: React.Dispatch>; } const SelectModel = ({ modalDetailsVisible, setModalDetailsVisible, insets, setSelectedImages, selectedImages, t, cancel, setCancel }: SelectModelProps) => { return ( { setModalDetailsVisible({ visible: false, content: [] }); }} > setModalDetailsVisible({ visible: false, content: [] })}> {t('ask.selectPhoto', { ns: 'ask' })} item.id} showsVerticalScrollIndicator={false} contentContainerStyle={detailsStyles.gridContainer} initialNumToRender={12} maxToRenderPerBatch={12} updateCellsBatchingPeriod={50} windowSize={10} removeClippedSubviews={true} renderItem={({ item }) => { const itemId = item?.id || item?.video?.id; const isSelected = selectedImages.includes(itemId); const toggleSelection = () => { setSelectedImages(prev => isSelected ? prev.filter(id => id !== itemId) : [...prev, itemId] ); }; return ( {isSelected && ( {selectedImages.indexOf(itemId) + 1} )} , label: "保存", onPress: () => { const imageUrl = item?.file_info?.url || item.video?.file_info?.url; if (imageUrl) { saveMediaToGallery(imageUrl, t); } }, textStyle: { color: '#4C320C' } }, { svg: , label: "取消", onPress: () => console.log('取消'), textStyle: { color: 'red' } } ]} menuStyle={{ backgroundColor: 'white', borderRadius: 8, padding: 8, minWidth: 150, shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.25, shadowRadius: 4, elevation: 5, }} > console.log('Image load error:', error.nativeEvent.error)} onLoad={() => console.log('Image loaded successfully')} loadingIndicatorSource={require('@/assets/images/png/placeholder.png')} /> { setSelectedImages(prev => isSelected ? prev.filter(id => id !== itemId) : [...prev, itemId] ); }} activeOpacity={0.8} > {isSelected && } ); }} /> { // 如果用户没有选择 则为选择全部 if (selectedImages?.length < 0) { setSelectedImages(mergeArrays(modalDetailsVisible?.content?.image_material_infos || [], modalDetailsVisible?.content?.video_material_infos || [])?.map((item) => { return item.id || item.video?.id })) } setModalDetailsVisible({ visible: false, content: [] }) }} activeOpacity={0.8} > {t('ask.continueAsking', { ns: 'ask' })} ) } const detailsStyles = StyleSheet.create({ gridContainer: { flex: 1, paddingHorizontal: 8, paddingTop: 8, }, gridItemContainer: { width: '33.33%', aspectRatio: 1, padding: 1, }, flatListContent: { paddingBottom: 100, paddingHorizontal: 8, paddingTop: 8, }, headerText: { fontSize: 20, fontWeight: 'bold', color: "#4C320C" }, container: { flex: 1, padding: 0, margin: 0, backgroundColor: '#fff', width: '100%', height: '100%', position: 'relative', }, imageNumber: { fontSize: 16, fontWeight: 'bold', color: '#fff', position: 'absolute', top: 10, left: 10, zIndex: 10, }, imageNumberText: { fontSize: 16, fontWeight: 'bold', color: '#fff', }, numberText: { position: 'absolute', top: 10, left: 10, width: 28, height: 28, borderRadius: 14, backgroundColor: 'rgba(0, 122, 255, 0.9)', justifyContent: 'center', alignItems: 'center', shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.25, shadowRadius: 3.84, elevation: 5, }, header: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', padding: 16, borderBottomWidth: 1, borderBottomColor: '#eee', }, gridItem: { flex: 1, backgroundColor: '#f5f5f5', borderRadius: 8, overflow: 'hidden', position: 'relative', }, image: { width: '100%', height: '100%', resizeMode: 'cover', }, circleMarker: { position: 'absolute', top: 10, right: 10, width: 28, height: 28, borderRadius: 14, justifyContent: 'center', alignItems: 'center', borderWidth: 2, borderColor: '#fff', }, circleMarkerSelected: { backgroundColor: '#FFB645', }, markerText: { fontSize: 16, fontWeight: 'bold', color: '#000', }, footer: { position: 'absolute', bottom: 20, left: 0, right: 0, paddingHorizontal: 16, zIndex: 10, paddingVertical: 10, }, continueButton: { backgroundColor: '#E2793F', borderRadius: 32, padding: 16, alignItems: 'center', width: '100%', zIndex: 10, }, continueButtonText: { color: '#fff', fontSize: 18, fontWeight: 'bold', } }); export default SelectModel