mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
fix excessive recompositions in SelectableLazyColumn
reference https://github.com/JetBrains/jewel/pull/723 closes https://github.com/JetBrains/intellij-community/pull/2905 (cherry picked from commit c7cf1e0405ac1894c7318627381dfb39dd0e0b20) (cherry picked from commit 0ee0e01e668d629d6216eaf15552c0b26d13f774) IJ-MR-155570 GitOrigin-RevId: 0bdf49d3a02e534b6c3a783de36534443afb15a1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3cf432e2c8
commit
17906ab3f6
@@ -15,9 +15,7 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusDirection
|
||||
@@ -59,19 +57,20 @@ public fun SelectableLazyColumn(
|
||||
content: SelectableLazyListScope.() -> Unit,
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
val container = SelectableLazyListScopeContainer().apply(content)
|
||||
val container = remember(content) { SelectableLazyListScopeContainer().apply(content) }
|
||||
|
||||
val keys = remember(container) { container.getKeys() }
|
||||
var isFocused by remember { mutableStateOf(false) }
|
||||
|
||||
val latestOnSelectedIndexesChanged = rememberUpdatedState(onSelectedIndexesChange)
|
||||
LaunchedEffect(state, container) {
|
||||
snapshotFlow { state.selectedKeys }
|
||||
.collect { selectedKeys ->
|
||||
val indices = selectedKeys.mapNotNull { key -> container.getKeyIndex(key) }
|
||||
latestOnSelectedIndexesChanged.value.invoke(indices)
|
||||
}
|
||||
var lastSelectedKeys by remember { mutableStateOf(state.selectedKeys) }
|
||||
LaunchedEffect(state.selectedKeys, onSelectedIndexesChange, container) {
|
||||
if (lastSelectedKeys == state.selectedKeys) return@LaunchedEffect
|
||||
|
||||
val indices = state.selectedKeys.mapNotNull { key -> container.getKeyIndex(key) }
|
||||
lastSelectedKeys = state.selectedKeys
|
||||
onSelectedIndexesChange(indices)
|
||||
}
|
||||
|
||||
val focusManager = LocalFocusManager.current
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
LazyColumn(
|
||||
|
||||
Reference in New Issue
Block a user