import ChatSvg from "@/assets/icons/svg/chat.svg"; import MoreSvg from "@/assets/icons/svg/more.svg"; import { Message, Video } from "@/types/ask"; import { MaterialItem } from "@/types/personal-info"; import { useVideoPlayer, VideoView } from 'expo-video'; import React from 'react'; import { Image, Modal, Pressable, StyleProp, StyleSheet, Text, TouchableOpacity, View, ViewStyle } from 'react-native'; import { ThemedText } from "../ThemedText"; import TypewriterText from "./typewriterText"; import { mergeArrays } from "./utils"; interface RenderMessageProps { item: Message; sessionId: string; setModalVisible: React.Dispatch>; modalVisible: { visible: boolean, data: Video | MaterialItem }; } const renderMessage = ({ item, sessionId, setModalVisible, modalVisible }: RenderMessageProps) => { const isUser = item.role === 'User'; const isVideo = (data: Video | MaterialItem): data is Video => { return 'video' in data; }; // 创建一个新的 VideoPlayer 组件 const VideoPlayer = ({ videoUrl, style, onPress }: { videoUrl: string; style?: StyleProp; onPress?: () => void; }) => { const player = useVideoPlayer(videoUrl, (player) => { player.loop = true; player.play(); }); return ( ); }; return ( {!isUser && } 0 || item.content.image_material_infos && item.content.image_material_infos.length > 0) ? '!rounded-t-3xl !rounded-b-2xl' : '!rounded-3xl'}`} > {!isUser ? sessionId ? item.content.text : : item.content.text } {(item.content.image_material_infos && item.content.image_material_infos.length > 0 || item.content.video_material_infos && item.content.video_material_infos.length > 0) && ( {mergeArrays(item.content.image_material_infos || [], item.content.video_material_infos || [])?.slice(0, 3)?.map((image, index, array) => ( { setModalVisible({ visible: true, data: image }); }} style={({ pressed }) => [ array.length === 1 ? styles.fullWidthImage : styles.gridImage, array.length === 2 && { width: '49%' }, array.length >= 3 && { width: '32%' }, { opacity: pressed ? 0.8 : 1 } // 添加按下效果 ]} > ))} { ((item.content.video_material_infos?.length || 0) + (item.content.image_material_infos?.length || 0)) > 3 && {((item.content.video_material_infos?.length || 0) + (item.content.image_material_infos?.length || 0))} } )} {/* {item.askAgain && item.askAgain.length > 0 && ( {item.askAgain.map((suggestion, index, array) => ( {suggestion.text} ))} )} */} { setModalVisible({ visible: false, data: {} as Video | MaterialItem }); }}> { setModalVisible({ visible: false, data: {} as Video | MaterialItem }) }} /> setModalVisible({ visible: false, data: {} as Video | MaterialItem })}> {isVideo(modalVisible.data) ? ( // 视频播放器 setModalVisible({ visible: false, data: {} as Video | MaterialItem })} > setModalVisible({ visible: false, data: {} as Video | MaterialItem })} /> ) : ( // 图片预览 setModalVisible({ visible: false, data: {} as Video | MaterialItem })} style={styles.imageContainer} > )} ); }; export default renderMessage; const styles = StyleSheet.create({ video: { width: '100%', height: '100%', }, imageContainer: { flex: 1, justifyContent: 'center', alignItems: 'center', width: '100%', maxHeight: '60%', }, fullWidthImage: { width: '100%', height: "54%", marginBottom: 8, }, gridImage: { aspectRatio: 1, marginBottom: 8, }, background: { ...StyleSheet.absoluteFillObject, backgroundColor: 'rgba(0, 0, 0, 0.5)', // 添加半透明黑色背景 }, centeredView: { flex: 1, justifyContent: 'center', alignItems: 'center', }, modalView: { borderRadius: 20, alignItems: 'center', height: '100%', width: "100%", justifyContent: 'center', alignSelf: 'center', }, container: { flex: 1, backgroundColor: '#f5f5f5', }, userAvatar: { width: 30, height: 30, borderRadius: 15, }, messageList: { padding: 16, }, messageBubble: { paddingHorizontal: 16, paddingVertical: 12, fontWeight: "600" }, userBubble: { alignSelf: 'flex-end', backgroundColor: '#FFB645', marginLeft: '20%', }, aiBubble: { alignSelf: 'flex-start', backgroundColor: '#fff', marginRight: '20%', borderWidth: 1, borderColor: '#e5e5ea', }, userText: { color: '#4C320C', fontSize: 16, }, aiText: { color: '#000', fontSize: 16, }, });