FIx height and concurrent exception
- Fix live waveform hight - Fix concurrent modification exception when sharing levels - Tidy up width of live waveform
This commit is contained in:
parent
1389c9ed24
commit
416aa3b64a
3 changed files with 34 additions and 20 deletions
|
|
@ -44,6 +44,7 @@ import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
|||
import io.element.android.libraries.theme.ElementTheme
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
import java.lang.Float.min
|
||||
|
||||
private const val DEFAULT_GRAPHICS_LAYER_ALPHA: Float = 0.99F
|
||||
private val waveFormHeight = 26.dp
|
||||
|
|
@ -57,7 +58,7 @@ fun LiveWaveformView(
|
|||
) {
|
||||
var canvasSize by remember { mutableStateOf(DpSize(0.dp, 0.dp)) }
|
||||
|
||||
val canvasWidth by remember(levels, lineWidth, linePadding) {
|
||||
val waveformWidth by remember(levels, lineWidth, linePadding) {
|
||||
derivedStateOf {
|
||||
levels.size * (lineWidth.value + linePadding.value)
|
||||
}
|
||||
|
|
@ -72,11 +73,11 @@ fun LiveWaveformView(
|
|||
) {
|
||||
Canvas(
|
||||
modifier = Modifier
|
||||
.width(Dp(canvasWidth))
|
||||
.width(canvasSize.width)
|
||||
.graphicsLayer(alpha = DEFAULT_GRAPHICS_LAYER_ALPHA)
|
||||
.then(modifier)
|
||||
) {
|
||||
canvasSize = DpSize(Dp(canvasWidth), size.height.toDp())
|
||||
canvasSize = DpSize(Dp(min(waveformWidth, width.toFloat())), size.height.toDp())
|
||||
val countThatFitsWidth = (width.toFloat() / (lineWidth.toPx() + linePadding.toPx())).toInt()
|
||||
drawWaveform(
|
||||
waveformData = levels.takeLast(countThatFitsWidth).toPersistentList(),
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ internal fun VoiceMessageRecording(
|
|||
|
||||
LiveWaveformView(
|
||||
modifier = Modifier
|
||||
.height(34.dp)
|
||||
.height(26.dp)
|
||||
.weight(1f),
|
||||
levels = levels
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue