[JEWEL-938] Split SelectableLazyColumn into Single/Multi APIs and add initial selected keys support#3450
Conversation
| f:org.jetbrains.jewel.foundation.lazy.SelectableLazyListStateKt | ||
| - sf:getVisibleItemsRange(androidx.compose.foundation.lazy.LazyListState):kotlin.ranges.IntRange | ||
| - sf:getVisibleItemsRange(org.jetbrains.jewel.foundation.lazy.SelectableLazyListState):kotlin.ranges.IntRange | ||
| - sf:rememberSelectableLazyListState(I,I,androidx.compose.runtime.Composer,I,I):org.jetbrains.jewel.foundation.lazy.SelectableLazyListState |
There was a problem hiding this comment.
The rememberSelectableLazyListState 2-args function is depricated
fun rememberSelectableLazyListState(
initialFirstVisibleItemIndex: Int = 0,
initialFirstVisibleItemScrollOffset: Int = 0,
)in favor of rememberSelectableLazyListState 4-args function:
public fun rememberSingleSelectionLazyListState(
initialFirstVisibleItemIndex: Int = 0,
initialFirstVisibleItemScrollOffset: Int = 0,
initialSelectedKey: Any? = null,
)ef805e1 to
fb0e75d
Compare
fb0e75d to
1133634
Compare
2a83570 to
458eb7c
Compare
DanielSouzaBertoldi
left a comment
There was a problem hiding this comment.
Great work! 🚀
| message = | ||
| "Migrate to SingleSelectionLazyColumn or MultiSelectionLazyColumn and use the matching " + | ||
| "rememberSingleSelectionLazyListState(...) or rememberMultiSelectionLazyListState(...)." | ||
| ) |
There was a problem hiding this comment.
We should discuss about how long can a method/class stay deprecated. I get we want to maintain source compat in this case, but in the release notes/deprecation message we could be a bit more precise with when are we expecting to fully hide this API for good
There was a problem hiding this comment.
Far point! As far as I know IntelliJ keeps API deprecated for at least two releases. I'm also fine with this approach :) @rock3r @DanielSouzaBertoldi What do you think if we state that we are planning to delete this in 26.3 release?
...el/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyListState.kt
Outdated
Show resolved
Hide resolved
… initial selected keys support - Split SelectableLazyColumn into new typed entry points `SingleSelectionLazyColumn` and `MultiSelectionLazyColumn`, each bound to the correct selection mode through dedicated state types. - Add support for initializing legacy and new states with preselected keys (`initialSelectedKeys` / `initialSelectedKey`) without triggering `onSelectedIndexesChange` on first composition. - Extend `SelectableLazyListState` with `selectionMode` and `initialSelectedKeys` metadata used for legacy compatibility paths and mismatch diagnostics. - Preserve source and binary compatibility by keeping legacy `SelectableLazyColumn` and `rememberSelectableLazyListState` overloads, with migration-focused deprecations. - Preserve legacy precedence contract where the explicit ` selectionMode ` parameter wins over `state.selectionMode` and emits warnings on mismatches instead of throwing or mutating state during composition. - Add tests for typed states, typed columns, remember overload normalization, legacy mismatch scenarios, and multi-selection keyboard edge cases. Signed-off-by: Nebojsa.Vuksic <nebojsa.vuksic@jetbrains.com>
458eb7c to
2368400
Compare
Summary
This PR splits Jewel
SelectableLazyColumninto explicit single-selection and multi-selection APIs (SingleSelectionLazyColumn,MultiSelectionLazyColumn) and adds support for initial selected keys during state creation, while preserving legacy API behavior andcompatibility.
Dependency
This PR depends on #3446 and should be merged only after that PR lands. Until then, the PR stays in draft mode.
Changes
SingleSelectionLazyColumnandMultiSelectionLazyColumnas new composable entry points.SingleSelectionLazyListStateandMultiSelectionLazyListState.rememberSingleSelectionLazyListState(initialSelectedKey = ...)rememberMultiSelectionLazyListState(initialSelectedKeys = ...)SelectableLazyListStatewithselectionModeandinitialSelectedKeysmetadata used in legacy compatibility scenarios.SelectableLazyColumn/rememberSelectableLazyListStateAPIs for source and binary compatibility and marked migration path with deprecations.rememberSelectableLazyListState(firstVisibleItemIndex, firstVisibleItemScrollOffset)and directed users to the 4-arg overload.onSelectedIndexesChange.Edge cases and behavior details
selectionMode=SelectionMode.Singlewith legacy state containing multiple selected keys.SelectionMode.Single.SelectionMode.Nonewith legacy state already containing selected keys.SelectionMode.Nonesemantics.SelectionMode.Nonedrops all initial keys.SelectionMode.Singlekeeps first key from list order.SelectionMode.Multiplekeeps all keys, deduplicated in insertion order.Why new APIs and why keep old ones
Release notes
New features
SingleSelectionLazyColumnandMultiSelectionLazyColumnwith dedicated typed state and remember APIs.initialSelectedKey/initialSelectedKeys).Bug fixes
Deprecated API
SelectableLazyColumnentry points in favor of explicit single/multi APIs while preservingcompatibility overloads.
rememberSelectableLazyListState(...); use the 4-arg overload.