import React, { useEffect, useState } from 'react'; import { LayoutChangeEvent, StyleSheet, Text, View, ViewStyle } from 'react-native'; import { MaterialIcons } from '@expo/vector-icons'; import Colors from '../theme/Colors'; import { useVoiceClient } from '../context/VoiceClientContext'; const dotCount = 5; const WaveformView: React.FC = () => { const [audioLevels, setAudioLevels] = useState(Array(dotCount).fill(0)); const [dimensions, setDimensions] = useState({ width: 0, height: 0 }); const { currentState: voiceClientStatus, botReady: isBotReady, remoteAudioLevel: audioLevel } = useVoiceClient(); const onLayout = (event: LayoutChangeEvent) => { const { width, height } = event.nativeEvent.layout; setDimensions({ width, height }); }; useEffect(() => { setAudioLevels((prevLevels) => [...prevLevels.slice(1), audioLevel]); }, [audioLevel]); const { width, height } = dimensions; const circleSize = width * 0.9; const innerCircleSize = width * 0.82; const barWidth = (width * 0.5) / dotCount; return ( {isBotReady ? ( audioLevel > 0 ? ( {audioLevels.map((level, index) => ( ))} ) : ( {Array(dotCount) .fill(0) .map((_, index) => ( ))} ) ) : ( {voiceClientStatus} )} ); }; const styles = StyleSheet.create({ container: { justifyContent: 'center', alignItems: 'center', width: "100%", } as ViewStyle, outerCircle: { borderWidth: 1, borderColor: 'gray', justifyContent: 'center', alignItems: 'center', } as ViewStyle, innerCircle: { justifyContent: 'center', alignItems: 'center', position: 'relative', } as ViewStyle, waveformContainer: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', } as ViewStyle, waveformBar: { backgroundColor: 'white', maxHeight: '100%', borderRadius: 12, } as ViewStyle, dotContainer: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', } as ViewStyle, dot: { backgroundColor: 'white', borderRadius: 50, } as ViewStyle, notReadyContainer: { justifyContent: 'center', alignItems: 'center', } as ViewStyle, voiceClientStatusText: { color: 'white', marginTop: 10, fontSize: 16, fontWeight: 'bold', } as ViewStyle, }); export default WaveformView;