rememberSelectionLifecycle

fun rememberSelectionLifecycle(selection: ChartSelection, data: Any?, itemCount: Int = Int.MAX_VALUE, lifetime: SelectionLifetime = SelectionLifetime.Persistent, autoDeselectTrigger: Any? = selection.version)(source)

Drives the background lifecycle of a ChartSelection:

  • Clears the selection when data changes according to equality between recompositions. The first composition never clears selection, so an initialIndex provided to rememberChartSelection is preserved.

  • Clears the selection when itemCount becomes zero, or when the currently selected index is no longer in 0 until itemCount. The bounds check re-runs whenever the index or item count changes, so external selection.select(...) calls that fall out of range are caught immediately.

  • When lifetime is SelectionLifetime.AutoDeselect, renews the auto-clear timer on each new selection.

The helper never overrides gesture-driven selection or explicit clear() calls beyond the rules above. Density-mode (compact vs scrollable) reshuffles should be reported through itemCount when the source range changes; if the chart reshuffles renderData while preserving source indices, pass itemCount = Int.MAX_VALUE to skip the bounds check.

Parameters

selection

The hoisted selection holder.

data

Source data key compared using equality. An unequal value clears selection; a new instance equal to the previous value preserves it.

itemCount

Number of selectable items in the source data, or Int.MAX_VALUE to skip the bounds check.

lifetime

Background policy. Defaults to SelectionLifetime.Persistent.

autoDeselectTrigger

Restarts SelectionLifetime.AutoDeselect when its value changes. Pass null until automatic cleanup is armed.