11import React , { useEffect , useState } from 'react' ;
2- import {
3- Keyboard ,
4- StyleSheet ,
5- Text ,
6- TouchableOpacity ,
7- View ,
8- } from 'react-native' ;
2+ import { StyleSheet , Text , TouchableOpacity , View } from 'react-native' ;
93
104import { AttachmentSelectionBar } from '../AttachmentPicker/components/AttachmentSelectionBar' ;
115import { AutoCompleteInput } from '../AutoCompleteInput/AutoCompleteInput' ;
@@ -122,20 +116,15 @@ type MessageInputPropsWithContext<
122116 Pick <
123117 MessageInputContextValue < At , Ch , Co , Ev , Me , Re , Us > ,
124118 | 'additionalTextInputProps'
125- | 'appendText'
126119 | 'asyncIds'
127120 | 'asyncUploads'
128- | 'AttachButton'
129- | 'CommandsButton'
130121 | 'clearEditingState'
131122 | 'clearQuotedMessageState'
123+ | 'closeAttachmentPicker'
132124 | 'editing'
133125 | 'FileUploadPreview'
134126 | 'fileUploads'
135127 | 'giphyActive'
136- | 'hasCommands'
137- | 'hasFilePicker'
138- | 'hasImagePicker'
139128 | 'ImageUploadPreview'
140129 | 'imageUploads'
141130 | 'Input'
@@ -144,21 +133,17 @@ type MessageInputPropsWithContext<
144133 | 'isValidMessage'
145134 | 'maxNumberOfFiles'
146135 | 'mentionedUsers'
147- | 'MoreOptionsButton'
148136 | 'numberOfUploads'
149- | 'pickFile'
150137 | 'quotedMessage'
151138 | 'resetInput'
152139 | 'SendButton'
153140 | 'sending'
154141 | 'sendMessageAsync'
155142 | 'setGiphyActive'
156- | 'setShowMoreOptions'
157143 | 'showMoreOptions'
158144 | 'ShowThreadMessageInChannelButton'
159145 | 'removeImage'
160146 | 'uploadNewImage'
161- | 'uploadsEnabled'
162147 > &
163148 Pick < MessagesContextValue < At , Ch , Co , Ev , Me , Re , Us > , 'Reply' > &
164149 Pick <
@@ -182,19 +167,17 @@ export const MessageInputWithContext = <
182167) => {
183168 const {
184169 additionalTextInputProps,
185- appendText,
186170 asyncIds,
187171 asyncUploads,
188172 clearEditingState,
189173 clearQuotedMessageState,
174+ closeAttachmentPicker,
190175 componentType,
191176 disabled,
192177 editing,
193178 FileUploadPreview,
194179 fileUploads,
195180 giphyActive,
196- hasFilePicker,
197- hasImagePicker,
198181 ImageUploadPreview,
199182 imageUploads,
200183 Input,
@@ -205,7 +188,6 @@ export const MessageInputWithContext = <
205188 members,
206189 mentionedUsers,
207190 numberOfUploads,
208- pickFile,
209191 quotedMessage,
210192 removeImage,
211193 Reply,
@@ -259,23 +241,24 @@ export const MessageInputWithContext = <
259241 attachmentPickerBottomSheetHeight,
260242 attachmentSelectionBarHeight,
261243 bottomInset,
262- closePicker,
263- openPicker,
264244 selectedImages,
265245 selectedPicker,
266246 setMaxNumberOfFiles,
267247 setSelectedImages,
268- setSelectedPicker,
269248 } = useAttachmentPickerContext ( ) ;
270249
250+ /**
251+ * Mounting and un-mounting logic are un-related in following useEffect.
252+ * While mounting we want to pass maxNumberOfFiles (which is prop on Channel component)
253+ * to AttachmentPicker (on OverlayProvider)
254+ *
255+ * While un-mounting, we want to close the picker e.g., while navigating away.
256+ */
271257 useEffect ( ( ) => {
272258 setMaxNumberOfFiles ( maxNumberOfFiles ?? 10 ) ;
273259
274- return ( ) => {
275- closePicker ( ) ;
276- setSelectedPicker ( undefined ) ;
277- } ;
278- } , [ maxNumberOfFiles ] ) ;
260+ return closeAttachmentPicker ;
261+ } , [ ] ) ;
279262
280263 const selectedImagesLength = selectedImages . length ;
281264 const imageUploadsLength = imageUploads . length ;
@@ -408,45 +391,6 @@ export const MessageInputWithContext = <
408391 return result ;
409392 } ;
410393
411- const openAttachmentPicker = ( ) => {
412- if ( hasImagePicker && ! fileUploads . length ) {
413- Keyboard . dismiss ( ) ;
414- openPicker ( ) ;
415- setSelectedPicker ( 'images' ) ;
416- } else if ( hasFilePicker && numberOfUploads < maxNumberOfFiles ) {
417- pickFile ( ) ;
418- }
419- } ;
420-
421- const closeAttachmentPicker = ( ) => {
422- if ( selectedPicker ) {
423- setSelectedPicker ( undefined ) ;
424- closePicker ( ) ;
425- }
426- } ;
427-
428- const toggleAttachmentPicker = ( ) => {
429- if ( selectedPicker ) {
430- closeAttachmentPicker ( ) ;
431- } else {
432- openAttachmentPicker ( ) ;
433- }
434- } ;
435-
436- const openCommandsPicker = ( ) => {
437- appendText ( '/' ) ;
438- if ( inputBoxRef . current ) {
439- inputBoxRef . current . focus ( ) ;
440- }
441- } ;
442-
443- const openMentionsPicker = ( ) => {
444- appendText ( '@' ) ;
445- if ( inputBoxRef . current ) {
446- inputBoxRef . current . focus ( ) ;
447- }
448- } ;
449-
450394 const additionalTextInputContainerProps = {
451395 editable : disabled ? false : undefined ,
452396 ...additionalTextInputProps ,
@@ -506,27 +450,12 @@ export const MessageInputWithContext = <
506450 { Input ? (
507451 < Input
508452 additionalTextInputProps = { additionalTextInputContainerProps }
509- closeAttachmentPicker = { closeAttachmentPicker }
510453 getUsers = { getUsers }
511- openAttachmentPicker = { openAttachmentPicker }
512- openCommandsPicker = { openCommandsPicker }
513- openFilePicker = { pickFile }
514- openMentionsPicker = { openMentionsPicker }
515- toggleAttachmentPicker = { toggleAttachmentPicker }
516454 />
517455 ) : (
518456 < >
519457 < View style = { [ styles . optionsContainer , optionsContainer ] } >
520- { InputButtons && (
521- < InputButtons
522- closeAttachmentPicker = { closeAttachmentPicker }
523- openAttachmentPicker = { openAttachmentPicker }
524- openCommandsPicker = { openCommandsPicker }
525- openFilePicker = { pickFile }
526- openMentionsPicker = { openMentionsPicker }
527- toggleAttachmentPicker = { toggleAttachmentPicker }
528- />
529- ) }
458+ { InputButtons && < InputButtons /> }
530459 </ View >
531460 < View
532461 style = { [
@@ -794,20 +723,15 @@ export const MessageInput = <
794723
795724 const {
796725 additionalTextInputProps,
797- appendText,
798726 asyncIds,
799727 asyncUploads,
800- AttachButton,
801728 clearEditingState,
802729 clearQuotedMessageState,
803- CommandsButton ,
730+ closeAttachmentPicker ,
804731 editing,
805732 FileUploadPreview,
806733 fileUploads,
807734 giphyActive,
808- hasCommands,
809- hasFilePicker,
810- hasImagePicker,
811735 ImageUploadPreview,
812736 imageUploads,
813737 Input,
@@ -816,21 +740,17 @@ export const MessageInput = <
816740 isValidMessage,
817741 maxNumberOfFiles,
818742 mentionedUsers,
819- MoreOptionsButton,
820743 numberOfUploads,
821- pickFile,
822744 quotedMessage,
823745 removeImage,
824746 resetInput,
825747 SendButton,
826748 sending,
827749 sendMessageAsync,
828750 setGiphyActive,
829- setShowMoreOptions,
830751 showMoreOptions,
831752 ShowThreadMessageInChannelButton,
832753 uploadNewImage,
833- uploadsEnabled,
834754 } = useMessageInputContext < At , Ch , Co , Ev , Me , Re , Us > ( ) ;
835755
836756 const { Reply } = useMessagesContext < At , Ch , Co , Ev , Me , Re , Us > ( ) ;
@@ -847,22 +767,17 @@ export const MessageInput = <
847767 < MemoizedMessageInput
848768 { ...{
849769 additionalTextInputProps,
850- appendText,
851770 asyncIds,
852771 asyncUploads,
853- AttachButton,
854772 clearEditingState,
855773 clearQuotedMessageState,
856- CommandsButton ,
774+ closeAttachmentPicker ,
857775 componentType,
858776 disabled,
859777 editing,
860778 FileUploadPreview,
861779 fileUploads,
862780 giphyActive,
863- hasCommands,
864- hasFilePicker,
865- hasImagePicker,
866781 ImageUploadPreview,
867782 imageUploads,
868783 Input,
@@ -872,9 +787,7 @@ export const MessageInput = <
872787 maxNumberOfFiles,
873788 members,
874789 mentionedUsers,
875- MoreOptionsButton,
876790 numberOfUploads,
877- pickFile,
878791 quotedMessage,
879792 removeImage,
880793 Reply,
@@ -883,14 +796,12 @@ export const MessageInput = <
883796 sending,
884797 sendMessageAsync,
885798 setGiphyActive,
886- setShowMoreOptions,
887799 showMoreOptions,
888800 ShowThreadMessageInChannelButton,
889801 suggestions,
890802 suggestionsTitle,
891803 t,
892804 uploadNewImage,
893- uploadsEnabled,
894805 watchers,
895806 } }
896807 { ...props }
0 commit comments