From e5d594a273087b5945bb5b23d122481baefac077 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Fri, 23 Feb 2024 22:12:28 +0100 Subject: [PATCH] fix(ui): Make RealtimeAudioVisualizer store more amplitudes than current width would allow to allow user to rotate its device Signed-off-by: Myzel394 <50424412+Myzel394@users.noreply.github.com> --- .../RecorderScreen/atoms/RealTimeAudioVisualizer.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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) {