import React from 'react'; import { TouchableOpacity } from 'react-native-gesture-handler'; import { useAttachmentPickerContext } from '../../contexts/attachmentPickerContext/AttachmentPickerContext'; import { ChannelContextValue, useChannelContext, } from '../../contexts/channelContext/ChannelContext'; import { useTheme } from '../../contexts/themeContext/ThemeContext'; import { Attach } from '../../icons/Attach'; import type { GestureResponderEvent } from 'react-native'; import type { DefaultAttachmentType, DefaultChannelType, DefaultCommandType, DefaultEventType, DefaultMessageType, DefaultReactionType, DefaultUserType, UnknownType, } from '../../types/types'; type AttachButtonPropsWithContext< 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, 'disabled'> & { /** Function that opens attachment options bottom sheet */ handleOnPress?: ((event: GestureResponderEvent) => void) & (() => void); selectedPicker?: 'images'; }; const AttachButtonWithContext = < 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: AttachButtonPropsWithContext, ) => { const { disabled, handleOnPress, selectedPicker } = props; const { theme: { colors: { accent_blue, grey }, messageInput: { attachButton }, }, } = useTheme(); return ( null : handleOnPress} style={[attachButton]} testID='attach-button' > ); }; 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: AttachButtonPropsWithContext, nextProps: AttachButtonPropsWithContext, ) => { const { disabled: prevDisabled, handleOnPress: prevHandleOnPress, selectedPicker: prevSelectedPicker, } = prevProps; const { disabled: nextDisabled, handleOnPress: nextHandleOnPress, selectedPicker: nextSelectedPicker, } = nextProps; const disabledEqual = prevDisabled === nextDisabled; if (!disabledEqual) return false; const handleOnPressEqual = prevHandleOnPress === nextHandleOnPress; if (!handleOnPressEqual) return false; const selectedPickerEqual = prevSelectedPicker === nextSelectedPicker; if (!selectedPickerEqual) return false; return true; }; const MemoizedAttachButton = React.memo( AttachButtonWithContext, areEqual, ) as typeof AttachButtonWithContext; export type AttachButtonProps< 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 attach button in MessageInput component. */ export const AttachButton = < 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: AttachButtonProps, ) => { const { disabled = false } = useChannelContext(); const { selectedPicker } = useAttachmentPickerContext(); return ; }; AttachButton.displayName = 'AttachButton{messageInput}';