@cometchat/chat-uikit-react-native 5.2.11 → 5.3.1
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 +4602 -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 +141 -14
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +6 -0
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +1 -20
- package/src/CometChatMessageComposer/styles.tsx +0 -1
- package/src/CometChatMessageList/CometChatMessageList.tsx +76 -30
- 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 +35 -29
- package/src/calls/CallUtils.ts +4 -4
- package/src/index.ts +48 -1
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +2 -0
- package/src/shared/constants/UIKitConstants.ts +12 -1
- package/src/shared/events/ListenerInitializer.ts +6 -0
- package/src/shared/events/messages.ts +2 -0
- 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 +37 -32
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +5 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +17 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +505 -500
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +18 -13
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +17 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +504 -499
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +504 -499
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +504 -499
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +18 -13
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +17 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +505 -500
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +17 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +17 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +18 -13
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +505 -500
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +17 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +18 -13
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +132 -11
- package/src/shared/utils/CometChatMessagePreview/style.ts +1 -3
- package/src/shared/utils/CommonUtils.ts +18 -1
- package/src/shared/utils/MarkdownUtils.ts +143 -0
- package/src/shared/utils/MentionUtils.ts +37 -0
- package/src/shared/utils/MessageReceiptUtils.ts +5 -4
- package/src/shared/utils/MessageUtils.tsx +5 -3
- package/src/shared/utils/index.ts +5 -0
- package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.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 +2 -1
- package/src/shared/views/CometChatListItem/style.ts +1 -0
- package/src/shared/views/CometChatSendButtonView/CometChatSendButtonView.tsx +32 -29
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +64 -16
- package/src/shared/views/index.ts +39 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Animated,
|
|
4
|
+
GestureResponderEvent,
|
|
5
|
+
LayoutChangeEvent,
|
|
6
|
+
PanResponder,
|
|
7
|
+
PanResponderGestureState,
|
|
8
|
+
StyleSheet,
|
|
9
|
+
View,
|
|
10
|
+
} from 'react-native';
|
|
11
|
+
import { useTheme } from '../../../theme';
|
|
12
|
+
import { AudioWaveformVisualizerProps, WaveformStyle } from './types';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Default style values for the waveform visualizer.
|
|
16
|
+
* Matches Figma design: thin rounded pill bars with compact spacing
|
|
17
|
+
*/
|
|
18
|
+
const DEFAULT_STYLE: Required<WaveformStyle> = {
|
|
19
|
+
recordingBarColor: '#6852D6', // Purple primary - will be overridden by theme
|
|
20
|
+
playedBarColor: '#6852D6', // Purple primary - will be overridden by theme
|
|
21
|
+
unplayedBarColor: '#A1A1A1', // Neutral-500 grey
|
|
22
|
+
barWidth: 2, // Figma: 2px width
|
|
23
|
+
barSpacing: 2.694, // Figma: ~2.694px gap between bars
|
|
24
|
+
minBarHeight: 2, // Figma: 2px minimum height
|
|
25
|
+
maxBarHeight: 16, // Figma: 16px maximum height
|
|
26
|
+
height: 24, // Figma: 24px container height
|
|
27
|
+
containerStyle: {},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Normalizes an amplitude value to the range [0.0, 1.0].
|
|
32
|
+
* Handles edge cases like negative values and values > 1.
|
|
33
|
+
*
|
|
34
|
+
* @param amplitude - Raw amplitude value
|
|
35
|
+
* @returns Normalized amplitude in range [0.0, 1.0]
|
|
36
|
+
* @validates Requirements 2.3
|
|
37
|
+
*/
|
|
38
|
+
export function normalizeAmplitude(amplitude: number): number {
|
|
39
|
+
// Handle edge cases
|
|
40
|
+
if (!Number.isFinite(amplitude)) {
|
|
41
|
+
return 0;
|
|
42
|
+
}
|
|
43
|
+
// Clamp to [0, 1] range
|
|
44
|
+
return Math.max(0, Math.min(1, amplitude));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Amplifies low amplitude values for better visual response.
|
|
49
|
+
* WhatsApp-style: more natural variation, less aggressive amplification.
|
|
50
|
+
* Quiet sounds show small bars, loud sounds show tall bars.
|
|
51
|
+
*
|
|
52
|
+
* @param normalizedAmplitude - Amplitude value already normalized to [0, 1]
|
|
53
|
+
* @returns Amplified amplitude in range [0.0, 1.0]
|
|
54
|
+
* @validates Requirements 2.4
|
|
55
|
+
*/
|
|
56
|
+
export function amplifyAmplitude(normalizedAmplitude: number): number {
|
|
57
|
+
// Handle edge cases
|
|
58
|
+
if (!Number.isFinite(normalizedAmplitude) || normalizedAmplitude <= 0) {
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
if (normalizedAmplitude >= 1) {
|
|
62
|
+
return 1;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// WhatsApp-style: Use a gentler curve that preserves natural variation
|
|
66
|
+
// This creates more dynamic waveforms with visible differences between quiet and loud
|
|
67
|
+
// pow(x, 0.7) gives a gentler boost than sqrt while still making quiet sounds visible
|
|
68
|
+
return Math.pow(normalizedAmplitude, 0.7);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Processes a raw amplitude value through normalization and amplification.
|
|
73
|
+
*
|
|
74
|
+
* @param rawAmplitude - Raw amplitude value from audio source
|
|
75
|
+
* @returns Processed amplitude in range [0.0, 1.0]
|
|
76
|
+
* @validates Requirements 2.3, 2.4
|
|
77
|
+
*/
|
|
78
|
+
export function processAmplitude(rawAmplitude: number): number {
|
|
79
|
+
const normalized = normalizeAmplitude(rawAmplitude);
|
|
80
|
+
return amplifyAmplitude(normalized);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Calculates seek position from touch coordinates.
|
|
85
|
+
* Clamps result to [0.0, 1.0] range regardless of input.
|
|
86
|
+
*
|
|
87
|
+
* @param touchX - X coordinate of touch
|
|
88
|
+
* @param containerWidth - Width of the waveform container
|
|
89
|
+
* @returns Seek progress in range [0.0, 1.0]
|
|
90
|
+
* @validates Requirements 5.1, 5.2, 5.3
|
|
91
|
+
*/
|
|
92
|
+
export function calculateSeekPosition(touchX: number, containerWidth: number): number {
|
|
93
|
+
// Handle edge cases
|
|
94
|
+
if (!Number.isFinite(touchX) || !Number.isFinite(containerWidth) || containerWidth <= 0) {
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Calculate progress and clamp to [0, 1]
|
|
99
|
+
const progress = touchX / containerWidth;
|
|
100
|
+
return Math.max(0, Math.min(1, progress));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* AudioWaveformVisualizer component displays animated waveform bars
|
|
105
|
+
* during recording and playback.
|
|
106
|
+
*
|
|
107
|
+
* Features:
|
|
108
|
+
* - Animated bars based on audio amplitude
|
|
109
|
+
* - Amplitude normalization and amplification for consistent visualization
|
|
110
|
+
* - Playback progress coloring (grey to purple)
|
|
111
|
+
* - Touch/drag seeking support (when allowed) with smooth local state updates
|
|
112
|
+
* - Scrolling effect during recording (new bars on right, scroll left)
|
|
113
|
+
*
|
|
114
|
+
* @validates Requirements 2.1, 2.2, 2.3, 2.4, 2.5, 4.2, 5.1, 5.2, 5.3, 5.5
|
|
115
|
+
*/
|
|
116
|
+
export const AudioWaveformVisualizer: React.FC<AudioWaveformVisualizerProps> = ({
|
|
117
|
+
isAnimating,
|
|
118
|
+
isPlaying: _isPlaying, // Reserved for future animation enhancements
|
|
119
|
+
playbackProgress,
|
|
120
|
+
amplitudes,
|
|
121
|
+
onSeek,
|
|
122
|
+
onSeekStart,
|
|
123
|
+
onSeekEnd,
|
|
124
|
+
allowSeeking,
|
|
125
|
+
style,
|
|
126
|
+
}) => {
|
|
127
|
+
const theme = useTheme();
|
|
128
|
+
const [containerWidth, setContainerWidth] = useState(0);
|
|
129
|
+
const barAnimationsRef = useRef<Animated.Value[]>([]);
|
|
130
|
+
|
|
131
|
+
// Local state for smooth dragging - updates immediately without waiting for native
|
|
132
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
133
|
+
const [localProgress, setLocalProgress] = useState(0);
|
|
134
|
+
|
|
135
|
+
// Merge styles with defaults and theme
|
|
136
|
+
const mergedStyle = useMemo((): Required<WaveformStyle> => {
|
|
137
|
+
const themeDefaults: WaveformStyle = {
|
|
138
|
+
recordingBarColor: theme.color.primary as string,
|
|
139
|
+
playedBarColor: theme.color.primary as string,
|
|
140
|
+
unplayedBarColor: theme.color.neutral400 as string,
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// First merge defaults with theme colors, then with user style
|
|
144
|
+
const baseStyle = { ...DEFAULT_STYLE, ...themeDefaults };
|
|
145
|
+
const finalStyle = { ...baseStyle, ...(style ?? {}) };
|
|
146
|
+
|
|
147
|
+
return finalStyle as Required<WaveformStyle>;
|
|
148
|
+
}, [theme, style]);
|
|
149
|
+
|
|
150
|
+
// Calculate how many bars can fit in the container
|
|
151
|
+
const maxBars = useMemo(() => {
|
|
152
|
+
if (containerWidth <= 0) return 0;
|
|
153
|
+
const totalBarWidth = mergedStyle.barWidth + mergedStyle.barSpacing;
|
|
154
|
+
return Math.floor(containerWidth / totalBarWidth);
|
|
155
|
+
}, [containerWidth, mergedStyle.barWidth, mergedStyle.barSpacing]);
|
|
156
|
+
|
|
157
|
+
// Get visible amplitudes (last N amplitudes that fit in container)
|
|
158
|
+
const visibleAmplitudes = useMemo(() => {
|
|
159
|
+
if (maxBars <= 0) return [];
|
|
160
|
+
|
|
161
|
+
// During recording, show the most recent amplitudes
|
|
162
|
+
// During playback, show all stored amplitudes
|
|
163
|
+
if (isAnimating) {
|
|
164
|
+
// Show last maxBars amplitudes during recording
|
|
165
|
+
return amplitudes.slice(-maxBars);
|
|
166
|
+
} else {
|
|
167
|
+
// During playback, distribute amplitudes across the container
|
|
168
|
+
if (amplitudes.length === 0) return [];
|
|
169
|
+
|
|
170
|
+
// If we have fewer amplitudes than bars, use what we have
|
|
171
|
+
if (amplitudes.length <= maxBars) {
|
|
172
|
+
return amplitudes;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Sample amplitudes to fit the container
|
|
176
|
+
const step = amplitudes.length / maxBars;
|
|
177
|
+
const sampled: number[] = [];
|
|
178
|
+
for (let i = 0; i < maxBars; i++) {
|
|
179
|
+
const index = Math.floor(i * step);
|
|
180
|
+
sampled.push(amplitudes[index]);
|
|
181
|
+
}
|
|
182
|
+
return sampled;
|
|
183
|
+
}
|
|
184
|
+
}, [amplitudes, maxBars, isAnimating]);
|
|
185
|
+
|
|
186
|
+
// Initialize bar animations when visible amplitudes change
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
const currentLength = barAnimationsRef.current.length;
|
|
189
|
+
const targetLength = visibleAmplitudes.length;
|
|
190
|
+
|
|
191
|
+
if (targetLength > currentLength) {
|
|
192
|
+
// Add new animated values
|
|
193
|
+
for (let i = currentLength; i < targetLength; i++) {
|
|
194
|
+
barAnimationsRef.current.push(new Animated.Value(0));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Animate bars to their target heights
|
|
199
|
+
visibleAmplitudes.forEach((amplitude, index) => {
|
|
200
|
+
if (barAnimationsRef.current[index]) {
|
|
201
|
+
const processedAmplitude = processAmplitude(amplitude);
|
|
202
|
+
Animated.timing(barAnimationsRef.current[index], {
|
|
203
|
+
toValue: processedAmplitude,
|
|
204
|
+
duration: 100,
|
|
205
|
+
useNativeDriver: false, // Height animation requires non-native driver
|
|
206
|
+
}).start();
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}, [visibleAmplitudes]);
|
|
210
|
+
|
|
211
|
+
// Handle layout changes to get container width
|
|
212
|
+
const handleLayout = useCallback((event: LayoutChangeEvent) => {
|
|
213
|
+
const { width } = event.nativeEvent.layout;
|
|
214
|
+
setContainerWidth(width);
|
|
215
|
+
}, []);
|
|
216
|
+
|
|
217
|
+
// Use the effective progress - local during drag, prop otherwise
|
|
218
|
+
const effectiveProgress = isDragging ? localProgress : playbackProgress;
|
|
219
|
+
|
|
220
|
+
// Ref to track dragging state for pan responder (avoids stale closure issues)
|
|
221
|
+
const isDraggingRef = useRef(false);
|
|
222
|
+
|
|
223
|
+
// Ref to store the initial touch position and progress for accurate delta tracking
|
|
224
|
+
const gestureStartRef = useRef({ touchX: 0, progress: 0 });
|
|
225
|
+
|
|
226
|
+
// Keep ref in sync with state
|
|
227
|
+
useEffect(() => {
|
|
228
|
+
isDraggingRef.current = isDragging;
|
|
229
|
+
}, [isDragging]);
|
|
230
|
+
|
|
231
|
+
// Pan responder for seek gestures - smooth local updates during drag
|
|
232
|
+
// Uses delta-based tracking for more accurate and smooth dragging
|
|
233
|
+
const panResponder = useMemo(() => {
|
|
234
|
+
return PanResponder.create({
|
|
235
|
+
onStartShouldSetPanResponder: () => allowSeeking,
|
|
236
|
+
onMoveShouldSetPanResponder: () => allowSeeking,
|
|
237
|
+
onPanResponderGrant: (event: GestureResponderEvent) => {
|
|
238
|
+
if (!allowSeeking || containerWidth <= 0) return;
|
|
239
|
+
|
|
240
|
+
// Use locationX which is relative to the touched view
|
|
241
|
+
const touchX = event.nativeEvent.locationX;
|
|
242
|
+
const progress = calculateSeekPosition(touchX, containerWidth);
|
|
243
|
+
|
|
244
|
+
// Store initial position for delta-based tracking
|
|
245
|
+
gestureStartRef.current = { touchX, progress };
|
|
246
|
+
|
|
247
|
+
// Start dragging - use ref for immediate access in move handler
|
|
248
|
+
isDraggingRef.current = true;
|
|
249
|
+
setIsDragging(true);
|
|
250
|
+
setLocalProgress(progress);
|
|
251
|
+
|
|
252
|
+
// Notify parent that seeking started
|
|
253
|
+
onSeekStart?.(progress);
|
|
254
|
+
},
|
|
255
|
+
onPanResponderMove: (event: GestureResponderEvent, gestureState) => {
|
|
256
|
+
// Use ref instead of state to avoid stale closure
|
|
257
|
+
if (!allowSeeking || !isDraggingRef.current || containerWidth <= 0) return;
|
|
258
|
+
|
|
259
|
+
// Use delta-based calculation for smoother, more accurate tracking
|
|
260
|
+
// gestureState.dx gives the total horizontal distance moved since gesture started
|
|
261
|
+
const deltaProgress = gestureState.dx / containerWidth;
|
|
262
|
+
const newProgress = Math.max(0, Math.min(1, gestureStartRef.current.progress + deltaProgress));
|
|
263
|
+
|
|
264
|
+
// Update local state immediately for smooth visual feedback
|
|
265
|
+
setLocalProgress(newProgress);
|
|
266
|
+
},
|
|
267
|
+
onPanResponderRelease: (event: GestureResponderEvent, gestureState) => {
|
|
268
|
+
if (!allowSeeking || containerWidth <= 0) return;
|
|
269
|
+
|
|
270
|
+
// Calculate final progress using delta
|
|
271
|
+
const deltaProgress = gestureState.dx / containerWidth;
|
|
272
|
+
const finalProgress = Math.max(0, Math.min(1, gestureStartRef.current.progress + deltaProgress));
|
|
273
|
+
|
|
274
|
+
// End dragging
|
|
275
|
+
isDraggingRef.current = false;
|
|
276
|
+
setIsDragging(false);
|
|
277
|
+
|
|
278
|
+
// Now call the actual seek handler (which may trigger native calls)
|
|
279
|
+
onSeek?.(finalProgress);
|
|
280
|
+
onSeekEnd?.(finalProgress);
|
|
281
|
+
},
|
|
282
|
+
onPanResponderTerminate: () => {
|
|
283
|
+
// Drag was interrupted
|
|
284
|
+
isDraggingRef.current = false;
|
|
285
|
+
setIsDragging(false);
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
// Only recreate when these stable dependencies change - NOT isDragging
|
|
289
|
+
}, [allowSeeking, containerWidth, onSeek, onSeekStart, onSeekEnd]);
|
|
290
|
+
|
|
291
|
+
// Calculate bar height from amplitude
|
|
292
|
+
const getBarHeight = useCallback((amplitude: number): number => {
|
|
293
|
+
const processed = processAmplitude(amplitude);
|
|
294
|
+
const heightRange = mergedStyle.maxBarHeight - mergedStyle.minBarHeight;
|
|
295
|
+
return mergedStyle.minBarHeight + (processed * heightRange);
|
|
296
|
+
}, [mergedStyle.minBarHeight, mergedStyle.maxBarHeight]);
|
|
297
|
+
|
|
298
|
+
// Determine bar color based on playback progress
|
|
299
|
+
const getBarColor = useCallback((barIndex: number, totalBars: number): string => {
|
|
300
|
+
if (isAnimating) {
|
|
301
|
+
// During recording, all bars are recording color
|
|
302
|
+
return mergedStyle.recordingBarColor;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (totalBars === 0) {
|
|
306
|
+
return mergedStyle.unplayedBarColor;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// During playback/completed, color based on progress (use effective progress for smooth drag)
|
|
310
|
+
const barProgress = (barIndex + 1) / totalBars;
|
|
311
|
+
if (barProgress <= effectiveProgress) {
|
|
312
|
+
return mergedStyle.playedBarColor;
|
|
313
|
+
}
|
|
314
|
+
return mergedStyle.unplayedBarColor;
|
|
315
|
+
}, [isAnimating, effectiveProgress, mergedStyle]);
|
|
316
|
+
|
|
317
|
+
// Render bars
|
|
318
|
+
const renderBars = useCallback(() => {
|
|
319
|
+
if (visibleAmplitudes.length === 0) {
|
|
320
|
+
// Show placeholder bars when no amplitudes
|
|
321
|
+
const placeholderCount = Math.min(maxBars, 20);
|
|
322
|
+
return Array.from({ length: placeholderCount }).map((_, index) => (
|
|
323
|
+
<View
|
|
324
|
+
key={`placeholder-${index}`}
|
|
325
|
+
style={[
|
|
326
|
+
styles.bar,
|
|
327
|
+
{
|
|
328
|
+
width: mergedStyle.barWidth,
|
|
329
|
+
height: mergedStyle.minBarHeight,
|
|
330
|
+
backgroundColor: mergedStyle.unplayedBarColor,
|
|
331
|
+
marginHorizontal: mergedStyle.barSpacing / 2,
|
|
332
|
+
},
|
|
333
|
+
]}
|
|
334
|
+
/>
|
|
335
|
+
));
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return visibleAmplitudes.map((amplitude, index) => {
|
|
339
|
+
const animatedValue = barAnimationsRef.current[index];
|
|
340
|
+
const barColor = getBarColor(index, visibleAmplitudes.length);
|
|
341
|
+
|
|
342
|
+
if (animatedValue) {
|
|
343
|
+
// Use animated height
|
|
344
|
+
const animatedHeight = animatedValue.interpolate({
|
|
345
|
+
inputRange: [0, 1],
|
|
346
|
+
outputRange: [mergedStyle.minBarHeight, mergedStyle.maxBarHeight],
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
return (
|
|
350
|
+
<Animated.View
|
|
351
|
+
key={`bar-${index}`}
|
|
352
|
+
style={[
|
|
353
|
+
styles.bar,
|
|
354
|
+
{
|
|
355
|
+
width: mergedStyle.barWidth,
|
|
356
|
+
height: animatedHeight,
|
|
357
|
+
backgroundColor: barColor,
|
|
358
|
+
marginHorizontal: mergedStyle.barSpacing / 2,
|
|
359
|
+
},
|
|
360
|
+
]}
|
|
361
|
+
/>
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// Fallback to static height
|
|
366
|
+
const height = getBarHeight(amplitude);
|
|
367
|
+
return (
|
|
368
|
+
<View
|
|
369
|
+
key={`bar-${index}`}
|
|
370
|
+
style={[
|
|
371
|
+
styles.bar,
|
|
372
|
+
{
|
|
373
|
+
width: mergedStyle.barWidth,
|
|
374
|
+
height,
|
|
375
|
+
backgroundColor: barColor,
|
|
376
|
+
marginHorizontal: mergedStyle.barSpacing / 2,
|
|
377
|
+
},
|
|
378
|
+
]}
|
|
379
|
+
/>
|
|
380
|
+
);
|
|
381
|
+
});
|
|
382
|
+
}, [visibleAmplitudes, maxBars, mergedStyle, getBarColor, getBarHeight]);
|
|
383
|
+
|
|
384
|
+
return (
|
|
385
|
+
<View
|
|
386
|
+
style={[
|
|
387
|
+
styles.container,
|
|
388
|
+
{ height: mergedStyle.height },
|
|
389
|
+
mergedStyle.containerStyle,
|
|
390
|
+
]}
|
|
391
|
+
onLayout={handleLayout}
|
|
392
|
+
{...panResponder.panHandlers}
|
|
393
|
+
>
|
|
394
|
+
<View style={styles.barsContainer}>
|
|
395
|
+
{renderBars()}
|
|
396
|
+
</View>
|
|
397
|
+
</View>
|
|
398
|
+
);
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
const styles = StyleSheet.create({
|
|
402
|
+
container: {
|
|
403
|
+
flex: 1,
|
|
404
|
+
justifyContent: 'center',
|
|
405
|
+
overflow: 'hidden',
|
|
406
|
+
},
|
|
407
|
+
barsContainer: {
|
|
408
|
+
flexDirection: 'row',
|
|
409
|
+
alignItems: 'center',
|
|
410
|
+
justifyContent: 'flex-start',
|
|
411
|
+
},
|
|
412
|
+
bar: {
|
|
413
|
+
borderRadius: 1000, // Figma: fully rounded pill shape
|
|
414
|
+
},
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
export default AudioWaveformVisualizer;
|