fix(charts): hoist rememberVicoZoomState above vararg layers to prevent ClassCastException (#5060)

This commit is contained in:
James Rich 2026-04-10 19:05:56 -05:00 committed by GitHub
parent 9c8532f80d
commit 37e9e2c8f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -96,6 +96,11 @@ fun GenericMetricChart(
onPointSelected: ((Double) -> Unit)? = null,
vicoScrollState: VicoScrollState = rememberVicoScrollState(),
) {
// Hoist zoom state above rememberCartesianChart so that the variable slot count
// from the vararg layers spread does not shift this remember call during recomposition
// (toggling legend chips changes the layer count, which corrupts the slot table).
val zoomState = rememberVicoZoomState(zoomEnabled = true, initialZoom = Zoom.Content)
val markerVisibilityListener =
remember(onPointSelected) {
object : CartesianMarkerVisibilityListener {
@ -126,7 +131,7 @@ fun GenericMetricChart(
modelProducer = modelProducer,
modifier = modifier,
scrollState = vicoScrollState,
zoomState = rememberVicoZoomState(zoomEnabled = true, initialZoom = Zoom.Content),
zoomState = zoomState,
)
}