import { ChatBubble, TimeSeparator, TypingIndicator } from '@/components/chat/ChatBubble'; import { ChatInput } from '@/components/chat/ChatInput'; import { AppColors } from '@/constants/theme'; import { getCurrentTimeString, getRandomAIResponse, Message, mockConversations, mockMessages, } from '@/data/mockData'; import { Ionicons } from '@expo/vector-icons'; import { router, useLocalSearchParams } from 'expo-router'; import React, { useEffect, useRef, useState } from 'react'; import { KeyboardAvoidingView, Platform, ScrollView, StyleSheet, Text, TouchableOpacity, View, } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; export default function ChatDetailScreen() { const { id } = useLocalSearchParams<{ id: string }>(); const scrollViewRef = useRef(null); const [messages, setMessages] = useState(mockMessages); const [isTyping, setIsTyping] = useState(false); // Find conversation info const conversation = mockConversations.find(c => c.id === id) || mockConversations[0]; // Scroll to bottom when messages change useEffect(() => { setTimeout(() => { scrollViewRef.current?.scrollToEnd({ animated: true }); }, 100); }, [messages, isTyping]); const handleSendMessage = (text: string) => { // Add user message const userMessage: Message = { id: `m${Date.now()}`, conversationId: id || '1', senderType: 'user', contentType: 'text', content: text, timestamp: getCurrentTimeString(), }; setMessages(prev => [...prev, userMessage]); // Simulate AI typing setTimeout(() => { setIsTyping(true); }, 500); // Add AI response after delay setTimeout(() => { setIsTyping(false); const aiMessage: Message = { id: `m${Date.now() + 1}`, conversationId: id || '1', senderType: 'ai', contentType: 'text', content: getRandomAIResponse(), timestamp: getCurrentTimeString(), }; setMessages(prev => [...prev, aiMessage]); }, 1500 + Math.random() * 1000); }; const handleBack = () => { router.back(); }; return ( {/* Header */} {conversation.title} 在线 {/* Messages */} {messages.map((message) => ( ))} {isTyping && } {/* Input Area */} { // Voice input placeholder console.log('Voice input pressed'); }} onEmojiPress={() => { // Emoji picker placeholder console.log('Emoji picker pressed'); }} onMorePress={() => { // More options placeholder console.log('More options pressed'); }} /> ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: AppColors.mediumPurple, }, header: { height: 62, flexDirection: 'row', alignItems: 'center', paddingHorizontal: 16, backgroundColor: AppColors.mediumPurple, }, backButton: { width: 40, height: 40, borderRadius: 12, backgroundColor: 'rgba(255, 255, 255, 0.2)', alignItems: 'center', justifyContent: 'center', }, headerTitleArea: { flex: 1, alignItems: 'center', marginRight: 40, // Balance the back button }, headerTitle: { fontSize: 18, fontWeight: '600', color: AppColors.white, }, headerStatus: { fontSize: 12, color: 'rgba(255, 255, 255, 0.8)', marginTop: 2, }, messageContainer: { flex: 1, backgroundColor: AppColors.cream, }, messageList: { flex: 1, backgroundColor: AppColors.cream, }, messageListContent: { paddingVertical: 16, }, });