@@ -5,13 +5,19 @@ import { Pressable } from 'react-native';
55import { NativeAttachmentPicker } from './components/NativeAttachmentPicker' ;
66
77import { useAttachmentPickerContext } from '../../contexts/attachmentPickerContext/AttachmentPickerContext' ;
8- import { useMessageInputContext } from '../../contexts/messageInputContext/MessageInputContext' ;
8+ import {
9+ MessageInputContextValue ,
10+ useMessageInputContext ,
11+ } from '../../contexts/messageInputContext/MessageInputContext' ;
912import { useTheme } from '../../contexts/themeContext/ThemeContext' ;
1013import { Attach } from '../../icons/Attach' ;
1114
1215import { isImageMediaLibraryAvailable } from '../../native' ;
1316
14- type AttachButtonPropsWithContext = {
17+ type AttachButtonPropsWithContext = Pick <
18+ MessageInputContextValue ,
19+ 'handleAttachButtonPress' | 'toggleAttachmentPicker'
20+ > & {
1521 disabled ?: boolean ;
1622 /** Function that opens attachment options bottom sheet */
1723 handleOnPress ?: ( ( event : GestureResponderEvent ) => void ) & ( ( ) => void ) ;
@@ -21,14 +27,19 @@ type AttachButtonPropsWithContext = {
2127const AttachButtonWithContext = ( props : AttachButtonPropsWithContext ) => {
2228 const [ showAttachButtonPicker , setShowAttachButtonPicker ] = useState < boolean > ( false ) ;
2329 const [ attachButtonLayoutRectangle , setAttachButtonLayoutRectangle ] = useState < LayoutRectangle > ( ) ;
24- const { disabled = false , handleOnPress, selectedPicker } = props ;
30+ const {
31+ disabled = false ,
32+ handleAttachButtonPress,
33+ handleOnPress,
34+ selectedPicker,
35+ toggleAttachmentPicker,
36+ } = props ;
2537 const {
2638 theme : {
2739 colors : { accent_blue, grey } ,
2840 messageInput : { attachButton } ,
2941 } ,
3042 } = useTheme ( ) ;
31- const { handleAttachButtonPress, toggleAttachmentPicker } = useMessageInputContext ( ) ;
3243
3344 const onAttachButtonLayout = ( event : LayoutChangeEvent ) => {
3445 const layout = event . nativeEvent . layout ;
@@ -122,8 +133,14 @@ export type AttachButtonProps = Partial<AttachButtonPropsWithContext>;
122133 */
123134export const AttachButton = ( props : AttachButtonProps ) => {
124135 const { selectedPicker } = useAttachmentPickerContext ( ) ;
136+ const { handleAttachButtonPress, toggleAttachmentPicker } = useMessageInputContext ( ) ;
125137
126- return < MemoizedAttachButton { ...{ selectedPicker } } { ...props } /> ;
138+ return (
139+ < MemoizedAttachButton
140+ { ...{ handleAttachButtonPress, selectedPicker, toggleAttachmentPicker } }
141+ { ...props }
142+ />
143+ ) ;
127144} ;
128145
129146AttachButton . displayName = 'AttachButton{messageInput}' ;
0 commit comments