diff --git a/app/src/main/java/app/myzel394/alibi/ui/components/RecorderScreen/atoms/RealTimeAudioVisualizer.kt b/app/src/main/java/app/myzel394/alibi/ui/components/RecorderScreen/atoms/RealTimeAudioVisualizer.kt index e1bd20f..b2d0808 100644 --- a/app/src/main/java/app/myzel394/alibi/ui/components/RecorderScreen/atoms/RealTimeAudioVisualizer.kt +++ b/app/src/main/java/app/myzel394/alibi/ui/components/RecorderScreen/atoms/RealTimeAudioVisualizer.kt @@ -61,11 +61,18 @@ fun RealtimeAudioVisualizer( } val configuration = LocalConfiguration.current - val screenWidth = with(LocalDensity.current) { configuration.screenWidthDp.dp.toPx() } + // Use greater value of width and height to make sure the amplitudes are shown + // when the user rotates the device + val availableSpace = with(LocalDensity.current) { + Math.max( + configuration.screenWidthDp.dp.toPx(), + configuration.screenHeightDp.dp.toPx() + ) + } - LaunchedEffect(screenWidth) { + LaunchedEffect(availableSpace) { // Add 1 to allow the visualizer to overflow the screen - audioRecorder.setMaxAmplitudesAmount(ceil(screenWidth.toInt() / BOX_DIFF).toInt() + 1) + audioRecorder.setMaxAmplitudesAmount(ceil(availableSpace.toInt() / BOX_DIFF).toInt() + 1) } Canvas(modifier = modifier) {