11import { useVoiceAssistant } from "@livekit/components-react" ;
22import { BarVisualizer , VideoTrack } from "@livekit/react-native" ;
3- import { StyleProp , StyleSheet , View , ViewStyle } from "react-native" ;
3+ import React , { useCallback , useLayoutEffect , useState } from "react" ;
4+ import { LayoutChangeEvent , StyleProp , StyleSheet , View , ViewStyle } from "react-native" ;
45
56type AgentVisualizationProps = {
67 style : StyleProp < ViewStyle > ,
78}
89
10+ const barSize = 0.20 ;
11+
912export default function AgentVisualization ( {
1013 style
1114} : AgentVisualizationProps ) {
1215 const { state, audioTrack, videoTrack } = useVoiceAssistant ( ) ;
13-
16+ const [ barWidth , setBarWidth ] = useState ( 0 ) ;
17+ const [ barBorderRadius , setBarBorderRadius ] = useState ( 0 ) ;
18+ const layoutCallback = useCallback ( ( event : LayoutChangeEvent ) => {
19+ const { x, y, width, height } = event . nativeEvent . layout
20+ console . log ( x , y , width , height ) ;
21+ setBarWidth ( barSize * height ) ;
22+ setBarBorderRadius ( barSize * height ) ;
23+ } , [ ] ) ;
1424 let videoView = ( videoTrack
1525 ? < VideoTrack
1626 trackRef = { videoTrack }
@@ -20,17 +30,20 @@ export default function AgentVisualization({
2030 )
2131 return (
2232 < View style = { [ style , styles . container ] } >
23-
24- < BarVisualizer
25- state = { state }
26- barCount = { 5 }
27- options = { {
28- minHeight : 0.1 ,
29- barWidth : 12 ,
30- } }
31- trackRef = { audioTrack }
32- style = { styles . voiceAssistant }
33- />
33+ < View style = { styles . barVisualizerContainer } onLayout = { layoutCallback } >
34+ < BarVisualizer
35+ state = { state }
36+ barCount = { 5 }
37+ options = { {
38+ minHeight : barSize ,
39+ barWidth : barWidth ,
40+ barColor : '#FFFFFF' ,
41+ barBorderRadius : barBorderRadius ,
42+ } }
43+ trackRef = { audioTrack }
44+ style = { styles . barVisualizer }
45+ />
46+ </ View >
3447 { videoView }
3548 </ View >
3649 ) ;
@@ -48,9 +61,13 @@ const styles = StyleSheet.create({
4861 height : '100%' ,
4962 zIndex : 1 ,
5063 } ,
51- voiceAssistant : {
64+ barVisualizerContainer : {
5265 width : '100%' ,
5366 height : '30%' ,
5467 zIndex : 0 ,
5568 } ,
69+ barVisualizer : {
70+ width : '100%' ,
71+ height : '100%' ,
72+ } ,
5673} ) ;
0 commit comments