import * as React from 'react'; import { Animated, Platform, StyleSheet, View } from 'react-native'; import { useConfigContext } from '../../config'; // import { uilog } from '../../const'; import { useColors } from '../../hook'; import { useI18nContext } from '../../i18n'; import { ChatConversationType } from '../../rename.chat'; import { usePaletteContext, useThemeContext } from '../../theme'; import { CmnButton, IconButton, IconButtonMemo } from '../../ui/Button'; import { KeyboardAvoidingView } from '../../ui/Keyboard'; import { TextInput } from '../../ui/TextInput'; import { EmojiListMemo } from '../EmojiList'; import { BottomVoiceBar } from '../VoiceBar'; import { useMessageInput } from './MessageInput.hooks'; import { MessageInputEditMessage } from './MessageInputEditMessage'; import { MessageInputQuoteView } from './MessageInputQuoteView'; import type { MessageInputProps, MessageInputRef } from './types'; /** * Message Input Component. * * This component can send text, send emoticons, send files, send pictures, send voice, send files, etc. You can customize the sending menu and add a UI for sending custom messages. Usually this component is used in conjunction with the `MessageList` component. */ export const MessageInput = React.forwardRef< MessageInputRef, MessageInputProps >(function ( props: React.PropsWithChildren, ref?: React.ForwardedRef ) { const { top, numberOfLines = 4, multiSelectCount, unreadCount, onClickedUnreadCount, convType, type: comType, } = props; const testRef = React.useRef | null>(null); const { fontFamily } = useConfigContext(); const { tr } = useI18nContext(); const { style } = useThemeContext(); const { colors } = usePaletteContext(); const { getColor } = useColors({ input_bg: { light: colors.neutral[95], dark: colors.neutral[2], }, enable_trash: { light: colors.error[5], dark: colors.error[6], }, }); const { value, setValue, onClickedFaceListItem, onClickedDelButton, onClickedEmojiButton, onClickedVoiceButton, inputRef, emojiHeight, emojiIconName, onFocus, onBlur, onCloseVoiceBar, voiceBarRef, onSelectSendVoice, onVoiceStateChange, menuRef, onRequestCloseMenu, sendIconName, onClickedSend, onVoiceFailed, showQuote, onHideQuoteMessage, onRequestCloseEdit, editRef, onEditMessageFinished, quoteMsg, onClickedEmojiSend, emojiList, multiSelectVisible, onClickedMultiSelectDeleteButton, onClickedMultiSelectShareButton, onKeyPress, msgPinBackgroundCurrentOpacity, msgPinHeightRef, MessageInputBarMenu, messageInputBarStyle, androidKeyboardAvoidOffset, } = useMessageInput(props, ref); const androidKeyboardAvoidingStyle = React.useMemo(() => { if (Platform.OS !== 'android') { return undefined; } return { paddingBottom: androidKeyboardAvoidOffset, }; }, [androidKeyboardAvoidOffset]); const inputContent = ( <> {unreadCount && unreadCount > 0 ? ( 99 ? '99+' : unreadCount )} style={{ backgroundColor: getColor('bg') }} textStyle={{ color: getColor('enable') }} onPress={onClickedUnreadCount} /> ) : null} {showQuote === true ? ( ) : null} { const { width, height } = event.nativeEvent.layout; // uilog.log( // '[KBAvoid] InputBar onLayout (android branch):', // 'w:', // width, // 'h:', // height, // 'paddingBottom:', // androidKeyboardAvoidOffset // ); } : undefined } > {(convType === ChatConversationType.GroupChat || convType === ChatConversationType.PeerChat) && comType === 'chat' ? ( ) : null} ); return ( <> {multiSelectVisible === true ? ( 0 ? 'enable_trash' : 'disable2' ), }} containerStyle={{ margin: 12, }} onPress={onClickedMultiSelectDeleteButton} iconName={'trash'} /> 0 ? 'enable' : 'disable2' ), }} containerStyle={{ margin: 12, }} onPress={onClickedMultiSelectShareButton} iconName={'arrowshape_right'} /> ) : ( <> {Platform.OS === 'ios' ? ( {inputContent} ) : ( {inputContent} )} {messageInputBarStyle === 'extension' && MessageInputBarMenu !== null ? ( ) : null} )} {messageInputBarStyle === 'bottom-sheet' && MessageInputBarMenu !== null ? ( ) : null} ); }); export type MessageInputComponent = typeof MessageInput;