Skip to content

Commit 75561fd

Browse files
fix: erroneous usage of AudioAttachment and its props from message input context (#1588)
* fix: erroneous usage of AudioAttachment and its props from message input context * fix: do not play audio message on message overlay Co-authored-by: Santhosh Vaiyapuri <[email protected]>
1 parent db4248f commit 75561fd

File tree

16 files changed

+172
-169
lines changed

16 files changed

+172
-169
lines changed
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
Component for rendering the Audio Attachment
22

3-
Available Props:
4-
5-
- `index`
6-
73
| Type | Default |
84
| --------- | ------------------------------------------------------------------- |
95
| Component | [`AudioAttachment`](../../../../ui-components/audio_attachment.mdx) |

docusaurus/docs/reactnative/contexts/message_input_context.mdx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import SelectedPicker from '../common-content/contexts/attachment-picker-context
77

88
import AdditionalTextInputProps from '../common-content/core-components/channel/props/additional_text_input_props.mdx';
99
import AttachButton from '../common-content/core-components/channel/props/attach_button.mdx';
10-
import AudioAttachment from '../common-content/core-components/channel/props/audio_attachment.mdx';
1110
import AutoCompleteSuggestionsLimit from '../common-content/core-components/channel/props/auto_complete_suggestions_limit.mdx';
1211
import AutoCompleteTriggerSettings from '../common-content/core-components/channel/props/auto_complete_trigger_settings.mdx';
1312
import CommandsButton from '../common-content/core-components/channel/props/commands_button.mdx';
@@ -371,10 +370,6 @@ const { sendMessage, toggleAttachmentPicker } = useMessageInputContext();
371370

372371
<AttachButton />
373372

374-
### <div class="label description">_forwarded from [Channel](../core-components/channel.mdx#audioattachment)_ props</div> AudioAttachment {#audioattachment}
375-
376-
<AudioAttachment />
377-
378373
### <div class="label description">_forwarded from [Channel](../core-components/channel.mdx#commandsbutton)_ props</div> CommandsButton {#commandsbutton}
379374

380375
<CommandsButton />

docusaurus/docs/reactnative/contexts/messages_context.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ title: MessagesContext
66
import AdditionalTouchableProps from '../common-content/core-components/channel/props/additional_touchable_props.mdx';
77
import Attachment from '../common-content/core-components/channel/props/attachment.mdx';
88
import AttachmentActions from '../common-content/core-components/channel/props/attachment_actions.mdx';
9+
import AudioAttachment from '../common-content/core-components/channel/props/audio_attachment.mdx';
910
import Card from '../common-content/core-components/channel/props/card.mdx';
1011
import CardCover from '../common-content/core-components/channel/props/card_cover.mdx';
1112
import CardFooter from '../common-content/core-components/channel/props/card_footer.mdx';
@@ -254,6 +255,10 @@ Upserts a given message in local channel state. Please note that this function d
254255

255256
<AttachmentActions />
256257

258+
### <div class="label description">_forwarded from [Channel](../core-components/channel.mdx#audioattachment)_ props</div> AudioAttachment {#audioattachment}
259+
260+
<AudioAttachment />
261+
257262
### <div class="label description">_forwarded from [Channel](../core-components/channel.mdx#card)_ props</div> Card {#card}
258263

259264
<Card />

docusaurus/docs/reactnative/ui-components/audio_attachment.mdx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ This is the default component provided to the prop [`AudioAttachment`](../core-c
99

1010
## Props
1111

12-
### <div class="label required">required</div> **index**
13-
14-
| Type |
15-
| ------ |
16-
| number |
17-
1812
### <div class="label required">required</div> **item**
1913

2014
| Type |

package/src/components/Attachment/AudioAttachment.tsx

Lines changed: 72 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import { I18nManager, StyleSheet, Text, TouchableOpacity, View } from 'react-nat
44
import dayjs from 'dayjs';
55
import 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';
138
import { Pause, Play } from '../../icons';
149
import {
1510
PlaybackStatus,
@@ -18,7 +13,6 @@ import {
1813
VideoPayloadData,
1914
VideoProgressData,
2015
} from '../../native';
21-
import type { DefaultStreamChatGenerics } from '../../types/types';
2216
import { ProgressControl } from '../ProgressControl/ProgressControl';
2317

2418
dayjs.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

357313
AudioAttachment.displayName = 'AudioAttachment{messageInput{autoAttachment}}';

0 commit comments

Comments
 (0)