88package com.nextcloud.talk.ui
99
1010import androidx.compose.foundation.background
11- import androidx.compose.foundation.interaction.MutableInteractionSource
1211import androidx.compose.foundation.layout.Box
1312import androidx.compose.foundation.layout.height
1413import androidx.compose.foundation.layout.size
@@ -17,7 +16,6 @@ import androidx.compose.foundation.shape.CircleShape
1716import androidx.compose.material3.ExperimentalMaterial3Api
1817import androidx.compose.material3.MaterialTheme
1918import androidx.compose.material3.Slider
20- import androidx.compose.material3.SliderState
2119import androidx.compose.runtime.Composable
2220import androidx.compose.runtime.remember
2321import androidx.compose.ui.Modifier
@@ -32,16 +30,16 @@ const val WAVEFORM_THUMB_SIZE = 20
3230const val WAVEFORM_SIZE = 30
3331@OptIn(ExperimentalMaterial3Api ::class )
3432@Composable
35- fun WaveformSeekBar1 ( sliderState : SliderState , modifier : Modifier , interaction : MutableInteractionSource , waveData : FloatArray ) {
33+ fun ComposeWaveformSeekBar ( value : Float , onValueChange : ( Float ) -> Unit , modifier : Modifier , waveData : FloatArray ) {
3634 val barWidth = Stroke .DefaultMiter
3735 val thumbSize = WAVEFORM_THUMB_SIZE .dp
3836 val inversePrimary = MaterialTheme .colorScheme.inversePrimary
3937 val onPrimaryContainer = MaterialTheme .colorScheme.onPrimaryContainer
4038
4139 Slider (
42- state = sliderState ,
43- interactionSource = interaction ,
44- track = { state ->
40+ value = value ,
41+ onValueChange = onValueChange ,
42+ track = {
4543 Box (modifier = modifier
4644 .drawWithCache {
4745 onDrawBehind {
@@ -51,7 +49,7 @@ fun WaveformSeekBar1(sliderState: SliderState, modifier: Modifier, interaction:
5149 for (i in waveData.indices) {
5250 val x: Float = i * (barWidth + barGap)
5351 val y: Float = waveData[i] * height
54- val isXBeforeThumb = (x / this .size.width) <= state. value + 0.025
52+ val isXBeforeThumb = (x / this .size.width) <= value + 0.025
5553
5654 drawLine(
5755 if (isXBeforeThumb) inversePrimary else onPrimaryContainer,
@@ -79,27 +77,13 @@ fun WaveformSeekBar1(sliderState: SliderState, modifier: Modifier, interaction:
7977@Preview
8078fun Preview () {
8179 val waveData = remember { FloatArray (50 ) { (Math .random() % 1 ).toFloat() } }
82- val sliderState = SliderState ()
83- val interaction = remember { MutableInteractionSource () }
84- sliderState.onValueChange = { progress ->
85- if (sliderState.isDragging) {
86- // onSeek(message.id, progress)
87- }
88- }
89-
90- // to update the slider, it should have
91- sliderState.value
92- // be updated in some kind of async programming callback
93- // but in practice, that is abstracted away due to the magic of
94- // recomposition, leading to just this derived state
95- // sliderState.value = typeContent.seekbarProgress
9680
97- WaveformSeekBar1 (
98- sliderState,
81+ ComposeWaveformSeekBar (
82+ 0f ,
83+ {},
9984 modifier = Modifier
10085 .height(56 .dp)
10186 .width(200 .dp),
102- interaction,
10387 waveData
10488 )
10589}
0 commit comments