@@ -4,30 +4,32 @@ import { Pressable } from 'react-native';
44
55import { NativeAttachmentPicker } from './components/NativeAttachmentPicker' ;
66
7- import { useAttachmentPickerContext } from '../../contexts/attachmentPickerContext/AttachmentPickerContext' ;
7+ import {
8+ AttachmentPickerContextValue ,
9+ useAttachmentPickerContext ,
10+ } from '../../contexts/attachmentPickerContext/AttachmentPickerContext' ;
811import {
912 MessageInputContextValue ,
1013 useMessageInputContext ,
1114} from '../../contexts/messageInputContext/MessageInputContext' ;
1215import { useTheme } from '../../contexts/themeContext/ThemeContext' ;
1316import { Attach } from '../../icons/Attach' ;
1417
15- import { isImageMediaLibraryAvailable } from '../../native' ;
16-
1718type AttachButtonPropsWithContext = Pick <
1819 MessageInputContextValue ,
1920 'handleAttachButtonPress' | 'toggleAttachmentPicker'
20- > & {
21- disabled ?: boolean ;
22- /** Function that opens attachment options bottom sheet */
23- handleOnPress ?: ( ( event : GestureResponderEvent ) => void ) & ( ( ) => void ) ;
24- selectedPicker ?: 'images' ;
25- } ;
21+ > &
22+ Pick < AttachmentPickerContextValue , 'disableAttachmentPicker' | 'selectedPicker' > & {
23+ disabled ?: boolean ;
24+ /** Function that opens attachment options bottom sheet */
25+ handleOnPress ?: ( ( event : GestureResponderEvent ) => void ) & ( ( ) => void ) ;
26+ } ;
2627
2728const AttachButtonWithContext = ( props : AttachButtonPropsWithContext ) => {
2829 const [ showAttachButtonPicker , setShowAttachButtonPicker ] = useState < boolean > ( false ) ;
2930 const [ attachButtonLayoutRectangle , setAttachButtonLayoutRectangle ] = useState < LayoutRectangle > ( ) ;
3031 const {
32+ disableAttachmentPicker,
3133 disabled = false ,
3234 handleAttachButtonPress,
3335 handleOnPress,
@@ -73,7 +75,7 @@ const AttachButtonWithContext = (props: AttachButtonPropsWithContext) => {
7375 handleAttachButtonPress ( ) ;
7476 return ;
7577 }
76- if ( isImageMediaLibraryAvailable ( ) ) {
78+ if ( ! disableAttachmentPicker ) {
7779 toggleAttachmentPicker ( ) ;
7880 } else {
7981 attachButtonHandler ( ) ;
@@ -132,12 +134,17 @@ export type AttachButtonProps = Partial<AttachButtonPropsWithContext>;
132134 * UI Component for attach button in MessageInput component.
133135 */
134136export const AttachButton = ( props : AttachButtonProps ) => {
135- const { selectedPicker } = useAttachmentPickerContext ( ) ;
137+ const { disableAttachmentPicker , selectedPicker } = useAttachmentPickerContext ( ) ;
136138 const { handleAttachButtonPress, toggleAttachmentPicker } = useMessageInputContext ( ) ;
137139
138140 return (
139141 < MemoizedAttachButton
140- { ...{ handleAttachButtonPress, selectedPicker, toggleAttachmentPicker } }
142+ { ...{
143+ disableAttachmentPicker,
144+ handleAttachButtonPress,
145+ selectedPicker,
146+ toggleAttachmentPicker,
147+ } }
141148 { ...props }
142149 />
143150 ) ;
0 commit comments