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

Rework SelectableLazyColumn #620

Merged
merged 5 commits into from
Sep 30, 2024
Merged
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
8 changes: 4 additions & 4 deletions foundation/api/foundation.api
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ public final class org/jetbrains/jewel/foundation/code/highlighting/NoOpCodeHigh
public fun highlight-C7ITchA (Ljava/lang/String;Ljava/lang/String;)Lkotlinx/coroutines/flow/Flow;
}

public final class org/jetbrains/jewel/foundation/lazy/BasicSelectableLazyColumnKt {
public static final fun BasicSelectableLazyColumn (Landroidx/compose/ui/Modifier;Lorg/jetbrains/jewel/foundation/lazy/SelectionMode;Lorg/jetbrains/jewel/foundation/lazy/SelectableLazyListState;Landroidx/compose/foundation/layout/PaddingValues;ZLkotlin/jvm/functions/Function1;Landroidx/compose/foundation/layout/Arrangement$Vertical;Landroidx/compose/ui/Alignment$Horizontal;Landroidx/compose/foundation/gestures/FlingBehavior;Lorg/jetbrains/jewel/foundation/lazy/tree/KeyActions;Lorg/jetbrains/jewel/foundation/lazy/tree/PointerEventActions;Landroidx/compose/foundation/interaction/MutableInteractionSource;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;III)V
}

public class org/jetbrains/jewel/foundation/lazy/DefaultMacOsSelectableColumnKeybindings : org/jetbrains/jewel/foundation/lazy/DefaultSelectableColumnKeybindings {
public static final field $stable I
public static final field Companion Lorg/jetbrains/jewel/foundation/lazy/DefaultMacOsSelectableColumnKeybindings$Companion;
Expand Down Expand Up @@ -372,10 +376,6 @@ public final class org/jetbrains/jewel/foundation/lazy/SelectableColumnOnKeyEven
public static fun onSelectPreviousItem (Lorg/jetbrains/jewel/foundation/lazy/SelectableColumnOnKeyEvent;Ljava/util/List;Lorg/jetbrains/jewel/foundation/lazy/SelectableLazyListState;)V
}

public final class org/jetbrains/jewel/foundation/lazy/SelectableLazyColumnKt {
public static final fun SelectableLazyColumn (Landroidx/compose/ui/Modifier;Lorg/jetbrains/jewel/foundation/lazy/SelectionMode;Lorg/jetbrains/jewel/foundation/lazy/SelectableLazyListState;Landroidx/compose/foundation/layout/PaddingValues;ZLkotlin/jvm/functions/Function1;Landroidx/compose/foundation/layout/Arrangement$Vertical;Landroidx/compose/ui/Alignment$Horizontal;Landroidx/compose/foundation/gestures/FlingBehavior;Lorg/jetbrains/jewel/foundation/lazy/tree/KeyActions;Lorg/jetbrains/jewel/foundation/lazy/tree/PointerEventActions;Landroidx/compose/foundation/interaction/MutableInteractionSource;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;III)V
}

public abstract interface class org/jetbrains/jewel/foundation/lazy/SelectableLazyItemScope : androidx/compose/foundation/lazy/LazyItemScope {
public abstract fun isActive ()Z
public abstract fun isSelected ()Z
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import org.jetbrains.jewel.foundation.lazy.tree.PointerEventActions

/** A composable that displays a scrollable and selectable list of items in a column arrangement. */
@Composable
public fun SelectableLazyColumn(
public fun BasicSelectableLazyColumn(
modifier: Modifier = Modifier,
selectionMode: SelectionMode = SelectionMode.Multiple,
state: SelectableLazyListState = rememberSelectableLazyListState(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
import org.jetbrains.jewel.foundation.lazy.SelectableLazyColumn
import org.jetbrains.jewel.foundation.lazy.BasicSelectableLazyColumn
import org.jetbrains.jewel.foundation.lazy.SelectableLazyItemScope
import org.jetbrains.jewel.foundation.lazy.SelectionMode
import org.jetbrains.jewel.foundation.lazy.itemsIndexed
Expand Down Expand Up @@ -109,7 +109,7 @@ public fun <T> BasicLazyTree(
)
}

SelectableLazyColumn(
BasicSelectableLazyColumn(
modifier = modifier,
state = treeState.delegate,
selectionMode = selectionMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal class SelectableLazyColumnTest {
val scrollState = SelectableLazyListState(LazyListState())
composeRule.setContent {
Box(modifier = Modifier.requiredHeight(100.dp)) {
SelectableLazyColumn(state = scrollState) {
BasicSelectableLazyColumn(state = scrollState) {
items(items1.size, key = { items1[it] }) {
val itemText = "Item ${items1[it]}"
BasicText(itemText, modifier = Modifier.testTag(itemText))
Expand All @@ -59,7 +59,7 @@ internal class SelectableLazyColumnTest {
val state = SelectableLazyListState(LazyListState())
composeRule.setContent {
Box(modifier = Modifier.requiredHeight(300.dp)) {
SelectableLazyColumn(state = state, modifier = Modifier.testTag("list")) {
BasicSelectableLazyColumn(state = state, modifier = Modifier.testTag("list")) {
items(items.size, key = { items[it] }) {
val itemText = "Item ${items[it]}"
BasicText(itemText, modifier = Modifier.testTag(itemText))
Expand Down Expand Up @@ -115,7 +115,7 @@ internal class SelectableLazyColumnTest {
val state = SelectableLazyListState(LazyListState())
composeRule.setContent {
Box(modifier = Modifier.requiredHeight(300.dp)) {
SelectableLazyColumn(state = state, modifier = Modifier.testTag("list")) {
BasicSelectableLazyColumn(state = state, modifier = Modifier.testTag("list")) {
items(items.size, key = { items[it] }) {
val itemText = "Item ${items[it]}"
BasicText(itemText, modifier = Modifier.testTag(itemText))
Expand Down Expand Up @@ -179,7 +179,7 @@ internal class SelectableLazyColumnTest {
val state = SelectableLazyListState(LazyListState())
composeRule.setContent {
Box(modifier = Modifier.requiredHeight(300.dp)) {
SelectableLazyColumn(state = state, modifier = Modifier.testTag("list")) {
BasicSelectableLazyColumn(state = state, modifier = Modifier.testTag("list")) {
items(items.size, key = { items[it] }) {
val itemText = "Item ${items[it]}"
BasicText(itemText, modifier = Modifier.testTag(itemText))
Expand Down Expand Up @@ -226,7 +226,7 @@ internal class SelectableLazyColumnTest {
composeRule.setContent {
Box(modifier = Modifier.requiredHeight(300.dp)) {
val items = currentItems.value
SelectableLazyColumn(state = state, modifier = Modifier.testTag("list")) {
BasicSelectableLazyColumn(state = state, modifier = Modifier.testTag("list")) {
items(items.size, key = { items[it] }) {
val itemText = "Item ${items[it]}"
BasicText(itemText, modifier = Modifier.testTag(itemText))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ import org.jetbrains.jewel.bridge.medium
import org.jetbrains.jewel.bridge.regular
import org.jetbrains.jewel.bridge.retrieveColorOrUnspecified
import org.jetbrains.jewel.bridge.toComposeColor
import org.jetbrains.jewel.foundation.lazy.SelectableLazyColumn
import org.jetbrains.jewel.foundation.lazy.SelectionMode
import org.jetbrains.jewel.foundation.lazy.items
import org.jetbrains.jewel.foundation.lazy.rememberSelectableLazyListState
Expand All @@ -79,6 +78,7 @@ import org.jetbrains.jewel.ui.component.HorizontalSplitLayout
import org.jetbrains.jewel.ui.component.Icon
import org.jetbrains.jewel.ui.component.IconButton
import org.jetbrains.jewel.ui.component.PopupMenu
import org.jetbrains.jewel.ui.component.SelectableLazyColumn
import org.jetbrains.jewel.ui.component.Text
import org.jetbrains.jewel.ui.component.TextField
import org.jetbrains.jewel.ui.component.Typography
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import androidx.compose.ui.unit.dp
import kotlin.random.Random
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.jetbrains.jewel.foundation.lazy.SelectableLazyColumn
import org.jetbrains.jewel.foundation.lazy.SelectionMode
import org.jetbrains.jewel.foundation.lazy.rememberSelectableLazyListState
import org.jetbrains.jewel.foundation.lazy.tree.buildTree
Expand All @@ -41,6 +40,7 @@ import org.jetbrains.jewel.ui.component.GroupHeader
import org.jetbrains.jewel.ui.component.LazyTree
import org.jetbrains.jewel.ui.component.OutlinedButton
import org.jetbrains.jewel.ui.component.RadioButtonChip
import org.jetbrains.jewel.ui.component.SelectableLazyColumn
import org.jetbrains.jewel.ui.component.Text
import org.jetbrains.jewel.ui.component.ToggleableChip
import org.jetbrains.jewel.ui.theme.colorPalette
Expand Down
4 changes: 4 additions & 0 deletions ui/api/ui.api
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,10 @@ public final class org/jetbrains/jewel/ui/component/SelectableIconButtonState$Co
public static synthetic fun of-z9lnavA$default (Lorg/jetbrains/jewel/ui/component/SelectableIconButtonState$Companion;ZZZZZZILjava/lang/Object;)J
}

public final class org/jetbrains/jewel/ui/component/SelectableLazyColumnKt {
public static final fun SelectableLazyColumn (Landroidx/compose/ui/Modifier;Lorg/jetbrains/jewel/foundation/lazy/SelectionMode;Lorg/jetbrains/jewel/foundation/lazy/SelectableLazyListState;Landroidx/compose/foundation/layout/PaddingValues;ZLkotlin/jvm/functions/Function1;Landroidx/compose/foundation/layout/Arrangement$Vertical;Landroidx/compose/ui/Alignment$Horizontal;Landroidx/compose/foundation/gestures/FlingBehavior;Lorg/jetbrains/jewel/foundation/lazy/tree/KeyActions;Lorg/jetbrains/jewel/foundation/lazy/tree/PointerEventActions;Landroidx/compose/foundation/interaction/MutableInteractionSource;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;III)V
}

public final class org/jetbrains/jewel/ui/component/SliderKt {
public static final fun Slider (FLkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;ZLkotlin/ranges/ClosedFloatingPointRange;ILkotlin/jvm/functions/Function0;Landroidx/compose/foundation/interaction/MutableInteractionSource;Lorg/jetbrains/jewel/ui/component/styling/SliderStyle;Landroidx/compose/runtime/Composer;II)V
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.jetbrains.jewel.ui.component

import androidx.compose.foundation.gestures.FlingBehavior
import androidx.compose.foundation.gestures.ScrollableDefaults
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import org.jetbrains.jewel.foundation.lazy.BasicSelectableLazyColumn
import org.jetbrains.jewel.foundation.lazy.SelectableLazyListScope
import org.jetbrains.jewel.foundation.lazy.SelectableLazyListState
import org.jetbrains.jewel.foundation.lazy.SelectionMode
import org.jetbrains.jewel.foundation.lazy.rememberSelectableLazyListState
import org.jetbrains.jewel.foundation.lazy.tree.DefaultSelectableLazyColumnEventAction
import org.jetbrains.jewel.foundation.lazy.tree.DefaultSelectableLazyColumnKeyActions
import org.jetbrains.jewel.foundation.lazy.tree.KeyActions
import org.jetbrains.jewel.foundation.lazy.tree.PointerEventActions

@Composable
public fun SelectableLazyColumn(
modifier: Modifier = Modifier,
selectionMode: SelectionMode = SelectionMode.Multiple,
state: SelectableLazyListState = rememberSelectableLazyListState(),
contentPadding: PaddingValues = PaddingValues(0.dp),
reverseLayout: Boolean = false,
onSelectedIndexesChanged: (List<Int>) -> Unit = {},
verticalArrangement: Arrangement.Vertical = if (!reverseLayout) Arrangement.Top else Arrangement.Bottom,
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(),
keyActions: KeyActions = DefaultSelectableLazyColumnKeyActions,
pointerEventActions: PointerEventActions = DefaultSelectableLazyColumnEventAction(),
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
// TODO: We will add support for styling in the near future
content: SelectableLazyListScope.() -> Unit,
) {
BasicSelectableLazyColumn(
modifier = modifier,
selectionMode = selectionMode,
state = state,
contentPadding = contentPadding,
reverseLayout = reverseLayout,
onSelectedIndexesChanged = onSelectedIndexesChanged,
verticalArrangement = verticalArrangement,
horizontalAlignment = horizontalAlignment,
flingBehavior = flingBehavior,
keyActions = keyActions,
pointerEventActions = pointerEventActions,
interactionSource = interactionSource,
content = content,
)
}