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>
This commit is contained in:
Myzel394 2024-02-23 22:12:28 +01:00
parent af19eec613
commit e5d594a273
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185

View File

@ -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) {