Remove useless derivedStateOf
This commit is contained in:
parent
9d4e9fe2d2
commit
dca7bf0a77
1 changed files with 8 additions and 13 deletions
|
|
@ -15,7 +15,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.derivedStateOf
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableIntStateOf
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
|
@ -51,27 +50,23 @@ fun LiveWaveformView(
|
||||||
linePadding: Dp = 2.dp,
|
linePadding: Dp = 2.dp,
|
||||||
) {
|
) {
|
||||||
var canvasSize by remember { mutableStateOf(DpSize(0.dp, 0.dp)) }
|
var canvasSize by remember { mutableStateOf(DpSize(0.dp, 0.dp)) }
|
||||||
|
|
||||||
var parentWidth by remember { mutableIntStateOf(0) }
|
var parentWidth by remember { mutableIntStateOf(0) }
|
||||||
|
val waveformWidth = remember(levels.size, lineWidth, linePadding) {
|
||||||
val waveformWidth by remember(levels.size, lineWidth, linePadding) {
|
levels.size * (lineWidth.value + linePadding.value)
|
||||||
derivedStateOf {
|
|
||||||
levels.size * (lineWidth.value + linePadding.value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
contentAlignment = Alignment.CenterEnd,
|
contentAlignment = Alignment.CenterEnd,
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.height(waveFormHeight)
|
.height(waveFormHeight)
|
||||||
.onSizeChanged { parentWidth = it.width }
|
.onSizeChanged { parentWidth = it.width }
|
||||||
) {
|
) {
|
||||||
Canvas(
|
Canvas(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.width(Dp(waveformWidth))
|
.width(Dp(waveformWidth))
|
||||||
.graphicsLayer(alpha = DEFAULT_GRAPHICS_LAYER_ALPHA)
|
.graphicsLayer(alpha = DEFAULT_GRAPHICS_LAYER_ALPHA)
|
||||||
.then(modifier)
|
.then(modifier)
|
||||||
) {
|
) {
|
||||||
val width = min(waveformWidth, parentWidth.toFloat())
|
val width = min(waveformWidth, parentWidth.toFloat())
|
||||||
canvasSize = DpSize(width.dp, size.height.toDp())
|
canvasSize = DpSize(width.dp, size.height.toDp())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue