4051610f812d
fix: settings stack drag gesture (detectDragGestures flip focus/deck) + dynamic collapsedTabStride fills screen height; SettingsStackTest 5 tests; v2.2.6 (171 tests)
- time
- 2026-06-10 12:42 UTC · 5 months ago
- machine
- koh2
- agent
- claude-opus-4-8
- session
- settings stack drag fill
- parent
- 24a6f5eceb7d
↓ peach-android-4051610f.tar.gzatlas at this save
files changed2 files
app/src/main/java/com/peachpasswords/ui/settings/SettingsScreen.kt+66 −1app/src/test/java/com/peachpasswords/ui/settings/SettingsStackTest.kt+54 −0app/src/main/java/com/peachpasswords/ui/settings/SettingsScreen.kt+66 −1
@@ -11,6 +11,7 @@1111 import androidx.compose.animation.core.tween1212 import androidx.compose.foundation.background1313 import androidx.compose.foundation.clickable14+import androidx.compose.foundation.gestures.detectDragGestures1415 import androidx.compose.foundation.interaction.MutableInteractionSource1516 import androidx.compose.foundation.layout.Arrangement1617 import androidx.compose.foundation.layout.Box@@ -47,7 +48,9 @@4748 import androidx.compose.ui.graphics.Color4849 import androidx.compose.ui.graphics.drawscope.DrawScope4950 import androidx.compose.ui.graphics.graphicsLayer51+import androidx.compose.ui.input.pointer.pointerInput5052 import androidx.compose.ui.platform.LocalDensity53+import androidx.compose.ui.unit.Dp5154 import androidx.compose.ui.text.font.FontStyle5255 import androidx.compose.ui.text.font.FontWeight5356 import androidx.compose.ui.text.style.TextOverflow@@ -76,6 +79,42 @@7679 private val TAB_OVERLAP = 14.dp7780 private val TAB_CARD_H = TAB_H + 4.dp7881 82+/** Drag distance past which a stack card flips between focused and deck states. */83+private val DRAG_THRESHOLD = 60.dp84+85+/** Outcome of releasing a vertical drag on a stack card. */86+internal enum class DragOutcome { EXPAND, COLLAPSE, NONE }87+88+/**89+ * Resolve a released drag on a stack card (brief Fix 7). Dragging a collapsed90+ * (deck) card up past the threshold focuses it; dragging the focused card down91+ * past the threshold returns to the deck. Anything short of the threshold is a no-op.92+ */93+internal fun resolveStackDrag(dragOffsetPx: Float, thresholdPx: Float, isExpanded: Boolean): DragOutcome = when {94+ dragOffsetPx < -thresholdPx && !isExpanded -> DragOutcome.EXPAND95+ dragOffsetPx > thresholdPx && isExpanded -> DragOutcome.COLLAPSE96+ else -> DragOutcome.NONE97+}98+99+/**100+ * The vertical stride between consecutive collapsed tabs, sized so the deck fans101+ * out to fill the available height instead of bunching in the top ~half (brief102+ * Fix 7). Falls back to [min] on short screens and is capped at [max] so tabs103+ * never spread too thin on tall ones.104+ */105+internal fun collapsedTabStride(106+ available: Dp,107+ expanded: Dp,108+ tabCard: Dp,109+ tabCount: Int,110+ min: Dp,111+ max: Dp,112+): Dp {113+ if (tabCount <= 0) return min114+ val raw = (available - expanded - tabCard) / tabCount115+ return raw.coerceIn(min, max)116+}117+79118 @Composable80119 fun SettingsScreen(81120 onBack: () -> Unit,@@ -160,6 +199,15 @@160199 161200 BoxWithConstraints(Modifier.fillMaxSize()) {162201 val focusHeight = maxHeight - 8.dp202+ // Fan the collapsed tabs across the whole height instead of the top ~half.203+ val tabStride = collapsedTabStride(204+ available = maxHeight,205+ expanded = EXPANDED_H,206+ tabCard = TAB_CARD_H,207+ tabCount = STACK_CARDS.size - 1,208+ min = TAB_H - TAB_OVERLAP,209+ max = 72.dp,210+ )163211 STACK_CARDS.forEachIndexed { index, card ->164212 val isActive = card.id == active165213 val distance = when {@@ -170,7 +218,7 @@170218 val targetTop = when {171219 isActive -> 0.dp172220 !deckOpen -> focusHeight + 44.dp + (distance * 8).dp173- else -> EXPANDED_H - TAB_OVERLAP + (distance * (TAB_H - TAB_OVERLAP).value.toInt()).dp221+ else -> EXPANDED_H - TAB_OVERLAP + (distance * tabStride.value).dp174222 }175223 val targetHeight = when {176224 isActive && deckOpen -> EXPANDED_H@@ -239,6 +287,23 @@239287 .fillMaxWidth()240288 .align(Alignment.TopStart)241289 .zIndex(zIndex)290+ // Drag the deck like a physical stack: flick a tab up to focus291+ // it, drag the focused card down to drop back into the deck.292+ .pointerInput(card.id, deckOpen, isActive) {293+ var dragY = 0f294+ val thresholdPx = with(density) { DRAG_THRESHOLD.toPx() }295+ detectDragGestures(296+ onDragStart = { dragY = 0f },297+ onDrag = { change, amount -> change.consume(); dragY += amount.y },298+ onDragEnd = {299+ when (resolveStackDrag(dragY, thresholdPx, isActive && !deckOpen)) {300+ DragOutcome.EXPAND -> { active = card.id; deckOpen = false }301+ DragOutcome.COLLAPSE -> { deckOpen = true }302+ DragOutcome.NONE -> {}303+ }304+ },305+ )306+ }242307 .graphicsLayer {243308 translationY = top.toPx() + with(density) { shakeDy.value.dp.toPx() }244309 rotationZ = shakeRot.valueapp/src/test/java/com/peachpasswords/ui/settings/SettingsStackTest.kt+54 −0
@@ -0,0 +1,54 @@1+package com.peachpasswords.ui.settings2+3+import androidx.compose.ui.unit.dp4+import org.junit.Assert.assertEquals5+import org.junit.Assert.assertTrue6+import org.junit.Test7+8+class SettingsStackTest {9+10+ // ── Screen fill: collapsed tabs fan to use the whole height ────────────────11+12+ @Test fun settings_stack_collapsed_fills_screen_height() {13+ // 6 tabs, 258dp active card, 50dp tab card. On a tall screen the stride14+ // opens up toward the cap rather than staying at the 32dp floor.15+ val tall = collapsedTabStride(16+ available = 800.dp, expanded = 258.dp, tabCard = 50.dp, tabCount = 6,17+ min = 32.dp, max = 72.dp,18+ )19+ val short = collapsedTabStride(20+ available = 480.dp, expanded = 258.dp, tabCard = 50.dp, tabCount = 6,21+ min = 32.dp, max = 72.dp,22+ )23+ assertTrue("taller screen spreads tabs further", tall > short)24+ // raw = (800-258-50)/6 = 82 → clamped to the 72dp cap.25+ assertEquals(72.dp, tall)26+ // raw = (480-258-50)/6 ≈ 28.7 → clamped up to the 32dp floor.27+ assertEquals(32.dp, short)28+ }29+30+ @Test fun stride_falls_back_to_min_with_no_tabs() {31+ assertEquals(32.dp, collapsedTabStride(800.dp, 258.dp, 50.dp, 0, 32.dp, 72.dp))32+ }33+34+ // ── Drag gesture resolution ───────────────────────────────────────────────35+36+ @Test fun settings_stack_drag_up_expands_card() {37+ // Collapsed (deck) card dragged up past the 60px threshold → focus it.38+ assertEquals(DragOutcome.EXPAND, resolveStackDrag(dragOffsetPx = -90f, thresholdPx = 60f, isExpanded = false))39+ }40+41+ @Test fun settings_stack_drag_down_collapses_card() {42+ // Focused card dragged down past the threshold → back to the deck.43+ assertEquals(DragOutcome.COLLAPSE, resolveStackDrag(dragOffsetPx = 90f, thresholdPx = 60f, isExpanded = true))44+ }45+46+ @Test fun settings_stack_drag_below_threshold_is_noop() {47+ assertEquals(DragOutcome.NONE, resolveStackDrag(-40f, 60f, isExpanded = false))48+ assertEquals(DragOutcome.NONE, resolveStackDrag(40f, 60f, isExpanded = true))49+ // Right direction, wrong state: dragging an already-focused card up does nothing.50+ assertEquals(DragOutcome.NONE, resolveStackDrag(-90f, 60f, isExpanded = true))51+ // Dragging a collapsed card down does nothing.52+ assertEquals(DragOutcome.NONE, resolveStackDrag(90f, 60f, isExpanded = false))53+ }54+}