import React from 'react'; import { TouchableOpacity } from 'react-native-gesture-handler'; import { MessageInputContextValue, useMessageInputContext, } from '../../contexts/messageInputContext/MessageInputContext'; import { useTheme } from '../../contexts/themeContext/ThemeContext'; import { Search } from '../../icons/Search'; import { SendRight } from '../../icons/SendRight'; import { SendUp } from '../../icons/SendUp'; import type { DefaultAttachmentType, DefaultChannelType, DefaultCommandType, DefaultEventType, DefaultMessageType, DefaultReactionType, DefaultUserType, UnknownType, } from '../../types/types'; type SendButtonPropsWithContext< At extends UnknownType = DefaultAttachmentType, Ch extends UnknownType = DefaultChannelType, Co extends string = DefaultCommandType, Ev extends UnknownType = DefaultEventType, Me extends UnknownType = DefaultMessageType, Re extends UnknownType = DefaultReactionType, Us extends UnknownType = DefaultUserType, > = Pick, 'giphyActive' | 'sendMessage'> & { /** Disables the button */ disabled: boolean; }; const SendButtonWithContext = < At extends UnknownType = DefaultAttachmentType, Ch extends UnknownType = DefaultChannelType, Co extends string = DefaultCommandType, Ev extends UnknownType = DefaultEventType, Me extends UnknownType = DefaultMessageType, Re extends UnknownType = DefaultReactionType, Us extends UnknownType = DefaultUserType, >( props: SendButtonPropsWithContext, ) => { const { disabled = false, giphyActive, sendMessage } = props; const { theme: { colors: { accent_blue, grey_gainsboro }, messageInput: { sendButton }, }, } = useTheme(); return ( null : sendMessage} style={[sendButton]} testID='send-button' > {giphyActive && } {!giphyActive && disabled && } {!giphyActive && !disabled && } ); }; const areEqual = < At extends UnknownType = DefaultAttachmentType, Ch extends UnknownType = DefaultChannelType, Co extends string = DefaultCommandType, Ev extends UnknownType = DefaultEventType, Me extends UnknownType = DefaultMessageType, Re extends UnknownType = DefaultReactionType, Us extends UnknownType = DefaultUserType, >( prevProps: SendButtonPropsWithContext, nextProps: SendButtonPropsWithContext, ) => { const { disabled: prevDisabled, giphyActive: prevGiphyActive, sendMessage: prevSendMessage, } = prevProps; const { disabled: nextDisabled, giphyActive: nextGiphyActive, sendMessage: nextSendMessage, } = nextProps; const disabledEqual = prevDisabled === nextDisabled; if (!disabledEqual) return false; const giphyActiveEqual = prevGiphyActive === nextGiphyActive; if (!giphyActiveEqual) return false; const sendMessageEqual = prevSendMessage === nextSendMessage; if (!sendMessageEqual) return false; return true; }; const MemoizedSendButton = React.memo( SendButtonWithContext, areEqual, ) as typeof SendButtonWithContext; export type SendButtonProps< At extends UnknownType = DefaultAttachmentType, Ch extends UnknownType = DefaultChannelType, Co extends string = DefaultCommandType, Ev extends UnknownType = DefaultEventType, Me extends UnknownType = DefaultMessageType, Re extends UnknownType = DefaultReactionType, Us extends UnknownType = DefaultUserType, > = Partial>; /** * UI Component for send button in MessageInput component. */ export const SendButton = < At extends UnknownType = DefaultAttachmentType, Ch extends UnknownType = DefaultChannelType, Co extends string = DefaultCommandType, Ev extends UnknownType = DefaultEventType, Me extends UnknownType = DefaultMessageType, Re extends UnknownType = DefaultReactionType, Us extends UnknownType = DefaultUserType, >( props: SendButtonProps, ) => { const { giphyActive, sendMessage } = useMessageInputContext(); return ( ); }; SendButton.displayName = 'SendButton{messageInput}';