components: ReorderableColumn row height parameter

This commit is contained in:
2026-09-23 16:51:55 +02:00
parent 103a37cb28
commit d5f5ad7b9d
@@ -31,7 +31,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlin.math.roundToInt
/** Uniform row height for [ReorderableColumn]; a fixed pitch keeps drag maths exact. */
/** Default uniform row height for [ReorderableColumn]; a fixed pitch keeps drag maths exact. */
val ReorderableRowHeight: Dp = 64.dp
private val RowGap: Dp = 2.dp
@@ -41,7 +41,7 @@ private val RowGap: Dp = 2.dp
* Built for the short, fixed grouped-card lists in Settings — no external
* dependency and no [androidx.compose.foundation.lazy.LazyColumn] (the settings
* screens are a single [androidx.compose.foundation.verticalScroll] column, which
* can't nest a scrolling list). Rows are a fixed [ReorderableRowHeight] with a
* can't nest a scrolling list). Rows are a fixed [rowHeight] with a
* uniform gap, so a row's target slot is simply how many whole pitches it has
* been dragged. The held row follows the finger while the others slide out of
* its way (animated); on release the order is committed immediately with a
@@ -52,6 +52,8 @@ private val RowGap: Dp = 2.dp
* [rowContent] receives the [Position] for the row's place in the order (to reuse
* [GroupedRow]'s card shaping — pass `gapBelow = false` there, this owns spacing)
* and a `dragHandle` [Modifier] to attach to the element that starts a drag.
* Pass [rowHeight] matching the rows' non-reorder `minHeight`, so they keep their
* size when a screen switches into reordering.
*/
@Composable
fun <T> ReorderableColumn(
@@ -59,9 +61,10 @@ fun <T> ReorderableColumn(
keyOf: (T) -> Any,
onReorder: (List<T>) -> Unit,
modifier: Modifier = Modifier,
rowHeight: Dp = ReorderableRowHeight,
rowContent: @Composable (item: T, position: Position, dragHandle: Modifier, isDragging: Boolean) -> Unit,
) {
val pitchPx = with(LocalDensity.current) { (ReorderableRowHeight + RowGap).toPx() }
val pitchPx = with(LocalDensity.current) { (rowHeight + RowGap).toPx() }
val scope = rememberCoroutineScope()
// Local working copy; re-seeded when the incoming list changes (including the
@@ -163,7 +166,7 @@ fun <T> ReorderableColumn(
Box(
Modifier
.height(ReorderableRowHeight)
.height(rowHeight)
.zIndex(if (isDragged) 1f else 0f)
.graphicsLayer {
translationY = if (isDragged) dragOffset else animatedShift