Skip to content

Commit

Permalink
Remove redundant index from SelectableLazyColumn items
Browse files Browse the repository at this point in the history
  • Loading branch information
Walingar committed Nov 1, 2023
1 parent 9762bba commit b47d05a
Showing 1 changed file with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ interface SelectableLazyListScope {
}

internal class SelectableLazyListScopeContainer : SelectableLazyListScope {

private var entriesCount = 0

private val keys = mutableListOf<SelectableLazyListKey>()
private val entries = mutableListOf<Entry>()

Expand All @@ -78,22 +75,19 @@ internal class SelectableLazyListScopeContainer : SelectableLazyListScope {
val key: Any,
val contentType: Any?,
val content: @Composable (SelectableLazyItemScope.() -> Unit),
val index: Int,
) : Entry

data class Items(
val count: Int,
val key: (index: Int) -> Any,
val contentType: (index: Int) -> Any?,
val itemContent: @Composable (SelectableLazyItemScope.(index: Int) -> Unit),
val startIndex: Int,
) : Entry

data class StickyHeader(
val key: Any,
val contentType: Any?,
val content: @Composable (SelectableLazyItemScope.() -> Unit),
val index: Int,
) : Entry
}

Expand All @@ -104,8 +98,7 @@ internal class SelectableLazyListScopeContainer : SelectableLazyListScope {
content: @Composable (SelectableLazyItemScope.() -> Unit),
) {
keys.add(if (selectable) Selectable(key) else NotSelectable(key))
entries.add(Entry.Item(key, contentType, content, entriesCount))
entriesCount++
entries.add(Entry.Item(key, contentType, content))
}

override fun items(
Expand All @@ -123,8 +116,7 @@ internal class SelectableLazyListScopeContainer : SelectableLazyListScope {
}
}
keys.addAll(selectableKeys)
entries.add(Entry.Items(count, key, contentType, itemContent, entriesCount))
entriesCount += count
entries.add(Entry.Items(count, key, contentType, itemContent))
}

@ExperimentalFoundationApi
Expand All @@ -135,8 +127,7 @@ internal class SelectableLazyListScopeContainer : SelectableLazyListScope {
content: @Composable (SelectableLazyItemScope.() -> Unit),
) {
keys.add(if (selectable) Selectable(key) else NotSelectable(key))
entries.add(Entry.StickyHeader(key, contentType, content, entriesCount))
entriesCount++
entries.add(Entry.StickyHeader(key, contentType, content))
}
}

Expand Down

0 comments on commit b47d05a

Please sign in to comment.