@@ -4,12 +4,7 @@ import { I18nManager, StyleSheet, Text, TouchableOpacity, View } from 'react-nat
44import dayjs from 'dayjs' ;
55import duration from 'dayjs/plugin/duration' ;
66
7- import {
8- FileUpload ,
9- MessageInputContextValue ,
10- useMessageInputContext ,
11- useTheme ,
12- } from '../../contexts' ;
7+ import { FileUpload , useTheme } from '../../contexts' ;
138import { Pause , Play } from '../../icons' ;
149import {
1510 PlaybackStatus ,
@@ -18,7 +13,6 @@ import {
1813 VideoPayloadData ,
1914 VideoProgressData ,
2015} from '../../native' ;
21- import type { DefaultStreamChatGenerics } from '../../types/types' ;
2216import { ProgressControl } from '../ProgressControl/ProgressControl' ;
2317
2418dayjs . extend ( duration ) ;
@@ -76,27 +70,17 @@ const styles = StyleSheet.create({
7670 } ,
7771} ) ;
7872
79- export type AudioAttachmentPropsWithContext <
80- StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ,
81- > = Pick <
82- MessageInputContextValue < StreamChatGenerics > ,
83- 'fileUploads' | 'removeFile' | 'uploadFile'
84- > & {
85- index : number ;
73+ export type AudioAttachmentPropsWithContext = {
8674 item : Omit < FileUpload , 'state' > ;
8775 onLoad : ( index : string , duration : number ) => void ;
8876 onPlayPause : ( index : string , pausedStatus ?: boolean ) => void ;
8977 onProgress : ( index : string , currentTime ?: number , hasEnd ?: boolean ) => void ;
9078 testID ?: string ;
9179} ;
9280
93- const AudioAttachmentWithContext = <
94- StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ,
95- > (
96- props : AudioAttachmentPropsWithContext < StreamChatGenerics > ,
97- ) => {
81+ const AudioAttachmentWithContext = ( props : AudioAttachmentPropsWithContext ) => {
9882 const soundRef = React . useRef < SoundReturnType | null > ( null ) ;
99- const { fileUploads , index , item, onLoad, onPlayPause, onProgress } = props ;
83+ const { item, onLoad, onPlayPause, onProgress } = props ;
10084
10185 const handleLoad = ( payload : VideoPayloadData ) => {
10286 onLoad ( item . id , payload . duration ) ;
@@ -212,11 +196,10 @@ const AudioAttachmentWithContext = <
212196
213197 const {
214198 theme : {
215- colors : { accent_blue, black, grey_dark, grey_whisper , static_black, static_white, white } ,
199+ colors : { accent_blue, black, grey_dark, static_black, static_white } ,
216200 messageInput : {
217201 fileUploadPreview : {
218202 audioAttachment : { progressControlView, progressDurationText, roundedView } ,
219- fileContainer,
220203 fileContentContainer,
221204 filenameText,
222205 fileTextContainer,
@@ -236,103 +219,82 @@ const AudioAttachmentWithContext = <
236219 const lastIndexOfDot = item . file . name . lastIndexOf ( '.' ) ;
237220
238221 return (
239- < View
240- style = { [
241- styles . fileContainer ,
242- index === fileUploads . length - 1
243- ? {
244- marginBottom : 0 ,
245- }
246- : { } ,
247- {
248- backgroundColor : white ,
249- borderColor : grey_whisper ,
250- width : - 16 ,
251- } ,
252- fileContainer ,
253- ] }
254- testID = 'audio-attachment-upload-preview'
255- >
256- < View style = { [ styles . fileContentContainer , fileContentContainer ] } >
257- < TouchableOpacity
258- accessibilityLabel = 'Play Pause Button'
259- onPress = { ( ) => handlePlayPause ( ) }
222+ < View style = { [ styles . fileContentContainer , fileContentContainer ] } >
223+ < TouchableOpacity
224+ accessibilityLabel = 'Play Pause Button'
225+ onPress = { ( ) => handlePlayPause ( ) }
226+ style = { [
227+ styles . roundedView ,
228+ roundedView ,
229+ { backgroundColor : static_white , shadowColor : black } ,
230+ ] }
231+ >
232+ { item . paused ? (
233+ < Play height = { 24 } pathFill = { static_black } width = { 24 } />
234+ ) : (
235+ < Pause height = { 24 } pathFill = { static_black } width = { 24 } />
236+ ) }
237+ </ TouchableOpacity >
238+ < View style = { [ styles . fileTextContainer , fileTextContainer ] } >
239+ < Text
240+ accessibilityLabel = 'File Name'
241+ numberOfLines = { 1 }
260242 style = { [
261- styles . roundedView ,
262- roundedView ,
263- { backgroundColor : static_white , shadowColor : black } ,
243+ styles . filenameText ,
244+ {
245+ color : black ,
246+ width :
247+ 16 - // 16 = horizontal padding
248+ 40 - // 40 = file icon size
249+ 24 - // 24 = close icon size
250+ 24 , // 24 = internal padding
251+ } ,
252+ I18nManager . isRTL ? { writingDirection : 'rtl' } : { writingDirection : 'ltr' } ,
253+ filenameText ,
264254 ] }
265255 >
266- { item . paused ? (
267- < Play height = { 24 } pathFill = { static_black } width = { 24 } />
268- ) : (
269- < Pause height = { 24 } pathFill = { static_black } width = { 24 } />
256+ { item . file . name . slice ( 0 , 12 ) + '...' + item . file . name . slice ( lastIndexOfDot ) }
257+ </ Text >
258+ < View
259+ style = { {
260+ alignItems : 'center' ,
261+ display : 'flex' ,
262+ flexDirection : 'row' ,
263+ } }
264+ >
265+ { /* <ExpoSoundPlayer filePaused={!!item.paused} soundRef={soundRef} /> */ }
266+ { Sound . Player && (
267+ < Sound . Player
268+ onEnd = { handleEnd }
269+ onLoad = { handleLoad }
270+ onProgress = { handleProgress }
271+ paused = { item . paused as boolean }
272+ soundRef = { soundRef }
273+ testID = 'sound-player'
274+ uri = { item . file . uri }
275+ />
270276 ) }
271- </ TouchableOpacity >
272- < View style = { [ styles . fileTextContainer , fileTextContainer ] } >
273- < Text
274- accessibilityLabel = 'File Name'
275- numberOfLines = { 1 }
276- style = { [
277- styles . filenameText ,
278- {
279- color : black ,
280- width :
281- 16 - // 16 = horizontal padding
282- 40 - // 40 = file icon size
283- 24 - // 24 = close icon size
284- 24 , // 24 = internal padding
285- } ,
286- I18nManager . isRTL ? { writingDirection : 'rtl' } : { writingDirection : 'ltr' } ,
287- filenameText ,
288- ] }
289- >
290- { item . file . name . slice ( 0 , 12 ) + '...' + item . file . name . slice ( lastIndexOfDot ) }
277+ < Text style = { [ styles . progressDurationText , { color : grey_dark } , progressDurationText ] } >
278+ { progressDuration }
291279 </ Text >
292- < View
293- style = { {
294- alignItems : 'center' ,
295- display : 'flex' ,
296- flexDirection : 'row' ,
297- } }
298- >
299- { /* <ExpoSoundPlayer filePaused={!!item.paused} soundRef={soundRef} /> */ }
300- { Sound . Player && (
301- < Sound . Player
302- onEnd = { handleEnd }
303- onLoad = { handleLoad }
304- onProgress = { handleProgress }
305- paused = { item . paused as boolean }
306- soundRef = { soundRef }
307- testID = 'sound-player'
308- uri = { item . file . uri }
309- />
310- ) }
311- < Text style = { [ styles . progressDurationText , { color : grey_dark } , progressDurationText ] } >
312- { progressDuration }
313- </ Text >
314- < View style = { [ styles . progressControlView , progressControlView ] } >
315- < ProgressControl
316- duration = { item . duration as number }
317- filledColor = { accent_blue }
318- onPlayPause = { handlePlayPause }
319- onProgressDrag = { handleProgressDrag }
320- progress = { item . progress as number }
321- testID = 'progress-control'
322- width = { 120 }
323- />
324- </ View >
280+ < View style = { [ styles . progressControlView , progressControlView ] } >
281+ < ProgressControl
282+ duration = { item . duration as number }
283+ filledColor = { accent_blue }
284+ onPlayPause = { handlePlayPause }
285+ onProgressDrag = { handleProgressDrag }
286+ progress = { item . progress as number }
287+ testID = 'progress-control'
288+ width = { 120 }
289+ />
325290 </ View >
326291 </ View >
327292 </ View >
328293 </ View >
329294 ) ;
330295} ;
331296
332- export type AudioAttachmentProps <
333- StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ,
334- > = Partial < AudioAttachmentPropsWithContext < StreamChatGenerics > > & {
335- index : number ;
297+ export type AudioAttachmentProps = Partial < AudioAttachmentPropsWithContext > & {
336298 item : Omit < FileUpload , 'state' > ;
337299 onLoad : ( index : string , duration : number ) => void ;
338300 onPlayPause : ( index : string , pausedStatus ?: boolean ) => void ;
@@ -344,14 +306,8 @@ export type AudioAttachmentProps<
344306 * AudioAttachment
345307 * UI Component to preview the audio files
346308 */
347- export const AudioAttachment = <
348- StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ,
349- > (
350- props : AudioAttachmentProps < StreamChatGenerics > ,
351- ) => {
352- const { fileUploads, removeFile, uploadFile } = useMessageInputContext < StreamChatGenerics > ( ) ;
353-
354- return < AudioAttachmentWithContext { ...{ fileUploads, removeFile, uploadFile } } { ...props } /> ;
355- } ;
309+ export const AudioAttachment = ( props : AudioAttachmentProps ) => (
310+ < AudioAttachmentWithContext { ...props } />
311+ ) ;
356312
357313AudioAttachment . displayName = 'AudioAttachment{messageInput{autoAttachment}}' ;
0 commit comments