stream-chat-react-native-core 6.3.1 → 6.4.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/components/Attachment/AudioAttachment.js +255 -216
- package/lib/commonjs/components/Attachment/AudioAttachment.js.map +1 -1
- package/lib/commonjs/components/Attachment/FileAttachmentGroup.js +11 -11
- package/lib/commonjs/components/Attachment/FileAttachmentGroup.js.map +1 -1
- package/lib/commonjs/components/Attachment/Gallery.js +9 -0
- package/lib/commonjs/components/Attachment/Gallery.js.map +1 -1
- package/lib/commonjs/components/ChannelList/ChannelList.js +23 -0
- package/lib/commonjs/components/ChannelList/ChannelList.js.map +1 -1
- package/lib/commonjs/components/ChannelList/hooks/listeners/useAddedToChannelNotification.js +31 -8
- package/lib/commonjs/components/ChannelList/hooks/listeners/useAddedToChannelNotification.js.map +1 -1
- package/lib/commonjs/components/ChannelList/hooks/listeners/useChannelMemberUpdated.js +75 -0
- package/lib/commonjs/components/ChannelList/hooks/listeners/useChannelMemberUpdated.js.map +1 -0
- package/lib/commonjs/components/ChannelList/hooks/listeners/useNewMessage.js +21 -10
- package/lib/commonjs/components/ChannelList/hooks/listeners/useNewMessage.js.map +1 -1
- package/lib/commonjs/components/ChannelList/hooks/listeners/useNewMessageNotification.js +23 -7
- package/lib/commonjs/components/ChannelList/hooks/listeners/useNewMessageNotification.js.map +1 -1
- package/lib/commonjs/components/ChannelList/hooks/useChannelMembershipState.js +17 -0
- package/lib/commonjs/components/ChannelList/hooks/useChannelMembershipState.js.map +1 -0
- package/lib/commonjs/components/ChannelList/hooks/useSelectedChannelState.js +32 -0
- package/lib/commonjs/components/ChannelList/hooks/useSelectedChannelState.js.map +1 -0
- package/lib/commonjs/components/ChannelList/hooks/utils/index.js +102 -0
- package/lib/commonjs/components/ChannelList/hooks/utils/index.js.map +1 -0
- package/lib/commonjs/components/ChannelList/utils.js +23 -11
- package/lib/commonjs/components/ChannelList/utils.js.map +1 -1
- package/lib/commonjs/components/ChannelPreview/ChannelPreviewMessenger.js +1 -2
- package/lib/commonjs/components/ChannelPreview/ChannelPreviewMessenger.js.map +1 -1
- package/lib/commonjs/components/ImageGallery/components/ImageGalleryVideoControl.js +24 -13
- package/lib/commonjs/components/ImageGallery/components/ImageGalleryVideoControl.js.map +1 -1
- package/lib/commonjs/components/Message/Message.js.map +1 -1
- package/lib/commonjs/components/MessageInput/FileUploadPreview.js +35 -23
- package/lib/commonjs/components/MessageInput/FileUploadPreview.js.map +1 -1
- package/lib/commonjs/components/ProgressControl/ProgressControl.js +57 -54
- package/lib/commonjs/components/ProgressControl/ProgressControl.js.map +1 -1
- package/lib/commonjs/components/ProgressControl/WaveProgressBar.js +52 -52
- package/lib/commonjs/components/ProgressControl/WaveProgressBar.js.map +1 -1
- package/lib/commonjs/components/index.js +22 -0
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/contexts/themeContext/utils/theme.js +1 -0
- package/lib/commonjs/contexts/themeContext/utils/theme.js.map +1 -1
- package/lib/commonjs/hooks/useAudioPlayer.js +158 -0
- package/lib/commonjs/hooks/useAudioPlayer.js.map +1 -0
- package/lib/commonjs/icons/Archieve.js +33 -0
- package/lib/commonjs/icons/Archieve.js.map +1 -0
- package/lib/commonjs/icons/Pause.js +2 -2
- package/lib/commonjs/icons/Pause.js.map +1 -1
- package/lib/commonjs/icons/Play.js +2 -2
- package/lib/commonjs/icons/Play.js.map +1 -1
- package/lib/commonjs/icons/index.js +11 -0
- package/lib/commonjs/icons/index.js.map +1 -1
- package/lib/commonjs/native.js.map +1 -1
- package/lib/commonjs/types/types.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/Attachment/AudioAttachment.js +255 -216
- package/lib/module/components/Attachment/AudioAttachment.js.map +1 -1
- package/lib/module/components/Attachment/FileAttachmentGroup.js +11 -11
- package/lib/module/components/Attachment/FileAttachmentGroup.js.map +1 -1
- package/lib/module/components/Attachment/Gallery.js +9 -0
- package/lib/module/components/Attachment/Gallery.js.map +1 -1
- package/lib/module/components/ChannelList/ChannelList.js +23 -0
- package/lib/module/components/ChannelList/ChannelList.js.map +1 -1
- package/lib/module/components/ChannelList/hooks/listeners/useAddedToChannelNotification.js +31 -8
- package/lib/module/components/ChannelList/hooks/listeners/useAddedToChannelNotification.js.map +1 -1
- package/lib/module/components/ChannelList/hooks/listeners/useChannelMemberUpdated.js +75 -0
- package/lib/module/components/ChannelList/hooks/listeners/useChannelMemberUpdated.js.map +1 -0
- package/lib/module/components/ChannelList/hooks/listeners/useNewMessage.js +21 -10
- package/lib/module/components/ChannelList/hooks/listeners/useNewMessage.js.map +1 -1
- package/lib/module/components/ChannelList/hooks/listeners/useNewMessageNotification.js +23 -7
- package/lib/module/components/ChannelList/hooks/listeners/useNewMessageNotification.js.map +1 -1
- package/lib/module/components/ChannelList/hooks/useChannelMembershipState.js +17 -0
- package/lib/module/components/ChannelList/hooks/useChannelMembershipState.js.map +1 -0
- package/lib/module/components/ChannelList/hooks/useSelectedChannelState.js +32 -0
- package/lib/module/components/ChannelList/hooks/useSelectedChannelState.js.map +1 -0
- package/lib/module/components/ChannelList/hooks/utils/index.js +102 -0
- package/lib/module/components/ChannelList/hooks/utils/index.js.map +1 -0
- package/lib/module/components/ChannelList/utils.js +23 -11
- package/lib/module/components/ChannelList/utils.js.map +1 -1
- package/lib/module/components/ChannelPreview/ChannelPreviewMessenger.js +1 -2
- package/lib/module/components/ChannelPreview/ChannelPreviewMessenger.js.map +1 -1
- package/lib/module/components/ImageGallery/components/ImageGalleryVideoControl.js +24 -13
- package/lib/module/components/ImageGallery/components/ImageGalleryVideoControl.js.map +1 -1
- package/lib/module/components/Message/Message.js.map +1 -1
- package/lib/module/components/MessageInput/FileUploadPreview.js +35 -23
- package/lib/module/components/MessageInput/FileUploadPreview.js.map +1 -1
- package/lib/module/components/ProgressControl/ProgressControl.js +57 -54
- package/lib/module/components/ProgressControl/ProgressControl.js.map +1 -1
- package/lib/module/components/ProgressControl/WaveProgressBar.js +52 -52
- package/lib/module/components/ProgressControl/WaveProgressBar.js.map +1 -1
- package/lib/module/components/index.js +22 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/contexts/themeContext/utils/theme.js +1 -0
- package/lib/module/contexts/themeContext/utils/theme.js.map +1 -1
- package/lib/module/hooks/useAudioPlayer.js +158 -0
- package/lib/module/hooks/useAudioPlayer.js.map +1 -0
- package/lib/module/icons/Archieve.js +33 -0
- package/lib/module/icons/Archieve.js.map +1 -0
- package/lib/module/icons/Pause.js +2 -2
- package/lib/module/icons/Pause.js.map +1 -1
- package/lib/module/icons/Play.js +2 -2
- package/lib/module/icons/Play.js.map +1 -1
- package/lib/module/icons/index.js +11 -0
- package/lib/module/icons/index.js.map +1 -1
- package/lib/module/native.js.map +1 -1
- package/lib/module/types/types.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/Attachment/AudioAttachment.d.ts +2 -2
- package/lib/typescript/components/Attachment/AudioAttachment.d.ts.map +1 -1
- package/lib/typescript/components/Attachment/FileAttachmentGroup.d.ts.map +1 -1
- package/lib/typescript/components/Attachment/Gallery.d.ts.map +1 -1
- package/lib/typescript/components/ChannelList/ChannelList.d.ts +20 -6
- package/lib/typescript/components/ChannelList/ChannelList.d.ts.map +1 -1
- package/lib/typescript/components/ChannelList/hooks/listeners/useAddedToChannelNotification.d.ts +4 -3
- package/lib/typescript/components/ChannelList/hooks/listeners/useAddedToChannelNotification.d.ts.map +1 -1
- package/lib/typescript/components/ChannelList/hooks/listeners/useChannelMemberUpdated.d.ts +12 -0
- package/lib/typescript/components/ChannelList/hooks/listeners/useChannelMemberUpdated.d.ts.map +1 -0
- package/lib/typescript/components/ChannelList/hooks/listeners/useNewMessage.d.ts +4 -3
- package/lib/typescript/components/ChannelList/hooks/listeners/useNewMessage.d.ts.map +1 -1
- package/lib/typescript/components/ChannelList/hooks/listeners/useNewMessageNotification.d.ts +4 -3
- package/lib/typescript/components/ChannelList/hooks/listeners/useNewMessageNotification.d.ts.map +1 -1
- package/lib/typescript/components/ChannelList/hooks/useChannelMembershipState.d.ts +5 -0
- package/lib/typescript/components/ChannelList/hooks/useChannelMembershipState.d.ts.map +1 -0
- package/lib/typescript/components/ChannelList/hooks/useSelectedChannelState.d.ts +13 -0
- package/lib/typescript/components/ChannelList/hooks/useSelectedChannelState.d.ts.map +1 -0
- package/lib/typescript/components/ChannelList/hooks/utils/index.d.ts +22 -0
- package/lib/typescript/components/ChannelList/hooks/utils/index.d.ts.map +1 -0
- package/lib/typescript/components/ChannelList/utils.d.ts +10 -4
- package/lib/typescript/components/ChannelList/utils.d.ts.map +1 -1
- package/lib/typescript/components/ChannelPreview/ChannelPreviewMessenger.d.ts.map +1 -1
- package/lib/typescript/components/ImageGallery/components/ImageGalleryVideoControl.d.ts.map +1 -1
- package/lib/typescript/components/Message/Message.d.ts +22 -11
- package/lib/typescript/components/Message/Message.d.ts.map +1 -1
- package/lib/typescript/components/MessageInput/FileUploadPreview.d.ts.map +1 -1
- package/lib/typescript/components/ProgressControl/ProgressControl.d.ts +35 -2
- package/lib/typescript/components/ProgressControl/ProgressControl.d.ts.map +1 -1
- package/lib/typescript/components/ProgressControl/WaveProgressBar.d.ts +27 -0
- package/lib/typescript/components/ProgressControl/WaveProgressBar.d.ts.map +1 -1
- package/lib/typescript/components/index.d.ts +2 -0
- package/lib/typescript/components/index.d.ts.map +1 -1
- package/lib/typescript/contexts/themeContext/utils/theme.d.ts +1 -0
- package/lib/typescript/contexts/themeContext/utils/theme.d.ts.map +1 -1
- package/lib/typescript/hooks/useAudioPlayer.d.ts +16 -0
- package/lib/typescript/hooks/useAudioPlayer.d.ts.map +1 -0
- package/lib/typescript/icons/Archieve.d.ts +4 -0
- package/lib/typescript/icons/Archieve.d.ts.map +1 -0
- package/lib/typescript/icons/Pause.d.ts.map +1 -1
- package/lib/typescript/icons/index.d.ts +1 -0
- package/lib/typescript/icons/index.d.ts.map +1 -1
- package/lib/typescript/native.d.ts +10 -3
- package/lib/typescript/native.d.ts.map +1 -1
- package/lib/typescript/types/types.d.ts +5 -1
- package/lib/typescript/types/types.d.ts.map +1 -1
- package/package.json +4 -2
- package/src/components/Attachment/AudioAttachment.tsx +173 -137
- package/src/components/Attachment/FileAttachmentGroup.tsx +9 -16
- package/src/components/Attachment/Gallery.tsx +3 -0
- package/src/components/ChannelList/ChannelList.tsx +38 -3
- package/src/components/ChannelList/hooks/listeners/useAddedToChannelNotification.ts +32 -3
- package/src/components/ChannelList/hooks/listeners/useChannelMemberUpdated.ts +116 -0
- package/src/components/ChannelList/hooks/listeners/useNewMessage.ts +46 -17
- package/src/components/ChannelList/hooks/listeners/useNewMessageNotification.ts +18 -3
- package/src/components/ChannelList/hooks/useChannelMembershipState.ts +22 -0
- package/src/components/ChannelList/hooks/useSelectedChannelState.ts +57 -0
- package/src/components/ChannelList/hooks/utils/index.ts +130 -0
- package/src/components/ChannelList/utils.ts +50 -14
- package/src/components/ChannelPreview/ChannelPreviewMessenger.tsx +1 -2
- package/src/components/ImageGallery/components/ImageGalleryVideoControl.tsx +23 -13
- package/src/components/Message/Message.tsx +26 -4
- package/src/components/MessageInput/FileUploadPreview.tsx +29 -28
- package/src/components/ProgressControl/ProgressControl.tsx +115 -92
- package/src/components/ProgressControl/WaveProgressBar.tsx +96 -59
- package/src/components/index.ts +2 -0
- package/src/contexts/themeContext/utils/theme.ts +2 -0
- package/src/hooks/useAudioPlayer.ts +59 -0
- package/src/icons/Archieve.tsx +10 -0
- package/src/icons/Pause.tsx +2 -5
- package/src/icons/Play.tsx +2 -2
- package/src/icons/index.ts +1 -0
- package/src/native.ts +11 -3
- package/src/types/types.ts +14 -1
- package/src/version.json +1 -1
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
1
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { I18nManager, Pressable, StyleSheet, Text, View } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import dayjs from 'dayjs';
|
|
5
5
|
import duration from 'dayjs/plugin/duration';
|
|
6
6
|
|
|
7
7
|
import { useTheme } from '../../contexts';
|
|
8
|
+
import { useAudioPlayer } from '../../hooks/useAudioPlayer';
|
|
8
9
|
import { Audio, Pause, Play } from '../../icons';
|
|
9
10
|
import {
|
|
10
11
|
PlaybackStatus,
|
|
12
|
+
SDK,
|
|
11
13
|
Sound,
|
|
12
14
|
SoundReturnType,
|
|
13
15
|
VideoPayloadData,
|
|
14
16
|
VideoProgressData,
|
|
17
|
+
VideoSeekResponse,
|
|
15
18
|
} from '../../native';
|
|
16
|
-
import type
|
|
19
|
+
import { FileTypes, type FileUpload } from '../../types/types';
|
|
17
20
|
import { getTrimmedAttachmentTitle } from '../../utils/getTrimmedAttachmentTitle';
|
|
18
21
|
import { ProgressControl } from '../ProgressControl/ProgressControl';
|
|
19
22
|
import { WaveProgressBar } from '../ProgressControl/WaveProgressBar';
|
|
@@ -24,7 +27,7 @@ export type AudioAttachmentProps = {
|
|
|
24
27
|
item: Omit<FileUpload, 'state'>;
|
|
25
28
|
onLoad: (index: string, duration: number) => void;
|
|
26
29
|
onPlayPause: (index: string, pausedStatus?: boolean) => void;
|
|
27
|
-
onProgress: (index: string,
|
|
30
|
+
onProgress: (index: string, progress: number) => void;
|
|
28
31
|
hideProgressBar?: boolean;
|
|
29
32
|
showSpeedSettings?: boolean;
|
|
30
33
|
testID?: string;
|
|
@@ -35,9 +38,8 @@ export type AudioAttachmentProps = {
|
|
|
35
38
|
* UI Component to preview the audio files
|
|
36
39
|
*/
|
|
37
40
|
export const AudioAttachment = (props: AudioAttachmentProps) => {
|
|
38
|
-
const [width, setWidth] = useState(0);
|
|
39
|
-
const [progressControlTextWidth, setProgressControlTextWidth] = useState(0);
|
|
40
41
|
const [currentSpeed, setCurrentSpeed] = useState<number>(1.0);
|
|
42
|
+
const [audioFinished, setAudioFinished] = useState(false);
|
|
41
43
|
const soundRef = React.useRef<SoundReturnType | null>(null);
|
|
42
44
|
const {
|
|
43
45
|
hideProgressBar = false,
|
|
@@ -48,59 +50,83 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
|
|
|
48
50
|
showSpeedSettings = false,
|
|
49
51
|
testID,
|
|
50
52
|
} = props;
|
|
53
|
+
const { changeAudioSpeed, pauseAudio, playAudio, seekAudio } = useAudioPlayer({ soundRef });
|
|
54
|
+
const isExpoCLI = SDK === 'stream-chat-expo';
|
|
55
|
+
const isVoiceRecording = item.type === FileTypes.VoiceRecording;
|
|
51
56
|
|
|
52
57
|
/** This is for Native CLI Apps */
|
|
53
58
|
const handleLoad = (payload: VideoPayloadData) => {
|
|
54
|
-
|
|
59
|
+
// The duration given by the rn-video is not same as the one of the voice recording, so we take the actual duration for voice recording.
|
|
60
|
+
if (isVoiceRecording && item.duration) {
|
|
61
|
+
onLoad(item.id, item.duration);
|
|
62
|
+
} else {
|
|
63
|
+
onLoad(item.id, item.duration || payload.duration);
|
|
64
|
+
}
|
|
55
65
|
};
|
|
56
66
|
|
|
57
67
|
/** This is for Native CLI Apps */
|
|
58
68
|
const handleProgress = (data: VideoProgressData) => {
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
const { currentTime, seekableDuration } = data;
|
|
70
|
+
// The duration given by the rn-video is not same as the one of the voice recording, so we take the actual duration for voice recording.
|
|
71
|
+
if (isVoiceRecording && item.duration) {
|
|
72
|
+
if (currentTime < item.duration && !audioFinished) {
|
|
73
|
+
onProgress(item.id, currentTime / item.duration);
|
|
74
|
+
} else {
|
|
75
|
+
setAudioFinished(true);
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
if (currentTime < seekableDuration && !audioFinished) {
|
|
79
|
+
onProgress(item.id, currentTime / seekableDuration);
|
|
80
|
+
} else {
|
|
81
|
+
setAudioFinished(true);
|
|
82
|
+
}
|
|
61
83
|
}
|
|
62
84
|
};
|
|
63
85
|
|
|
64
86
|
/** This is for Native CLI Apps */
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
onProgress(item.id, item.duration
|
|
87
|
+
const onSeek = (seekResponse: VideoSeekResponse) => {
|
|
88
|
+
setAudioFinished(false);
|
|
89
|
+
onProgress(item.id, seekResponse.currentTime / (item.duration as number));
|
|
68
90
|
};
|
|
69
91
|
|
|
70
|
-
const handlePlayPause = async (
|
|
71
|
-
if (
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (item.paused) {
|
|
80
|
-
// For expo CLI
|
|
81
|
-
if (soundRef.current.playAsync) await soundRef.current.playAsync();
|
|
82
|
-
if (soundRef.current.setProgressUpdateIntervalAsync)
|
|
83
|
-
await soundRef.current.setProgressUpdateIntervalAsync(60);
|
|
84
|
-
onPlayPause(item.id, false);
|
|
85
|
-
} else {
|
|
86
|
-
// For expo CLI
|
|
87
|
-
if (soundRef.current.pauseAsync) await soundRef.current.pauseAsync();
|
|
88
|
-
onPlayPause(item.id, true);
|
|
89
|
-
}
|
|
90
|
-
} else {
|
|
91
|
-
onPlayPause(item.id, isPausedStatusAvailable);
|
|
92
|
+
const handlePlayPause = async () => {
|
|
93
|
+
if (item.paused) {
|
|
94
|
+
if (isExpoCLI) {
|
|
95
|
+
await playAudio();
|
|
96
|
+
}
|
|
97
|
+
onPlayPause(item.id, false);
|
|
98
|
+
} else {
|
|
99
|
+
if (isExpoCLI) {
|
|
100
|
+
await pauseAudio();
|
|
92
101
|
}
|
|
102
|
+
onPlayPause(item.id, true);
|
|
93
103
|
}
|
|
94
104
|
};
|
|
95
105
|
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
106
|
+
const handleEnd = async () => {
|
|
107
|
+
setAudioFinished(false);
|
|
108
|
+
await pauseAudio();
|
|
109
|
+
onPlayPause(item.id, true);
|
|
110
|
+
await seekAudio(0);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const dragStart = async () => {
|
|
114
|
+
if (isExpoCLI) {
|
|
115
|
+
await pauseAudio();
|
|
116
|
+
}
|
|
117
|
+
onPlayPause(item.id, true);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const dragProgress = (progress: number) => {
|
|
121
|
+
onProgress(item.id, progress);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const dragEnd = async (progress: number) => {
|
|
125
|
+
await seekAudio(progress * (item.duration as number));
|
|
126
|
+
if (isExpoCLI) {
|
|
127
|
+
await playAudio();
|
|
103
128
|
}
|
|
129
|
+
onPlayPause(item.id, false);
|
|
104
130
|
};
|
|
105
131
|
|
|
106
132
|
/** For Expo CLI */
|
|
@@ -115,11 +141,25 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
|
|
|
115
141
|
// This is done for Expo CLI where we don't get file duration from file picker
|
|
116
142
|
if (item.duration === 0) {
|
|
117
143
|
onLoad(item.id, durationMillis / 1000);
|
|
144
|
+
} else {
|
|
145
|
+
// The duration given by the expo-av is not same as the one of the voice recording, so we take the actual duration for voice recording.
|
|
146
|
+
if (isVoiceRecording && item.duration) {
|
|
147
|
+
onLoad(item.id, item.duration);
|
|
148
|
+
} else {
|
|
149
|
+
onLoad(item.id, durationMillis / 1000);
|
|
150
|
+
}
|
|
118
151
|
}
|
|
119
152
|
// Update your UI for the loaded state
|
|
120
153
|
if (playbackStatus.isPlaying) {
|
|
121
|
-
|
|
122
|
-
|
|
154
|
+
if (isVoiceRecording && item.duration) {
|
|
155
|
+
if (positionMillis <= item.duration * 1000) {
|
|
156
|
+
onProgress(item.id, positionMillis / (item.duration * 1000));
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
if (positionMillis <= durationMillis) {
|
|
160
|
+
onProgress(item.id, positionMillis / durationMillis);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
123
163
|
} else {
|
|
124
164
|
// Update your UI for the paused state
|
|
125
165
|
}
|
|
@@ -129,6 +169,7 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
|
|
|
129
169
|
}
|
|
130
170
|
|
|
131
171
|
if (playbackStatus.didJustFinish && !playbackStatus.isLooping) {
|
|
172
|
+
onProgress(item.id, 1);
|
|
132
173
|
// The player has just finished playing and will stop. Maybe you want to play something else?
|
|
133
174
|
// status: opposite of pause,says i am playing
|
|
134
175
|
handleEnd();
|
|
@@ -136,13 +177,16 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
|
|
|
136
177
|
}
|
|
137
178
|
};
|
|
138
179
|
|
|
180
|
+
// This is for Expo CLI, sound initialization is done here.
|
|
139
181
|
useEffect(() => {
|
|
140
|
-
if (
|
|
182
|
+
if (isExpoCLI) {
|
|
141
183
|
const initiateSound = async () => {
|
|
142
184
|
if (item && item.file && item.file.uri) {
|
|
143
185
|
soundRef.current = await Sound.initializeSound(
|
|
144
186
|
{ uri: item.file.uri },
|
|
145
|
-
{
|
|
187
|
+
{
|
|
188
|
+
progressUpdateIntervalMillis: 100,
|
|
189
|
+
},
|
|
146
190
|
onPlaybackStatusUpdate,
|
|
147
191
|
);
|
|
148
192
|
}
|
|
@@ -162,39 +206,32 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
|
|
|
162
206
|
// This is needed for expo applications where the rerender doesn't occur on time thefore you need to update the state of the sound.
|
|
163
207
|
useEffect(() => {
|
|
164
208
|
const initalPlayPause = async () => {
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
209
|
+
if (!isExpoCLI) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (item.paused) {
|
|
213
|
+
await pauseAudio();
|
|
214
|
+
} else {
|
|
215
|
+
await playAudio();
|
|
173
216
|
}
|
|
174
217
|
};
|
|
175
218
|
// For expo CLI
|
|
176
219
|
if (!Sound.Player) {
|
|
177
220
|
initalPlayPause();
|
|
178
221
|
}
|
|
179
|
-
}, [item.paused]);
|
|
222
|
+
}, [item.paused, isExpoCLI, pauseAudio, playAudio]);
|
|
180
223
|
|
|
181
224
|
const onSpeedChangeHandler = async () => {
|
|
182
225
|
if (currentSpeed === 2.0) {
|
|
183
226
|
setCurrentSpeed(1.0);
|
|
184
|
-
|
|
185
|
-
await soundRef.current.setRateAsync(1.0);
|
|
186
|
-
}
|
|
227
|
+
await changeAudioSpeed(1.0);
|
|
187
228
|
} else {
|
|
188
229
|
if (currentSpeed === 1.0) {
|
|
189
230
|
setCurrentSpeed(1.5);
|
|
190
|
-
|
|
191
|
-
await soundRef.current.setRateAsync(1.5);
|
|
192
|
-
}
|
|
231
|
+
await changeAudioSpeed(1.5);
|
|
193
232
|
} else if (currentSpeed === 1.5) {
|
|
194
233
|
setCurrentSpeed(2.0);
|
|
195
|
-
|
|
196
|
-
await soundRef.current.setRateAsync(2.0);
|
|
197
|
-
}
|
|
234
|
+
await changeAudioSpeed(2.0);
|
|
198
235
|
}
|
|
199
236
|
}
|
|
200
237
|
};
|
|
@@ -218,13 +255,20 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
|
|
|
218
255
|
},
|
|
219
256
|
} = useTheme();
|
|
220
257
|
|
|
221
|
-
const progressValueInSeconds = (
|
|
258
|
+
const progressValueInSeconds = useMemo(
|
|
259
|
+
() => (item.duration as number) * (item.progress as number),
|
|
260
|
+
[item.duration, item.progress],
|
|
261
|
+
);
|
|
222
262
|
|
|
223
|
-
const progressDuration =
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
263
|
+
const progressDuration = useMemo(
|
|
264
|
+
() =>
|
|
265
|
+
progressValueInSeconds
|
|
266
|
+
? progressValueInSeconds / 3600 >= 1
|
|
267
|
+
? dayjs.duration(progressValueInSeconds, 'second').format('HH:mm:ss')
|
|
268
|
+
: dayjs.duration(progressValueInSeconds, 'second').format('mm:ss')
|
|
269
|
+
: dayjs.duration(item.duration ?? 0, 'second').format('mm:ss'),
|
|
270
|
+
[progressValueInSeconds, item.duration],
|
|
271
|
+
);
|
|
228
272
|
|
|
229
273
|
return (
|
|
230
274
|
<View
|
|
@@ -239,27 +283,24 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
|
|
|
239
283
|
]}
|
|
240
284
|
testID={testID}
|
|
241
285
|
>
|
|
242
|
-
<
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}}
|
|
261
|
-
style={[styles.leftContainer, leftContainer]}
|
|
262
|
-
>
|
|
286
|
+
<View style={[styles.leftContainer, leftContainer]}>
|
|
287
|
+
<Pressable
|
|
288
|
+
accessibilityLabel='Play Pause Button'
|
|
289
|
+
onPress={handlePlayPause}
|
|
290
|
+
style={[
|
|
291
|
+
styles.playPauseButton,
|
|
292
|
+
{ backgroundColor: static_white, shadowColor: black },
|
|
293
|
+
playPauseButton,
|
|
294
|
+
]}
|
|
295
|
+
>
|
|
296
|
+
{item.paused ? (
|
|
297
|
+
<Play fill={static_black} height={32} width={32} />
|
|
298
|
+
) : (
|
|
299
|
+
<Pause fill={static_black} height={32} width={32} />
|
|
300
|
+
)}
|
|
301
|
+
</Pressable>
|
|
302
|
+
</View>
|
|
303
|
+
<View style={[styles.centerContainer]}>
|
|
263
304
|
<Text
|
|
264
305
|
accessibilityLabel='File Name'
|
|
265
306
|
numberOfLines={1}
|
|
@@ -275,39 +316,17 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
|
|
|
275
316
|
{getTrimmedAttachmentTitle(item.file.name)}
|
|
276
317
|
</Text>
|
|
277
318
|
<View style={styles.audioInfo}>
|
|
278
|
-
|
|
279
|
-
{Sound.Player && (
|
|
280
|
-
<Sound.Player
|
|
281
|
-
onEnd={handleEnd}
|
|
282
|
-
onLoad={handleLoad}
|
|
283
|
-
onProgress={handleProgress}
|
|
284
|
-
paused={item.paused as boolean}
|
|
285
|
-
rate={currentSpeed}
|
|
286
|
-
soundRef={soundRef}
|
|
287
|
-
testID='sound-player'
|
|
288
|
-
uri={item.file.uri}
|
|
289
|
-
/>
|
|
290
|
-
)}
|
|
291
|
-
<Text
|
|
292
|
-
onLayout={({ nativeEvent }) => {
|
|
293
|
-
setProgressControlTextWidth(nativeEvent.layout.width);
|
|
294
|
-
}}
|
|
295
|
-
style={[styles.progressDurationText, { color: grey_dark }, progressDurationText]}
|
|
296
|
-
>
|
|
319
|
+
<Text style={[styles.progressDurationText, { color: grey_dark }, progressDurationText]}>
|
|
297
320
|
{progressDuration}
|
|
298
321
|
</Text>
|
|
299
322
|
{!hideProgressBar && (
|
|
300
323
|
<View style={[styles.progressControlContainer, progressControlContainer]}>
|
|
301
324
|
{item.file.waveform_data ? (
|
|
302
325
|
<WaveProgressBar
|
|
303
|
-
amplitudesCount={
|
|
304
|
-
|
|
305
|
-
onProgressDrag={
|
|
306
|
-
|
|
307
|
-
const progress = (position / 30) * (item.duration as number);
|
|
308
|
-
handleProgressDrag(progress);
|
|
309
|
-
}
|
|
310
|
-
}}
|
|
326
|
+
amplitudesCount={30}
|
|
327
|
+
onEndDrag={dragEnd}
|
|
328
|
+
onProgressDrag={dragProgress}
|
|
329
|
+
onStartDrag={dragStart}
|
|
311
330
|
progress={item.progress as number}
|
|
312
331
|
waveformData={item.file.waveform_data}
|
|
313
332
|
/>
|
|
@@ -315,20 +334,33 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
|
|
|
315
334
|
<ProgressControl
|
|
316
335
|
duration={item.duration as number}
|
|
317
336
|
filledColor={accent_blue}
|
|
318
|
-
|
|
319
|
-
onProgressDrag={
|
|
337
|
+
onEndDrag={dragEnd}
|
|
338
|
+
onProgressDrag={dragProgress}
|
|
339
|
+
onStartDrag={dragStart}
|
|
320
340
|
progress={item.progress as number}
|
|
321
341
|
testID='progress-control'
|
|
322
|
-
width={width - progressControlTextWidth}
|
|
323
342
|
/>
|
|
324
343
|
)}
|
|
325
344
|
</View>
|
|
326
345
|
)}
|
|
327
346
|
</View>
|
|
347
|
+
{Sound.Player && (
|
|
348
|
+
<Sound.Player
|
|
349
|
+
onEnd={handleEnd}
|
|
350
|
+
onLoad={handleLoad}
|
|
351
|
+
onProgress={handleProgress}
|
|
352
|
+
onSeek={onSeek}
|
|
353
|
+
paused={item.paused}
|
|
354
|
+
rate={currentSpeed}
|
|
355
|
+
soundRef={soundRef}
|
|
356
|
+
testID='sound-player'
|
|
357
|
+
uri={item.file.uri}
|
|
358
|
+
/>
|
|
359
|
+
)}
|
|
328
360
|
</View>
|
|
329
|
-
{showSpeedSettings
|
|
361
|
+
{showSpeedSettings ? (
|
|
330
362
|
<View style={[styles.rightContainer, rightContainer]}>
|
|
331
|
-
{item.
|
|
363
|
+
{item.paused ? (
|
|
332
364
|
<Audio fill={'#ffffff'} />
|
|
333
365
|
) : (
|
|
334
366
|
<Pressable
|
|
@@ -341,11 +373,11 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
|
|
|
341
373
|
>
|
|
342
374
|
<Text
|
|
343
375
|
style={[styles.speedChangeButtonText, speedChangeButtonText]}
|
|
344
|
-
>{`x${currentSpeed}`}</Text>
|
|
376
|
+
>{`x${currentSpeed.toFixed(1)}`}</Text>
|
|
345
377
|
</Pressable>
|
|
346
378
|
)}
|
|
347
379
|
</View>
|
|
348
|
-
)}
|
|
380
|
+
) : null}
|
|
349
381
|
</View>
|
|
350
382
|
);
|
|
351
383
|
};
|
|
@@ -353,34 +385,36 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
|
|
|
353
385
|
const styles = StyleSheet.create({
|
|
354
386
|
audioInfo: {
|
|
355
387
|
alignItems: 'center',
|
|
356
|
-
display: 'flex',
|
|
357
388
|
flexDirection: 'row',
|
|
358
389
|
},
|
|
390
|
+
centerContainer: {
|
|
391
|
+
flexGrow: 1,
|
|
392
|
+
},
|
|
359
393
|
container: {
|
|
360
394
|
alignItems: 'center',
|
|
361
395
|
borderRadius: 12,
|
|
362
396
|
borderWidth: 1,
|
|
397
|
+
flex: 1,
|
|
363
398
|
flexDirection: 'row',
|
|
364
|
-
|
|
399
|
+
paddingLeft: 8,
|
|
400
|
+
paddingRight: 16,
|
|
365
401
|
paddingVertical: 12,
|
|
366
402
|
},
|
|
367
403
|
filenameText: {
|
|
368
404
|
fontSize: 14,
|
|
369
405
|
fontWeight: 'bold',
|
|
370
|
-
|
|
406
|
+
marginBottom: 8,
|
|
371
407
|
},
|
|
372
408
|
leftContainer: {
|
|
373
|
-
|
|
374
|
-
marginHorizontal: 16,
|
|
375
|
-
width: '60%',
|
|
409
|
+
marginRight: 8,
|
|
376
410
|
},
|
|
377
411
|
playPauseButton: {
|
|
378
412
|
alignItems: 'center',
|
|
379
|
-
alignSelf: 'center',
|
|
380
413
|
borderRadius: 50,
|
|
381
414
|
elevation: 4,
|
|
382
415
|
justifyContent: 'center',
|
|
383
|
-
|
|
416
|
+
marginRight: 8,
|
|
417
|
+
padding: 4,
|
|
384
418
|
shadowOffset: {
|
|
385
419
|
height: 2,
|
|
386
420
|
width: 0,
|
|
@@ -388,13 +422,16 @@ const styles = StyleSheet.create({
|
|
|
388
422
|
shadowOpacity: 0.23,
|
|
389
423
|
shadowRadius: 2.62,
|
|
390
424
|
},
|
|
391
|
-
progressControlContainer: {
|
|
425
|
+
progressControlContainer: {
|
|
426
|
+
flexGrow: 1,
|
|
427
|
+
justifyContent: 'center',
|
|
428
|
+
},
|
|
392
429
|
progressDurationText: {
|
|
393
430
|
fontSize: 12,
|
|
394
|
-
marginRight:
|
|
431
|
+
marginRight: 8,
|
|
395
432
|
},
|
|
396
433
|
rightContainer: {
|
|
397
|
-
marginLeft:
|
|
434
|
+
marginLeft: 16,
|
|
398
435
|
},
|
|
399
436
|
speedChangeButton: {
|
|
400
437
|
alignItems: 'center',
|
|
@@ -402,8 +439,8 @@ const styles = StyleSheet.create({
|
|
|
402
439
|
borderRadius: 50,
|
|
403
440
|
elevation: 4,
|
|
404
441
|
justifyContent: 'center',
|
|
405
|
-
paddingHorizontal:
|
|
406
|
-
paddingVertical:
|
|
442
|
+
paddingHorizontal: 8,
|
|
443
|
+
paddingVertical: 4,
|
|
407
444
|
shadowOffset: {
|
|
408
445
|
height: 2,
|
|
409
446
|
width: 0,
|
|
@@ -413,7 +450,6 @@ const styles = StyleSheet.create({
|
|
|
413
450
|
},
|
|
414
451
|
speedChangeButtonText: {
|
|
415
452
|
fontSize: 12,
|
|
416
|
-
fontWeight: '500',
|
|
417
453
|
},
|
|
418
454
|
});
|
|
419
455
|
|
|
@@ -66,18 +66,11 @@ const FileAttachmentGroupWithContext = <
|
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
// The handler which is triggered when the audio progresses/ the thumb is dragged in the progress control. The progressed duration is set here.
|
|
69
|
-
const onProgress = (index: string,
|
|
69
|
+
const onProgress = (index: string, progress: number) => {
|
|
70
70
|
setFilesToDisplay((prevFilesToDisplay) =>
|
|
71
71
|
prevFilesToDisplay.map((filesToDisplay, id) => ({
|
|
72
72
|
...filesToDisplay,
|
|
73
|
-
progress:
|
|
74
|
-
id.toString() === index
|
|
75
|
-
? hasEnd
|
|
76
|
-
? 1
|
|
77
|
-
: currentTime
|
|
78
|
-
? currentTime / (filesToDisplay.duration as number)
|
|
79
|
-
: 0
|
|
80
|
-
: filesToDisplay.progress,
|
|
73
|
+
progress: id.toString() === index ? progress : filesToDisplay.progress,
|
|
81
74
|
})),
|
|
82
75
|
);
|
|
83
76
|
};
|
|
@@ -86,17 +79,17 @@ const FileAttachmentGroupWithContext = <
|
|
|
86
79
|
const onPlayPause = (index: string, pausedStatus?: boolean) => {
|
|
87
80
|
if (pausedStatus === false) {
|
|
88
81
|
// If the status is false we set the audio with the index as playing and the others as paused.
|
|
89
|
-
setFilesToDisplay((
|
|
90
|
-
|
|
91
|
-
...
|
|
82
|
+
setFilesToDisplay((prevFilesToDisplay) =>
|
|
83
|
+
prevFilesToDisplay.map((fileToDisplay, id) => ({
|
|
84
|
+
...fileToDisplay,
|
|
92
85
|
paused: id.toString() !== index,
|
|
93
86
|
})),
|
|
94
87
|
);
|
|
95
88
|
} else {
|
|
96
89
|
// If the status is true we simply set all the audio's paused state as true.
|
|
97
|
-
setFilesToDisplay((
|
|
98
|
-
|
|
99
|
-
...
|
|
90
|
+
setFilesToDisplay((prevFilesToDisplay) =>
|
|
91
|
+
prevFilesToDisplay.map((fileToDisplay) => ({
|
|
92
|
+
...fileToDisplay,
|
|
100
93
|
paused: true,
|
|
101
94
|
})),
|
|
102
95
|
);
|
|
@@ -135,12 +128,12 @@ const FileAttachmentGroupWithContext = <
|
|
|
135
128
|
id: index.toString(),
|
|
136
129
|
paused: file.paused,
|
|
137
130
|
progress: file.progress,
|
|
131
|
+
type: file.type,
|
|
138
132
|
}}
|
|
139
133
|
onLoad={onLoad}
|
|
140
134
|
onPlayPause={onPlayPause}
|
|
141
135
|
onProgress={onProgress}
|
|
142
136
|
showSpeedSettings={true}
|
|
143
|
-
testID='audio-attachment-preview'
|
|
144
137
|
/>
|
|
145
138
|
) : (
|
|
146
139
|
<Attachment attachment={file} />
|
|
@@ -332,6 +332,7 @@ const GalleryThumbnail = <
|
|
|
332
332
|
onLongPress={(event) => {
|
|
333
333
|
if (onLongPress) {
|
|
334
334
|
onLongPress({
|
|
335
|
+
additionalInfo: { thumbnail },
|
|
335
336
|
emitter: 'gallery',
|
|
336
337
|
event,
|
|
337
338
|
});
|
|
@@ -340,6 +341,7 @@ const GalleryThumbnail = <
|
|
|
340
341
|
onPress={(event) => {
|
|
341
342
|
if (onPress) {
|
|
342
343
|
onPress({
|
|
344
|
+
additionalInfo: { thumbnail },
|
|
343
345
|
defaultHandler: defaultOnPress,
|
|
344
346
|
emitter: 'gallery',
|
|
345
347
|
event,
|
|
@@ -349,6 +351,7 @@ const GalleryThumbnail = <
|
|
|
349
351
|
onPressIn={(event) => {
|
|
350
352
|
if (onPressIn) {
|
|
351
353
|
onPressIn({
|
|
354
|
+
additionalInfo: { thumbnail },
|
|
352
355
|
defaultHandler: defaultOnPress,
|
|
353
356
|
emitter: 'gallery',
|
|
354
357
|
event,
|