@@ -5,7 +5,6 @@ import Immutable from 'seamless-immutable';
55import PropTypes from 'prop-types' ;
66import uniq from 'lodash/uniq' ;
77import styled from '@stream-io/styled-components' ;
8- import { ActionSheetCustom as ActionSheet } from 'react-native-actionsheet' ;
98
109import { logChatPromiseExecution } from 'stream-chat' ;
1110
@@ -21,14 +20,13 @@ import { pickImage, pickDocument } from '../../native';
2120import { FileState , ACITriggerSettings } from '../../utils' ;
2221import { themed } from '../../styles/theme' ;
2322
23+ import ActionSheetAttachment from './ActionSheetAttachment' ;
2424import SendButton from './SendButton' ;
2525import AttachButton from './AttachButton' ;
2626import ImageUploadPreview from './ImageUploadPreview' ;
2727import FileUploadPreview from './FileUploadPreview' ;
2828import { AutoCompleteInput } from '../AutoCompleteInput' ;
2929
30- import iconGallery from '../../images/icons/icon_attach-media.png' ;
31- import iconFolder from '../../images/icons/icon_folder.png' ;
3230import iconClose from '../../images/icons/icon_close.png' ;
3331
3432// https://stackoverflow.com/a/6860916/2570866
@@ -87,35 +85,6 @@ const InputBoxContainer = styled.View`
8785 ${ ( { theme } ) => theme . messageInput . inputBoxContainer . css }
8886` ;
8987
90- const ActionSheetTitleContainer = styled . View `
91- flex-direction: row;
92- justify-content: space-between;
93- align-items: center;
94- width: 100%;
95- height: 100%;
96- padding-left: 20;
97- padding-right: 20;
98- ${ ( { theme } ) => theme . messageInput . actionSheet . titleContainer . css } ;
99- ` ;
100-
101- const ActionSheetTitleText = styled . Text `
102- font-weight: bold;
103- ${ ( { theme } ) => theme . messageInput . actionSheet . titleText . css } ;
104- ` ;
105-
106- const ActionSheetButtonContainer = styled . View `
107- flex-direction: row;
108- align-items: center;
109- justify-content: flex-start;
110- width: 100%;
111- padding-left: 20;
112- ${ ( { theme } ) => theme . messageInput . actionSheet . buttonContainer . css } ;
113- ` ;
114-
115- const ActionSheetButtonText = styled . Text `
116- ${ ( { theme } ) => theme . messageInput . actionSheet . buttonText . css } ;
117- ` ;
118-
11988/**
12089 * UI Component for message input
12190 * Its a consumer of [Channel Context](https://getstream.github.io/stream-chat-react-native/#channelcontext)
@@ -210,6 +179,15 @@ class MessageInput extends PureComponent {
210179 * Defaults to and accepts same props as: [AttachButton](https://getstream.github.io/stream-chat-react-native/#attachbutton)
211180 * */
212181 AttachButton : PropTypes . oneOfType ( [ PropTypes . node , PropTypes . elementType ] ) ,
182+ /**
183+ * Custom UI component for ActionSheetAttachment.
184+ *
185+ * Defaults to and accepts same props as: [ActionSheetAttachment](https://getstream.github.io/stream-chat-react-native/#actionsheetattachment)
186+ * */
187+ ActionSheetAttachment : PropTypes . oneOfType ( [
188+ PropTypes . node ,
189+ PropTypes . elementType ,
190+ ] ) ,
213191 /**
214192 * Additional props for underlying TextInput component. These props will be forwarded as it is to TextInput component.
215193 *
@@ -238,12 +216,13 @@ class MessageInput extends PureComponent {
238216 } ;
239217
240218 static defaultProps = {
241- hasImagePicker : true ,
242- hasFilePicker : true ,
219+ ActionSheetAttachment ,
220+ AttachButton ,
243221 disabled : false ,
244- sendImageAsync : false ,
222+ hasFilePicker : true ,
223+ hasImagePicker : true ,
245224 SendButton,
246- AttachButton ,
225+ sendImageAsync : false ,
247226 } ;
248227
249228 getMessageDetailsForState = ( message , initialValue ) => {
@@ -840,7 +819,8 @@ class MessageInput extends PureComponent {
840819 text : this . state . text + text ,
841820 } ) ;
842821 } ;
843- setInputBoxRef = ( o ) => ( this . inputBox = o ) ;
822+
823+ setInputBoxRef = ( o ) => ( this . attachActionSheet = o ) ;
844824
845825 closeAttachActionSheet = ( ) => {
846826 this . attachActionSheet . hide ( ) ;
@@ -892,43 +872,11 @@ class MessageInput extends PureComponent {
892872 work well with async onPress operations. So find a solution.
893873 */ }
894874
895- < ActionSheet
896- ref = { ( o ) => ( this . attachActionSheet = o ) }
897- title = {
898- < ActionSheetTitleContainer >
899- < ActionSheetTitleText > { t ( 'Add a file' ) } </ ActionSheetTitleText >
900- < IconSquare
901- icon = { iconClose }
902- onPress = { this . closeAttachActionSheet }
903- />
904- </ ActionSheetTitleContainer >
905- }
906- options = { [
907- /* eslint-disable */
908- < AttachmentActionSheetItem
909- icon = { iconGallery }
910- text = { t ( 'Upload a photo' ) }
911- /> ,
912- < AttachmentActionSheetItem
913- icon = { iconFolder }
914- text = { t ( 'Upload a file' ) }
915- /> ,
916- /* eslint-enable */
917- ] }
918- onPress = { ( index ) => {
919- // https://github.com/beefe/react-native-actionsheet/issues/36
920- setTimeout ( ( ) => {
921- switch ( index ) {
922- case 0 :
923- this . _pickImage ( ) ;
924- break ;
925- case 1 :
926- this . _pickFile ( ) ;
927- break ;
928- default :
929- }
930- } , 201 ) ; // 201ms to fire after the animation is complete https://github.com/beefe/react-native-actionsheet/blob/master/lib/ActionSheetCustom.js#L78
931- } }
875+ < ActionSheetAttachment
876+ setAttachActionSheetRef = { this . setInputBoxRef }
877+ closeAttachActionSheet = { this . closeAttachActionSheet }
878+ pickFile = { this . _pickFile }
879+ pickImage = { this . _pickImage }
932880 styles = { this . props . actionSheetStyles }
933881 />
934882 < InputBoxContainer ref = { this . props . setInputBoxContainerRef } >
@@ -1044,10 +992,3 @@ export default withTranslationContext(
1044992 withSuggestionsContext ( withChannelContext ( themed ( MessageInput ) ) ) ,
1045993 ) ,
1046994) ;
1047-
1048- const AttachmentActionSheetItem = ( { icon, text } ) => (
1049- < ActionSheetButtonContainer >
1050- < IconSquare icon = { icon } />
1051- < ActionSheetButtonText > { text } </ ActionSheetButtonText >
1052- </ ActionSheetButtonContainer >
1053- ) ;
0 commit comments