import React, { useState } from "react"; import customRF from '../utils/customRF'; import { View, Text, StyleSheet, TextInput, TouchableOpacity, FlatList, KeyboardAvoidingView, Platform, ImageBackground, } from "react-native"; import { useNavigation } from "@react-navigation/native"; import { NativeStackNavigationProp } from "@react-navigation/native-stack"; import { RootStackParamList } from "../../App"; interface Message { id: string; text: string; isMe: boolean; timestamp: Date; } type TabType = "customer" | "product" | "notification"; export const ChatScreen = () => { const [messages, setMessages] = useState([]); const [inputText, setInputText] = useState(""); const [activeTab, setActiveTab] = useState("customer"); const sendMessage = () => { if (inputText.trim() === "") return; const newMessage: Message = { id: Date.now().toString(), text: inputText, isMe: true, timestamp: new Date(), }; setMessages([...messages, newMessage]); setInputText(""); }; const renderMessage = ({ item }: { item: Message }) => ( {item.text} {item.timestamp.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", })} ); const renderTabContent = () => { switch (activeTab) { case "customer": return ( item.id} contentContainerStyle={styles.messageList} showsVerticalScrollIndicator={false} /> ); case "product": return ( item.id} contentContainerStyle={styles.messageList} showsVerticalScrollIndicator={false} /> ); case "notification": return ( item.id} contentContainerStyle={styles.messageList} showsVerticalScrollIndicator={false} /> ); } }; return ( setActiveTab("customer")} > 客服聊天 setActiveTab("product")} > 产品聊天 setActiveTab("notification")} > 消息通知 {renderTabContent()} 发送 ); }; const styles = StyleSheet.create({ container: { flex: 1, }, backgroundImage: { flex: 1, width: '100%', height: '100%', }, tabBar: { flexDirection: "row", backgroundColor: "#007a6c", borderBottomWidth: 1, borderBottomColor: "#eef0f1", shadowColor: "#000", shadowOffset: { width: 0, height: 2, }, shadowOpacity: 0.25, shadowRadius: 3.84, elevation: 5, }, tab: { flex: 1, paddingVertical: 15, alignItems: "center", }, activeTab: { borderBottomWidth: 2, borderBottomColor: "#eef0f1", }, tabText: { fontSize: customRF(14), color: "#fff", }, activeTabText: { color: "#fff", fontWeight: "600", }, tabContent: { flex: 1, }, messageList: { padding: 10, }, messageContainer: { maxWidth: "80%", padding: 10, borderRadius: 10, marginVertical: 5, }, myMessage: { alignSelf: "flex-end", backgroundColor: "#dcf8c6", }, theirMessage: { alignSelf: "flex-start", backgroundColor: "white", }, messageText: { fontSize: 16, }, timestamp: { fontSize: 12, color: "#666", alignSelf: "flex-end", marginTop: 5, }, inputContainer: { flexDirection: "row", padding: 10, backgroundColor: "white", borderTopWidth: 1, borderTopColor: "#ddd", }, input: { flex: 1, backgroundColor: "#f0f0f0", borderRadius: 20, paddingHorizontal: 15, paddingVertical: 8, marginRight: 10, maxHeight: 100, }, sendButton: { backgroundColor: "#128C7E", borderRadius: 20, paddingHorizontal: 20, justifyContent: "center", }, sendButtonText: { color: "white", fontSize: 16, }, });