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 reference changes 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

Stable identity key for the source data. Changing this reference clears selection.

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.