@cometchat/chat-uikit-react-native 5.2.10 → 5.3.0
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/android/build.gradle +3 -0
- package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +4 -1
- package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +909 -10
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorPackage.kt +24 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +5382 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +452 -0
- package/ios/FileManager.m +430 -3
- package/ios/RichTextEditorView.swift +5504 -0
- package/ios/RichTextEditorViewManager.m +66 -0
- package/ios/RichTextEditorViewManager.swift +291 -0
- package/ios/ToolbarIcons.swift +736 -0
- package/package.json +1 -1
- package/react-native-cometchat-ui-kit.podspec +1 -1
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +4557 -0
- package/src/CometChatCompactMessageComposer/SingleLineTextComposerConfiguration.tsx +568 -0
- package/src/CometChatCompactMessageComposer/heightUtils.ts +204 -0
- package/src/CometChatCompactMessageComposer/index.ts +56 -0
- package/src/CometChatCompactMessageComposer/resources/index.ts +5 -0
- package/src/CometChatCompactMessageComposer/styles.ts +291 -0
- package/src/CometChatConversations/CometChatConversations.tsx +139 -10
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +25 -21
- package/src/CometChatMessageComposer/styles.tsx +0 -1
- package/src/CometChatMessageList/CometChatMessageList.tsx +39 -6
- package/src/CometChatMessageList/components/MessageListItem.tsx +11 -8
- package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +105 -0
- package/src/CometChatRichTextEditor/index.tsx +385 -0
- package/src/CometChatRichTextEditor/types.ts +162 -0
- package/src/CometChatSearch/CometChatSearch.tsx +8 -3
- package/src/CometChatSearch/style.ts +3 -3
- package/src/index.ts +48 -1
- package/src/shared/constants/UIKitConstants.ts +12 -1
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +5 -5
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +768 -0
- package/src/shared/formatters/index.ts +3 -0
- package/src/shared/framework/MessageDataSource.tsx +93 -2
- package/src/shared/helper/composerHelpers.ts +553 -0
- package/src/shared/helper/useKeyboard.tsx +7 -17
- package/src/shared/icons/components/code-blocks.tsx +13 -0
- package/src/shared/icons/components/code.tsx +11 -0
- package/src/shared/icons/components/format-bold.tsx +11 -0
- package/src/shared/icons/components/format-italic.tsx +11 -0
- package/src/shared/icons/components/format-list-bulleted.tsx +11 -0
- package/src/shared/icons/components/format-list-numbered.tsx +11 -0
- package/src/shared/icons/components/format-quote.tsx +13 -0
- package/src/shared/icons/components/format-strikethrough.tsx +13 -0
- package/src/shared/icons/components/format-underlined.tsx +11 -0
- package/src/shared/icons/components/smileys-&-people.tsx +1 -1
- package/src/shared/icons/icon-mapping.tsx +18 -0
- package/src/shared/index.ts +54 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +38 -32
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +6 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +18 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +505 -499
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +19 -13
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +18 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +504 -498
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +504 -498
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +504 -498
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +19 -13
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +18 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +505 -499
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +18 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +18 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +19 -13
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +505 -499
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +18 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +19 -13
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +132 -11
- package/src/shared/utils/CometChatMessagePreview/style.ts +1 -3
- package/src/shared/utils/MarkdownUtils.ts +143 -0
- package/src/shared/utils/MentionUtils.ts +37 -0
- package/src/shared/utils/MessageUtils.tsx +55 -0
- package/src/shared/utils/index.ts +5 -0
- package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +1 -1
- package/src/shared/views/CometChatInlineAudioRecorder/AudioWaveformVisualizer.tsx +417 -0
- package/src/shared/views/CometChatInlineAudioRecorder/CometChatInlineAudioRecorder.tsx +537 -0
- package/src/shared/views/CometChatInlineAudioRecorder/index.ts +34 -0
- package/src/shared/views/CometChatInlineAudioRecorder/style.ts +155 -0
- package/src/shared/views/CometChatInlineAudioRecorder/types.ts +303 -0
- package/src/shared/views/CometChatInlineAudioRecorder/useAudioRecorder.ts +1336 -0
- package/src/shared/views/CometChatLinkConfirmPopup/CometChatLinkConfirmPopup.tsx +183 -0
- package/src/shared/views/CometChatLinkConfirmPopup/index.ts +13 -0
- package/src/shared/views/CometChatLinkConfirmPopup/style.ts +128 -0
- package/src/shared/views/CometChatList/Header.tsx +57 -49
- package/src/shared/views/CometChatMediaRecorder/CometChatMediaRecorder.tsx +0 -1
- package/src/shared/views/CometChatQuickReactions/QuickReactionsStyle.tsx +2 -2
- package/src/shared/views/CometChatReactionList/ReactionListStyle.tsx +3 -2
- package/src/shared/views/CometChatReactions/CometChatReactions.tsx +11 -5
- package/src/shared/views/CometChatReactions/style.ts +35 -8
- package/src/shared/views/CometChatSendButtonView/CometChatSendButtonView.tsx +32 -29
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +108 -75
- package/src/shared/views/index.ts +39 -0
- package/src/theme/index.ts +1 -1
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Animated,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
Text,
|
|
6
|
+
TouchableOpacity,
|
|
7
|
+
View,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
import { useTheme } from '../../../theme';
|
|
10
|
+
import { Icon } from '../../icons/Icon';
|
|
11
|
+
import { AudioWaveformVisualizer } from './AudioWaveformVisualizer';
|
|
12
|
+
import { useAudioRecorder } from './useAudioRecorder';
|
|
13
|
+
import { getInlineAudioRecorderStyle } from './style';
|
|
14
|
+
import {
|
|
15
|
+
CometChatInlineAudioRecorderProps,
|
|
16
|
+
} from './types';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Formats duration in milliseconds to MM:SS format.
|
|
20
|
+
*
|
|
21
|
+
* @param durationMs - Duration in milliseconds
|
|
22
|
+
* @returns Formatted string in MM:SS format
|
|
23
|
+
* @validates Requirements 1.4, 4.3
|
|
24
|
+
*/
|
|
25
|
+
export function formatDuration(durationMs: number): string {
|
|
26
|
+
if (!Number.isFinite(durationMs) || durationMs < 0) {
|
|
27
|
+
return '00:00';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const totalSeconds = Math.floor(durationMs / 1000);
|
|
31
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
32
|
+
const seconds = totalSeconds % 60;
|
|
33
|
+
|
|
34
|
+
const paddedMinutes = String(minutes).padStart(2, '0');
|
|
35
|
+
const paddedSeconds = String(seconds).padStart(2, '0');
|
|
36
|
+
|
|
37
|
+
return `${paddedMinutes}:${paddedSeconds}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* CometChatInlineAudioRecorder component provides an inline audio recording
|
|
42
|
+
* experience within the message composer area.
|
|
43
|
+
*
|
|
44
|
+
* Features:
|
|
45
|
+
* - UI Layout: Delete | Record/Play | Waveform | Duration | Pause/Mic | Send
|
|
46
|
+
* - Red pulsing dot indicator during active recording
|
|
47
|
+
* - Waveform visualization with amplitude bars
|
|
48
|
+
* - Duration display in MM:SS format
|
|
49
|
+
* - Button state logic based on recorder state
|
|
50
|
+
*
|
|
51
|
+
* @validates Requirements 1.1, 1.2, 1.5, 3.2, 8.2
|
|
52
|
+
*/
|
|
53
|
+
export const CometChatInlineAudioRecorder: React.FC<CometChatInlineAudioRecorderProps> = ({
|
|
54
|
+
onSubmit,
|
|
55
|
+
onCancel,
|
|
56
|
+
style,
|
|
57
|
+
deleteIcon,
|
|
58
|
+
sendIcon,
|
|
59
|
+
recordIcon,
|
|
60
|
+
pauseIcon,
|
|
61
|
+
micIcon,
|
|
62
|
+
playIcon,
|
|
63
|
+
}) => {
|
|
64
|
+
const theme = useTheme();
|
|
65
|
+
const recorder = useAudioRecorder();
|
|
66
|
+
|
|
67
|
+
// Animation value for the pulsing recording indicator
|
|
68
|
+
const pulseAnim = useRef(new Animated.Value(1)).current;
|
|
69
|
+
|
|
70
|
+
// Local state for smooth drag feedback - updates immediately without waiting for native
|
|
71
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
72
|
+
const [dragProgress, setDragProgress] = useState(0);
|
|
73
|
+
|
|
74
|
+
// Merge styles with defaults using the style.ts function
|
|
75
|
+
// Uses CometChatThemeHelper pattern for default colors
|
|
76
|
+
const mergedStyle = useMemo(() => {
|
|
77
|
+
return getInlineAudioRecorderStyle(
|
|
78
|
+
theme.color,
|
|
79
|
+
theme.spacing,
|
|
80
|
+
theme.typography,
|
|
81
|
+
style
|
|
82
|
+
);
|
|
83
|
+
}, [theme, style]);
|
|
84
|
+
|
|
85
|
+
// Start recording automatically when component mounts
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
recorder.startRecording();
|
|
88
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
89
|
+
}, []);
|
|
90
|
+
|
|
91
|
+
// Pulsing animation for recording indicator
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
let animation: Animated.CompositeAnimation | null = null;
|
|
94
|
+
|
|
95
|
+
if (recorder.isRecording) {
|
|
96
|
+
animation = Animated.loop(
|
|
97
|
+
Animated.sequence([
|
|
98
|
+
Animated.timing(pulseAnim, {
|
|
99
|
+
toValue: 0.3,
|
|
100
|
+
duration: 500,
|
|
101
|
+
useNativeDriver: true,
|
|
102
|
+
}),
|
|
103
|
+
Animated.timing(pulseAnim, {
|
|
104
|
+
toValue: 1,
|
|
105
|
+
duration: 500,
|
|
106
|
+
useNativeDriver: true,
|
|
107
|
+
}),
|
|
108
|
+
])
|
|
109
|
+
);
|
|
110
|
+
animation.start();
|
|
111
|
+
} else {
|
|
112
|
+
pulseAnim.setValue(1);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return () => {
|
|
116
|
+
if (animation) {
|
|
117
|
+
animation.stop();
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}, [recorder.isRecording, pulseAnim]);
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Handle delete button press.
|
|
124
|
+
* Cancels recording and calls onCancel callback.
|
|
125
|
+
* @validates Requirements 7.1, 7.3
|
|
126
|
+
*/
|
|
127
|
+
const handleDelete = useCallback(async () => {
|
|
128
|
+
await recorder.cancel();
|
|
129
|
+
onCancel();
|
|
130
|
+
}, [recorder, onCancel]);
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Handle send button press.
|
|
134
|
+
* Stops any active recording or playback and sends the audio file.
|
|
135
|
+
* @validates Requirements 6.1, 6.2
|
|
136
|
+
*/
|
|
137
|
+
const handleSend = useCallback(async () => {
|
|
138
|
+
let filePath = recorder.filePath;
|
|
139
|
+
|
|
140
|
+
// Stop playback if currently playing
|
|
141
|
+
if (recorder.isPlaying) {
|
|
142
|
+
await recorder.pausePlayback();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// If still recording or paused (recording paused), stop recording first
|
|
146
|
+
if (recorder.isRecording || recorder.isPaused) {
|
|
147
|
+
filePath = await recorder.stopRecording();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (filePath) {
|
|
151
|
+
onSubmit(filePath);
|
|
152
|
+
}
|
|
153
|
+
}, [recorder, onSubmit]);
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Handle record/play button press.
|
|
157
|
+
* - If playing: pause playback
|
|
158
|
+
* - If paused: start playback (preview recorded segments)
|
|
159
|
+
* - If completed: resume playback if position > 0, otherwise start from beginning
|
|
160
|
+
* @validates Requirements 4.1, 4.5, 3.4
|
|
161
|
+
*/
|
|
162
|
+
const handleRecordPlayPress = useCallback(async () => {
|
|
163
|
+
if (recorder.isPlaying) {
|
|
164
|
+
// Pause playback
|
|
165
|
+
await recorder.pausePlayback();
|
|
166
|
+
} else if (recorder.isPaused && recorder.hasRecording) {
|
|
167
|
+
// WhatsApp-style: Preview recorded segments while paused
|
|
168
|
+
await recorder.startPlaybackPreview();
|
|
169
|
+
} else if (recorder.isCompleted) {
|
|
170
|
+
// If we have a position (paused mid-playback), resume from there
|
|
171
|
+
// Otherwise start from the beginning
|
|
172
|
+
if (recorder.currentPosition > 0 && recorder.currentPosition < recorder.duration) {
|
|
173
|
+
// Resume playback from current position - instant since player is already prepared
|
|
174
|
+
await recorder.resumePlayback();
|
|
175
|
+
} else {
|
|
176
|
+
// Start playback from beginning
|
|
177
|
+
await recorder.startPlayback();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}, [recorder]);
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Handle pause/mic/stop button press.
|
|
184
|
+
* - Recording: pause recording (finalize segment)
|
|
185
|
+
* - Paused: continue recording (start new segment) - WhatsApp-style
|
|
186
|
+
* @validates Requirements 3.1, 3.4, 3.5
|
|
187
|
+
*/
|
|
188
|
+
const handlePauseMicPress = useCallback(async () => {
|
|
189
|
+
if (recorder.isRecording) {
|
|
190
|
+
// Pause recording (finalize current segment)
|
|
191
|
+
await recorder.pauseRecording();
|
|
192
|
+
} else if (recorder.isPaused) {
|
|
193
|
+
// Continue recording (start new segment) - WhatsApp-style flow
|
|
194
|
+
await recorder.continueRecording();
|
|
195
|
+
}
|
|
196
|
+
}, [recorder]);
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Handle seek in waveform.
|
|
200
|
+
* In preview/paused mode or completed mode, tapping starts playback from that position.
|
|
201
|
+
* @validates Requirements 5.1, 5.2
|
|
202
|
+
*/
|
|
203
|
+
const handleSeek = useCallback(async (progress: number) => {
|
|
204
|
+
// If playing, just seek to the position
|
|
205
|
+
if (recorder.isPlaying) {
|
|
206
|
+
await recorder.seekTo(progress);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// If paused (preview mode) or completed, seek and start playback
|
|
211
|
+
if (recorder.isPaused || recorder.isCompleted) {
|
|
212
|
+
await recorder.seekAndPlay(progress);
|
|
213
|
+
}
|
|
214
|
+
}, [recorder]);
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Handle seek start - called when user starts dragging the waveform.
|
|
218
|
+
* Updates local state for smooth visual feedback.
|
|
219
|
+
* @validates Requirements 5.1
|
|
220
|
+
*/
|
|
221
|
+
const handleSeekStart = useCallback((progress: number) => {
|
|
222
|
+
setIsDragging(true);
|
|
223
|
+
setDragProgress(progress);
|
|
224
|
+
}, []);
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Handle seek end - called when user finishes dragging the waveform.
|
|
228
|
+
* Clears local drag state.
|
|
229
|
+
* @validates Requirements 5.1
|
|
230
|
+
*/
|
|
231
|
+
const handleSeekEnd = useCallback((progress: number) => {
|
|
232
|
+
setIsDragging(false);
|
|
233
|
+
setDragProgress(progress);
|
|
234
|
+
}, []);
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Calculate playback progress for waveform visualization.
|
|
238
|
+
* Uses drag progress during dragging for smooth visual feedback.
|
|
239
|
+
*/
|
|
240
|
+
const playbackProgress = useMemo(() => {
|
|
241
|
+
// During dragging, use local drag progress for smooth visual feedback
|
|
242
|
+
if (isDragging) {
|
|
243
|
+
return dragProgress;
|
|
244
|
+
}
|
|
245
|
+
if (recorder.duration <= 0) return 0;
|
|
246
|
+
return recorder.currentPosition / recorder.duration;
|
|
247
|
+
}, [isDragging, dragProgress, recorder.currentPosition, recorder.duration]);
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Determine which duration to display.
|
|
251
|
+
* Shows drag position during dragging, playback position during playing,
|
|
252
|
+
* recording duration otherwise.
|
|
253
|
+
* @validates Requirements 1.4, 4.3
|
|
254
|
+
*/
|
|
255
|
+
const displayDuration = useMemo(() => {
|
|
256
|
+
// During dragging, show the position based on drag progress
|
|
257
|
+
if (isDragging) {
|
|
258
|
+
const dragPosition = Math.floor(dragProgress * recorder.duration);
|
|
259
|
+
return formatDuration(dragPosition);
|
|
260
|
+
}
|
|
261
|
+
if (recorder.isPlaying) {
|
|
262
|
+
return formatDuration(recorder.currentPosition);
|
|
263
|
+
}
|
|
264
|
+
return formatDuration(recorder.duration);
|
|
265
|
+
}, [isDragging, dragProgress, recorder.isPlaying, recorder.currentPosition, recorder.duration]);
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Determine if seeking is allowed.
|
|
269
|
+
* Seeking is disabled during active recording.
|
|
270
|
+
* @validates Requirements 5.5
|
|
271
|
+
*/
|
|
272
|
+
const allowSeeking = useMemo(() => {
|
|
273
|
+
return !recorder.isRecording && recorder.hasRecording;
|
|
274
|
+
}, [recorder.isRecording, recorder.hasRecording]);
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Determine if send button should be enabled.
|
|
278
|
+
* Only enabled when a recording exists.
|
|
279
|
+
* @validates Requirements 6.5
|
|
280
|
+
*/
|
|
281
|
+
const isSendEnabled = recorder.hasRecording;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Render the recording indicator (red pulsing dot).
|
|
285
|
+
* Shown during active recording state.
|
|
286
|
+
* @validates Requirements 1.2
|
|
287
|
+
*/
|
|
288
|
+
const renderRecordingIndicator = () => {
|
|
289
|
+
if (!recorder.isRecording) return null;
|
|
290
|
+
|
|
291
|
+
return (
|
|
292
|
+
<Animated.View
|
|
293
|
+
style={[
|
|
294
|
+
styles.recordingIndicator,
|
|
295
|
+
{
|
|
296
|
+
backgroundColor: mergedStyle.recordingIndicatorColor,
|
|
297
|
+
opacity: pulseAnim,
|
|
298
|
+
},
|
|
299
|
+
]}
|
|
300
|
+
/>
|
|
301
|
+
);
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Render the record/play button.
|
|
306
|
+
* - Recording: shows recording indicator (red dot)
|
|
307
|
+
* - Paused: shows play icon (to preview recording) - WhatsApp-style
|
|
308
|
+
* - Completed: shows play icon
|
|
309
|
+
* - Playing: shows pause icon
|
|
310
|
+
* @validates Requirements 3.2, 3.4, 4.1
|
|
311
|
+
*/
|
|
312
|
+
const renderRecordPlayButton = () => {
|
|
313
|
+
// During active recording, show the recording indicator
|
|
314
|
+
if (recorder.isRecording) {
|
|
315
|
+
return (
|
|
316
|
+
<View style={styles.buttonContainer}>
|
|
317
|
+
{renderRecordingIndicator()}
|
|
318
|
+
</View>
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// When paused (recording paused), show play icon for preview - WhatsApp-style
|
|
323
|
+
if (recorder.isPaused && recorder.hasRecording) {
|
|
324
|
+
return (
|
|
325
|
+
<TouchableOpacity
|
|
326
|
+
style={styles.buttonContainer}
|
|
327
|
+
onPress={handleRecordPlayPress}
|
|
328
|
+
>
|
|
329
|
+
<Icon
|
|
330
|
+
name="play-arrow-fill"
|
|
331
|
+
height={mergedStyle.recordPlayButtonStyle?.iconSize}
|
|
332
|
+
width={mergedStyle.recordPlayButtonStyle?.iconSize}
|
|
333
|
+
color={mergedStyle.recordPlayButtonStyle?.iconColor}
|
|
334
|
+
icon={playIcon || recordIcon}
|
|
335
|
+
/>
|
|
336
|
+
</TouchableOpacity>
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Completed or playing state - show play/pause
|
|
341
|
+
const isPauseState = recorder.isPlaying;
|
|
342
|
+
|
|
343
|
+
let iconName: 'play-arrow-fill' | 'pause-fill' = 'play-arrow-fill';
|
|
344
|
+
let iconColor = mergedStyle.recordPlayButtonStyle?.iconColor;
|
|
345
|
+
let customIcon = playIcon || recordIcon;
|
|
346
|
+
|
|
347
|
+
if (isPauseState) {
|
|
348
|
+
iconName = 'pause-fill';
|
|
349
|
+
iconColor = mergedStyle.pauseButtonStyle?.iconColor;
|
|
350
|
+
customIcon = pauseIcon;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// Enable button only when completed (has recording and file is finalized)
|
|
354
|
+
const isEnabled = recorder.isCompleted || recorder.isPlaying;
|
|
355
|
+
|
|
356
|
+
return (
|
|
357
|
+
<TouchableOpacity
|
|
358
|
+
style={[styles.buttonContainer, !isEnabled && styles.buttonDisabled]}
|
|
359
|
+
onPress={handleRecordPlayPress}
|
|
360
|
+
disabled={!isEnabled}
|
|
361
|
+
>
|
|
362
|
+
<Icon
|
|
363
|
+
name={iconName}
|
|
364
|
+
height={mergedStyle.recordPlayButtonStyle?.iconSize}
|
|
365
|
+
width={mergedStyle.recordPlayButtonStyle?.iconSize}
|
|
366
|
+
color={iconColor}
|
|
367
|
+
icon={customIcon}
|
|
368
|
+
/>
|
|
369
|
+
</TouchableOpacity>
|
|
370
|
+
);
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Render the pause/mic button.
|
|
375
|
+
* - Recording: shows pause icon (to pause recording)
|
|
376
|
+
* - Paused: shows mic icon (to continue recording) - WhatsApp-style
|
|
377
|
+
* - Completed/Playing: hidden (empty space)
|
|
378
|
+
* @validates Requirements 1.5, 3.2, 3.5
|
|
379
|
+
*/
|
|
380
|
+
const renderPauseMicButton = () => {
|
|
381
|
+
// Only show during recording or paused states
|
|
382
|
+
if (!recorder.isRecording && !recorder.isPaused) {
|
|
383
|
+
return <View style={styles.buttonContainer} />;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// Recording state: show pause icon
|
|
387
|
+
if (recorder.isRecording) {
|
|
388
|
+
return (
|
|
389
|
+
<TouchableOpacity
|
|
390
|
+
style={styles.buttonContainer}
|
|
391
|
+
onPress={handlePauseMicPress}
|
|
392
|
+
>
|
|
393
|
+
<Icon
|
|
394
|
+
name="pause-fill"
|
|
395
|
+
height={mergedStyle.pauseButtonStyle?.iconSize}
|
|
396
|
+
width={mergedStyle.pauseButtonStyle?.iconSize}
|
|
397
|
+
color={mergedStyle.pauseButtonStyle?.iconColor}
|
|
398
|
+
icon={pauseIcon}
|
|
399
|
+
/>
|
|
400
|
+
</TouchableOpacity>
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// Paused state: show mic icon (to continue recording) - WhatsApp-style
|
|
405
|
+
return (
|
|
406
|
+
<TouchableOpacity
|
|
407
|
+
style={styles.buttonContainer}
|
|
408
|
+
onPress={handlePauseMicPress}
|
|
409
|
+
>
|
|
410
|
+
<Icon
|
|
411
|
+
name="mic-fill"
|
|
412
|
+
height={mergedStyle.micButtonStyle?.iconSize}
|
|
413
|
+
width={mergedStyle.micButtonStyle?.iconSize}
|
|
414
|
+
color={mergedStyle.micButtonStyle?.iconColor}
|
|
415
|
+
icon={micIcon}
|
|
416
|
+
/>
|
|
417
|
+
</TouchableOpacity>
|
|
418
|
+
);
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
return (
|
|
422
|
+
<View
|
|
423
|
+
style={[
|
|
424
|
+
styles.container,
|
|
425
|
+
{
|
|
426
|
+
backgroundColor: mergedStyle.backgroundColor,
|
|
427
|
+
borderRadius: mergedStyle.borderRadius,
|
|
428
|
+
},
|
|
429
|
+
mergedStyle.containerStyle,
|
|
430
|
+
mergedStyle.border,
|
|
431
|
+
]}
|
|
432
|
+
>
|
|
433
|
+
{/* Delete Button */}
|
|
434
|
+
<TouchableOpacity
|
|
435
|
+
style={styles.buttonContainer}
|
|
436
|
+
onPress={handleDelete}
|
|
437
|
+
>
|
|
438
|
+
<Icon
|
|
439
|
+
name="delete-fill"
|
|
440
|
+
height={mergedStyle.deleteButtonStyle?.iconSize}
|
|
441
|
+
width={mergedStyle.deleteButtonStyle?.iconSize}
|
|
442
|
+
color={mergedStyle.deleteButtonStyle?.iconColor}
|
|
443
|
+
icon={deleteIcon}
|
|
444
|
+
/>
|
|
445
|
+
</TouchableOpacity>
|
|
446
|
+
|
|
447
|
+
{/* Record/Play Button */}
|
|
448
|
+
{renderRecordPlayButton()}
|
|
449
|
+
|
|
450
|
+
{/* Waveform Visualizer */}
|
|
451
|
+
<View style={styles.waveformContainer}>
|
|
452
|
+
<AudioWaveformVisualizer
|
|
453
|
+
isAnimating={recorder.isRecording}
|
|
454
|
+
isPlaying={recorder.isPlaying}
|
|
455
|
+
playbackProgress={playbackProgress}
|
|
456
|
+
amplitudes={recorder.amplitudes}
|
|
457
|
+
onSeek={handleSeek}
|
|
458
|
+
onSeekStart={handleSeekStart}
|
|
459
|
+
onSeekEnd={handleSeekEnd}
|
|
460
|
+
allowSeeking={allowSeeking}
|
|
461
|
+
style={mergedStyle.waveformStyle}
|
|
462
|
+
/>
|
|
463
|
+
</View>
|
|
464
|
+
|
|
465
|
+
{/* Duration Display */}
|
|
466
|
+
<Text style={[styles.duration, mergedStyle.durationTextStyle]}>
|
|
467
|
+
{displayDuration}
|
|
468
|
+
</Text>
|
|
469
|
+
|
|
470
|
+
{/* Pause/Mic Button */}
|
|
471
|
+
{renderPauseMicButton()}
|
|
472
|
+
|
|
473
|
+
{/* Send Button — circular style matching the composer send button */}
|
|
474
|
+
<TouchableOpacity
|
|
475
|
+
style={[
|
|
476
|
+
styles.sendButtonCircle,
|
|
477
|
+
{
|
|
478
|
+
backgroundColor: isSendEnabled
|
|
479
|
+
? (theme.color.primary as string)
|
|
480
|
+
: (theme.color.background4 as string),
|
|
481
|
+
},
|
|
482
|
+
!isSendEnabled && styles.buttonDisabled,
|
|
483
|
+
]}
|
|
484
|
+
onPress={handleSend}
|
|
485
|
+
disabled={!isSendEnabled}
|
|
486
|
+
>
|
|
487
|
+
<Icon
|
|
488
|
+
name="send-fill"
|
|
489
|
+
height={mergedStyle.sendButtonStyle?.iconSize ?? 20}
|
|
490
|
+
width={mergedStyle.sendButtonStyle?.iconSize ?? 20}
|
|
491
|
+
color={
|
|
492
|
+
isSendEnabled
|
|
493
|
+
? (theme.color.primaryButtonIcon as string)
|
|
494
|
+
: (theme.color.iconSecondary as string)
|
|
495
|
+
}
|
|
496
|
+
icon={sendIcon}
|
|
497
|
+
/>
|
|
498
|
+
</TouchableOpacity>
|
|
499
|
+
</View>
|
|
500
|
+
);
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
const styles = StyleSheet.create({
|
|
504
|
+
container: {
|
|
505
|
+
flexDirection: 'row',
|
|
506
|
+
alignItems: 'center',
|
|
507
|
+
},
|
|
508
|
+
buttonContainer: {
|
|
509
|
+
justifyContent: 'center',
|
|
510
|
+
alignItems: 'center',
|
|
511
|
+
minWidth: 24,
|
|
512
|
+
minHeight: 24,
|
|
513
|
+
},
|
|
514
|
+
buttonDisabled: {
|
|
515
|
+
opacity: 0.5,
|
|
516
|
+
},
|
|
517
|
+
waveformContainer: {
|
|
518
|
+
flex: 1,
|
|
519
|
+
},
|
|
520
|
+
duration: {
|
|
521
|
+
// Gap handles spacing between elements
|
|
522
|
+
},
|
|
523
|
+
recordingIndicator: {
|
|
524
|
+
width: 12,
|
|
525
|
+
height: 12,
|
|
526
|
+
borderRadius: 6,
|
|
527
|
+
},
|
|
528
|
+
sendButtonCircle: {
|
|
529
|
+
width: 32,
|
|
530
|
+
height: 32,
|
|
531
|
+
borderRadius: 16,
|
|
532
|
+
justifyContent: 'center',
|
|
533
|
+
alignItems: 'center',
|
|
534
|
+
},
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
export default CometChatInlineAudioRecorder;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CometChatInlineAudioRecorder - Public Exports
|
|
3
|
+
*
|
|
4
|
+
* This module exports the inline audio recorder component and its associated types
|
|
5
|
+
* for use in the CometChat React Native UI Kit.
|
|
6
|
+
*
|
|
7
|
+
* @validates Requirements 8.3
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Main component exports
|
|
11
|
+
export { CometChatInlineAudioRecorder, formatDuration } from './CometChatInlineAudioRecorder';
|
|
12
|
+
export { default } from './CometChatInlineAudioRecorder';
|
|
13
|
+
|
|
14
|
+
// Type exports
|
|
15
|
+
export type {
|
|
16
|
+
CometChatInlineAudioRecorderProps,
|
|
17
|
+
CometChatInlineAudioRecorderStyle,
|
|
18
|
+
AudioWaveformVisualizerProps,
|
|
19
|
+
WaveformStyle,
|
|
20
|
+
ButtonStyle,
|
|
21
|
+
RecorderState,
|
|
22
|
+
UseAudioRecorderReturn,
|
|
23
|
+
} from './types';
|
|
24
|
+
|
|
25
|
+
// Style exports
|
|
26
|
+
export {
|
|
27
|
+
getInlineAudioRecorderStyle,
|
|
28
|
+
getInlineAudioRecorderStyleLight,
|
|
29
|
+
getInlineAudioRecorderStyleDark,
|
|
30
|
+
} from './style';
|
|
31
|
+
|
|
32
|
+
// Internal component exports (for advanced usage)
|
|
33
|
+
export { AudioWaveformVisualizer } from './AudioWaveformVisualizer';
|
|
34
|
+
export { useAudioRecorder } from './useAudioRecorder';
|