Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JEWEL-723] Fix excessive recompositions in SelectableLazyColumn #2905

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion platform/jewel/decorated-window/api/decorated-window.api
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public abstract interface class com/jetbrains/DesktopActions$Handler {
public fun print (Ljava/io/File;)V
}

public class com/jetbrains/JBR {
public final class com/jetbrains/JBR {
public static fun getApiVersion ()Ljava/lang/String;
public static fun getDesktopActions ()Lcom/jetbrains/DesktopActions;
public static fun getRoundedCornersManager ()Lcom/jetbrains/RoundedCornersManager;
Expand Down
1 change: 1 addition & 0 deletions platform/jewel/foundation/api/foundation.api
Original file line number Diff line number Diff line change
Expand Up @@ -1023,3 +1023,4 @@ public final class org/jetbrains/jewel/foundation/util/JewelLogger$Companion {
public final fun getInstance (Ljava/lang/Class;)Lorg/jetbrains/jewel/foundation/util/JewelLogger;
public final fun getInstance (Ljava/lang/String;)Lorg/jetbrains/jewel/foundation/util/JewelLogger;
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ internal abstract class ContentSource<T : ContentItem> {
}
}

internal data class FilteredContentSource<T : ContentItem>(override val items: List<T>, val original: ContentSource<*>) :
ContentSource<T>() {
internal data class FilteredContentSource<T : ContentItem>(
override val items: List<T>,
val original: ContentSource<*>,
) : ContentSource<T>() {
override val displayName: String
get() = original.displayName
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the
// Apache 2.0 license.
package org.jetbrains.jewel.samples.standalone.view.component

import androidx.compose.foundation.border
Expand Down
Loading