/** * 聊天输入框组件 * 支持响应式布局(宽屏下居中显示) */ import React, { useMemo } from 'react'; import { View, TouchableOpacity, TextInput, ActivityIndicator } from 'react-native'; import { MaterialCommunityIcons } from '@expo/vector-icons'; import { Text } from '../../../../components/common'; import { colors } from '../../../../theme'; import { chatScreenStyles as baseStyles } from './styles'; import { useBreakpointGTE } from '../../../../hooks/useResponsive'; import { ChatInputProps, GroupMessage, SenderInfo } from './types'; import { extractTextFromSegments } from '../../../../types/dto'; export const ChatInput: React.FC SenderInfo; }> = ({ inputText, onInputChange, onSend, onToggleEmoji, onToggleMore, activePanel, sending, isMuted, isGroupChat, muteAll, replyingTo, onCancelReply, onFocus, restrictionHint, disableMore = false, currentUser, otherUser, getSenderInfo, }) => { const isDisabled = isGroupChat && isMuted; // 获取当前用户ID const currentUserId = currentUser?.id || ''; // 响应式布局 const isWideScreen = useBreakpointGTE('lg'); const styles = baseStyles; const inputContainerStyle = useMemo(() => ([ styles.inputContainer, isWideScreen ? { maxWidth: 900, alignSelf: 'center' as const, width: '100%' as const } : null, ]), [isWideScreen, styles.inputContainer]); // 回复预览组件 - 定义在内部以访问 styles const ReplyPreview: React.FC<{ replyingTo: GroupMessage; onCancel: () => void; }> = ({ replyingTo, onCancel }) => { const senderInfo = replyingTo.sender_id === currentUserId ? { nickname: '我', avatar: currentUser?.avatar } : isGroupChat ? getSenderInfo(replyingTo.sender_id) : { nickname: otherUser?.nickname || '对方', avatar: otherUser?.avatar }; return ( 回复 {senderInfo.nickname} {replyingTo.segments?.some(seg => seg.type === 'image') ? '[图片]' : extractTextFromSegments(replyingTo.segments)} ); }; return ( {/* 回复预览 */} {replyingTo && ( )} {/* 禁言提示 */} {isGroupChat && isMuted && ( {muteAll ? '全员禁言中,暂无法发送消息' : '你已被禁言,暂无法发送消息'} )} {!!restrictionHint && ( {restrictionHint} )} {inputText.trim() && !sending && !isDisabled ? ( ) : sending ? ( ) : ( )} ); }; export default ChatInput;