Fix slider controls not updating preview

Use rememberUpdatedState in ControlPanel to prevent stale closure
capture during continuous slider drags. This ensures the latest
blur parameters are used when updating, avoiding conflicts with
concurrent gesture updates from TiltShiftOverlay.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Ole-Morten Duesund 2026-01-29 16:36:35 +01:00
commit 656385e48d

View file

@ -42,6 +42,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@ -440,6 +441,10 @@ private fun ControlPanel(
onParamsChange: (BlurParameters) -> Unit,
modifier: Modifier = Modifier
) {
// Use rememberUpdatedState to avoid stale closure capture during slider drags
val currentParams by rememberUpdatedState(params)
val currentOnParamsChange by rememberUpdatedState(onParamsChange)
Column(
modifier = modifier
.width(200.dp)
@ -453,7 +458,7 @@ private fun ControlPanel(
label = "Blur",
value = params.blurAmount,
valueRange = BlurParameters.MIN_BLUR..BlurParameters.MAX_BLUR,
onValueChange = { onParamsChange(params.copy(blurAmount = it)) }
onValueChange = { currentOnParamsChange(currentParams.copy(blurAmount = it)) }
)
// Falloff slider
@ -461,7 +466,7 @@ private fun ControlPanel(
label = "Falloff",
value = params.falloff,
valueRange = BlurParameters.MIN_FALLOFF..BlurParameters.MAX_FALLOFF,
onValueChange = { onParamsChange(params.copy(falloff = it)) }
onValueChange = { currentOnParamsChange(currentParams.copy(falloff = it)) }
)
// Aspect ratio slider (radial mode only)
@ -470,7 +475,7 @@ private fun ControlPanel(
label = "Shape",
value = params.aspectRatio,
valueRange = BlurParameters.MIN_ASPECT..BlurParameters.MAX_ASPECT,
onValueChange = { onParamsChange(params.copy(aspectRatio = it)) }
onValueChange = { currentOnParamsChange(currentParams.copy(aspectRatio = it)) }
)
}
}