From 57bc5096f31a89308179a32d8ac7c277394b0ee4 Mon Sep 17 00:00:00 2001 From: Saad Nadeem Date: Tue, 18 Aug 2026 15:19:43 -0400 Subject: [PATCH] fix(ui): prevent draggable list scroll jumps --- .../ui/components/settings/DraggableListOption.kt | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/internal/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/components/settings/DraggableListOption.kt b/modules/internal/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/components/settings/DraggableListOption.kt index 26dbc7290..965d1d539 100644 --- a/modules/internal/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/components/settings/DraggableListOption.kt +++ b/modules/internal/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/components/settings/DraggableListOption.kt @@ -32,7 +32,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.input.pointer.PointerIcon import androidx.compose.ui.input.pointer.pointerHoverIcon -import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.IntOffset @@ -53,6 +52,9 @@ import kotlin.math.roundToInt private val ListContainerShape @Composable get() = LocalTheme.current.sideBarNavigationEntryShape private val ListItemShape @Composable get() = LocalTheme.current.sideBarNavigationEntryShape +private val PlainListItemHeight = 32.dp +private val CheckableListItemHeight = 40.dp +private val ListItemSpacing = 14.dp @Suppress("UNCHECKED_CAST") @Composable @@ -88,17 +90,14 @@ fun DraggableListOption(data: DraggableListOptionData) { var draggingIndex by remember { mutableStateOf(-1) } var dragAccum by remember { mutableStateOf(0f) } - var itemHeightPx by remember { mutableStateOf(40) } - val spacingPx = with(density) { 14.dp.roundToPx() } - val stridePx = (itemHeightPx + spacingPx).toFloat() + val itemHeight = if (data.checkable) CheckableListItemHeight else PlainListItemHeight + val stridePx = with(density) { (itemHeight + ListItemSpacing).toPx() } val dragTargetIndex = if (draggingIndex == -1) { -1 } else { (draggingIndex + (dragAccum / stridePx).roundToInt()).coerceIn(0, items.lastIndex) } - val contentHeight = with(density) { - (itemHeightPx * items.size + spacingPx * (items.size - 1).coerceAtLeast(0)).toDp() - } + val contentHeight = itemHeight * items.size + ListItemSpacing * (items.size - 1).coerceAtLeast(0) fun save(list: List = items) { val toSave = if (data.checkable) list.filter { it.id in enabledIds } else list @@ -168,7 +167,7 @@ fun DraggableListOption(data: DraggableListOptionData) { modifier = Modifier .fillMaxWidth() .offset { IntOffset(0, visualOffset.roundToInt()) } - .onSizeChanged { if (index == 0) itemHeightPx = it.height } + .height(itemHeight) .zIndex(if (isDragging) 1f else 0f) .clip(ListItemShape) .background(bgColor, ListItemShape)