contacts: exclude FAB zone from section scroller scale
- Commit
4675633c6e9fd8c2b36bfe8171b3b9306c921452- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-02 02:57 UTC (4 days ago)
- Parents
4c14d75
The contact list's fast-scroll pill could not drag the list all the way to its end. The pill's travel was derived from the grab strip's height measured up from the raw track bottom with a flat 88dp allowance, but the scaffold floats the FAB above the navigation-bar inset, so the FAB's top edge sits at inset + 72dp from the bottom. With a navigation inset larger than ~16dp (3-button nav, gesture bar), the lowest stretch of the pill's range slid behind the FAB: the pill disappeared under it and touches starting there were consumed by the FAB, leaving the end of the scale ungrabbable. The scale also mixed two bottom references (padded strip height and the list's afterContentPadding) instead of one explicit limit. Fix: measure the full track height once and compute a single FAB-zone height - the navigation-bars/IME bottom inset the FAB floats above plus FAB height, margin, and gap (88dp, 72dp on compact-height tracks) - that drives both the grab strip's bottom padding (where a drag can start) and the pill's travel scale via the pure helpers fabZoneHeightPx, scrollerBottomLimitPx, scrollerTravelPx, and scrollerThumbOffsetPx. At progress 1 the pill's bottom sits exactly on the FAB-excluded limit and the list is at its true end; the pill never enters the FAB zone. The scroll-fraction mapping (progressOf/scrollTargetFor) is unchanged. Verified: :contacts:lint, :contacts:lintVitalRelease green; new ContactSectionScrollerTest pins FAB-zone exclusion, both scale extremes, linearity/clamping, full-travel drag reachability, and degenerate tracks; existing ScrollerMathPass2Test still passes. Full :contacts:testDevUnitTest: 595/599 pass - the 2 deterministic failures (insertOrEdit intent tests) fail identically on pristine HEAD and 2 others are flakes that pass on re-run.
Diff
contacts/AGENTS.md
diff --git a/contacts/AGENTS.md b/contacts/AGENTS.mdindex 864ab0d129..5a60f8e9f1 100644--- a/contacts/AGENTS.md+++ b/contacts/AGENTS.md@@ -46,6 +46,7 @@ _Install: ./install contacts (dev by default)._ ### ui/ + ui/dialogs/ — list/detail/edit/import - com/vayunmathur/contacts/ui/ContactListScreen.kt - com/vayunmathur/contacts/ui/ContactList.kt+- com/vayunmathur/contacts/ui/ContactSectionScroller.kt — list fast-scroll pill; its travel and drag scale exclude the FAB zone (bottom window inset + FAB clearance), so the scale's end is the true list end and stays grabbable - com/vayunmathur/contacts/ui/ContactItem.kt - com/vayunmathur/contacts/ui/ContactListPick.kt - com/vayunmathur/contacts/ui/ContactItemPick.kt
contacts/src/main/java/com/vayunmathur/contacts/ui/ContactSectionScroller.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactSectionScroller.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactSectionScroller.ktindex 636501ffb3..c68ed2a886 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactSectionScroller.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactSectionScroller.kt@@ -3,11 +3,15 @@ package com.vayunmathur.contacts.ui import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.gestures.detectVerticalDragGestures import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.ime+import androidx.compose.foundation.layout.navigationBars import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.union import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyListState import androidx.compose.runtime.Composable@@ -24,6 +28,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.layout.onSizeChanged+import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp import com.vayunmathur.library.ui.IconStar@@ -51,6 +56,13 @@ import kotlin.math.roundToInt * This must be hosted in [com.vayunmathur.library.ui.LazyListScaffold]'s `overlay` slot (a box * exactly the list's size), so the pill travels only along the actual list - hosted full-screen * it would run up behind the app bar and down behind the navigation bar.+ *+ * The bottom of the pill's travel excludes the FAB zone: the scaffold floats the FAB above+ * the navigation-bar/IME inset, so the zone's height is that inset plus the FAB's height,+ * its margin, and a gap. One FAB-zone height drives both the grab strip's bottom padding+ * (where a drag can start) and the thumb-offset scale (where the pill can sit), so the end+ * of the scale is always grabbable and the pill never slides behind the FAB; dragging the+ * pill through its full travel reaches the true end of the list. */ @Composable internal fun ContactSectionScroller(@@ -71,39 +83,48 @@ internal fun ContactSectionScroller( var scrollJob by remember { mutableStateOf<Job?>(null) } val keys = sectionIndex.keys.toList()+ // Short (landscape) tracks shrink the pill and clear less space above the FAB,+ // so the pill's travel stays usable when the viewport is only ~300dp tall.+ val shortTrack = isCompactHeight()+ val density = LocalDensity.current+ // The FAB floats above the navigation-bar/IME inset (the same insets the scaffold+ // unions for its slots), so the FAB zone is measured from that inset, not from the+ // raw track bottom: FAB height + its bottom margin + a gap above the inset.+ val bottomWindowInsetPx = WindowInsets.navigationBars.union(WindowInsets.ime).getBottom(density)+ val fabClearancePx = with(density) { (if (shortTrack) 72.dp else 88.dp).roundToPx() }+ val fabZoneHeightPx = fabZoneHeightPx(bottomWindowInsetPx, fabClearancePx) // The overlay box is the full scaffold content size, including the area behind the app bar and // the navigation bar (the list draws under both and insets its *content* instead). Bound the- // pill's travel to the list's actual viewport - between the top/bottom content padding - so it- // runs only along the side of the visible list.+ // pill's travel to the list's actual viewport - between the top/bottom content padding - and+ // to the FAB zone, whichever ends higher, so it runs only along the visible list and never+ // behind the FAB. val topInsetPx by remember { derivedStateOf { state.layoutInfo.beforeContentPadding } } val bottomInsetPx by remember { derivedStateOf { state.layoutInfo.afterContentPadding } }- val listViewportPx = (trackHeightPx - topInsetPx - bottomInsetPx).coerceAtLeast(1)- val travelPx = (listViewportPx - thumbHeightPx).coerceAtLeast(1).toFloat()- val latestTravelPx = rememberUpdatedState(travelPx)+ val bottomLimitPx = scrollerBottomLimitPx(trackHeightPx, bottomInsetPx, fabZoneHeightPx)+ val travelPx = scrollerTravelPx(bottomLimitPx, topInsetPx, thumbHeightPx).toFloat()+ val latestTravelPx = rememberUpdatedState(travelPx.coerceAtLeast(1f)) val progress = if (dragging) dragProgress else progressOf(state, itemCount)- val thumbOffsetPx = topInsetPx + progress * travelPx+ val thumbOffsetPx = scrollerThumbOffsetPx(progress, topInsetPx, travelPx.roundToInt()) val currentKey = keys.lastOrNull { sectionIndex[it]!! <= state.firstVisibleItemIndex } ?: keys.first() Box(- modifier.fillMaxSize(),+ modifier+ .fillMaxSize()+ .onSizeChanged { trackHeightPx = it.height }, ) { // Full-height grab strip on the right edge: starting a vertical drag anywhere in it // scrubs the list, so a finger that drifts off the small pill mid-drag no longer falls // through to the list itself and stalls the scrub. Horizontal gestures pass through to // the list untouched - only vertical drags are claimed. //- // Short (landscape) tracks shrink the pill and clear less space above the FAB,- // so the pill's travel stays usable when the viewport is only ~300dp tall.- val shortTrack = isCompactHeight()+ // The strip ends at the same FAB-zone limit the thumb scale uses (its bottom padding+ // is the FAB-zone height), so the grabbable area and the pill's travel always agree. Box( Modifier .align(Alignment.TopEnd) .fillMaxHeight() .width(if (shortTrack) 48.dp else 64.dp)- // End the grab strip above the FAB (56dp button + 16dp margin + room), and- // measure the track here so the pill's travel ends there too.- .padding(bottom = if (shortTrack) 72.dp else 88.dp)- .onSizeChanged { trackHeightPx = it.height }+ .padding(bottom = with(density) { fabZoneHeightPx.toDp() }) // Stable keys: the travel distance is read through updated state, so a // recomposition mid-drag never restarts the detector and drops the gesture. .pointerInput(itemCount) {@@ -131,7 +152,7 @@ internal fun ContactSectionScroller( border = BorderStroke(1.dp, MaterialTheme.colorScheme.primary), modifier = Modifier .align(Alignment.TopEnd)- .offset { IntOffset(0, thumbOffsetPx.roundToInt()) }+ .offset { IntOffset(0, thumbOffsetPx) } .padding(end = 8.dp) .onSizeChanged { thumbHeightPx = it.height }, ) {@@ -158,6 +179,46 @@ internal fun ContactSectionScroller( /** Favorites section key for the [ContactSectionScroller]. */ internal const val FAVORITES_KEY = "favorites" +/**+ * Height of the FAB zone at the bottom of the track: the bottom window inset the FAB+ * floats above ([bottomWindowInsetPx], navigation bars union IME) plus the clearance+ * above that inset ([clearanceAboveInsetPx]: FAB height + bottom margin + gap). The+ * pill and any drag starting on it must stay above this zone.+ */+internal fun fabZoneHeightPx(+ bottomWindowInsetPx: Int,+ clearanceAboveInsetPx: Int,+): Int = (bottomWindowInsetPx + clearanceAboveInsetPx).coerceAtLeast(0)++/**+ * Lowest y (in track coordinates) the pill's bottom edge may reach: the higher of the+ * list's bottom content inset and the FAB zone, measured up from the track bottom.+ */+internal fun scrollerBottomLimitPx(+ trackHeightPx: Int,+ afterContentPaddingPx: Int,+ fabZoneHeightPx: Int,+): Int = (trackHeightPx - maxOf(afterContentPaddingPx, fabZoneHeightPx)).coerceAtLeast(0)++/**+ * Distance the pill's top edge travels between scroll progress 0 and 1: from the top+ * content inset to [scrollerBottomLimitPx] minus the pill's own height, so at progress+ * 1 the pill's bottom sits exactly on the FAB-excluded limit and the list is at its+ * true end.+ */+internal fun scrollerTravelPx(+ bottomLimitPx: Int,+ topInsetPx: Int,+ thumbHeightPx: Int,+): Int = (bottomLimitPx - topInsetPx - thumbHeightPx).coerceAtLeast(0)++/** Pill top-edge offset for a scroll [progress] within its FAB-excluded travel. */+internal fun scrollerThumbOffsetPx(+ progress: Float,+ topInsetPx: Int,+ travelPx: Int,+): Int = topInsetPx + (progress.coerceIn(0f, 1f) * travelPx).roundToInt()+ /** * Scroll fraction 0 (top) to 1 (last item bottom at the viewport bottom): * scrolled pixels over the true scrollable distance, so the pill hits the
contacts/src/test/java/com/vayunmathur/contacts/ui/ContactSectionScrollerTest.kt
diff --git a/contacts/src/test/java/com/vayunmathur/contacts/ui/ContactSectionScrollerTest.kt b/contacts/src/test/java/com/vayunmathur/contacts/ui/ContactSectionScrollerTest.ktnew file mode 100644index 0000000000..0ea603e6fa--- /dev/null+++ b/contacts/src/test/java/com/vayunmathur/contacts/ui/ContactSectionScrollerTest.kt@@ -0,0 +1,90 @@+package com.vayunmathur.contacts.ui++import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/**+ * FAB-excluded scale of the contact list section scroller. The numbers model a phone+ * track: 2000px tall, 100px top content inset, 48dp-class pill (140px at this density),+ * 88dp-class FAB clearance (260px) above a 140px bottom window inset (3-button nav).+ */+class ContactSectionScrollerTest {+ private val trackHeight = 2000+ private val topInset = 100+ private val thumbHeight = 140+ private val windowInset = 140+ private val clearance = 260++ private val fabZone = fabZoneHeightPx(windowInset, clearance) // 400+ private val bottomLimit = scrollerBottomLimitPx(trackHeight, 0, fabZone) // 1600+ private val travel = scrollerTravelPx(bottomLimit, topInset, thumbHeight) // 1360++ @Test+ fun fabZoneStacksWindowInsetAndClearance() {+ assertEquals(400, fabZoneHeightPx(windowInset, clearance))+ assertEquals(clearance, fabZoneHeightPx(0, clearance))+ assertEquals(0, fabZoneHeightPx(0, 0))+ assertEquals(0, fabZoneHeightPx(-10, -5))+ }++ @Test+ fun bottomLimitHonoursHigherOfListInsetAndFabZone() {+ // FAB zone higher than the list's own bottom content inset: FAB wins.+ assertEquals(1600, scrollerBottomLimitPx(trackHeight, 0, fabZone))+ assertEquals(1600, scrollerBottomLimitPx(trackHeight, 200, fabZone))+ // A taller bottom inset (e.g. a bottom bar) wins over the FAB zone.+ assertEquals(trackHeight - 500, scrollerBottomLimitPx(trackHeight, 500, fabZone))+ // Degenerate track never goes negative.+ assertEquals(0, scrollerBottomLimitPx(300, 0, fabZone))+ }++ @Test+ fun thumbAtExtremesStaysOutOfFabZone() {+ // Top of the scale: pill top on the top content inset.+ assertEquals(topInset, scrollerThumbOffsetPx(0f, topInset, travel))+ // End of the scale: pill bottom exactly on the FAB-excluded bottom limit,+ // i.e. a full FAB zone away from the track bottom.+ val endOffset = scrollerThumbOffsetPx(1f, topInset, travel)+ assertEquals(bottomLimit - thumbHeight, endOffset)+ assertEquals(fabZone, trackHeight - (endOffset + thumbHeight))+ // And the plain list-end limit without any FAB (zone smaller than inset) is kept.+ val noFabLimit = scrollerBottomLimitPx(trackHeight, 0, 0)+ assertEquals(+ noFabLimit - thumbHeight,+ scrollerThumbOffsetPx(1f, topInset, scrollerTravelPx(noFabLimit, topInset, thumbHeight)),+ )+ }++ @Test+ fun thumbMappingIsLinearAndClamped() {+ assertEquals(topInset + travel / 2, scrollerThumbOffsetPx(0.5f, topInset, travel))+ assertTrue(scrollerThumbOffsetPx(0.25f, topInset, travel) < scrollerThumbOffsetPx(0.75f, topInset, travel))+ // Out-of-range progress clamps to the same extremes instead of leaving the track.+ assertEquals(scrollerThumbOffsetPx(0f, topInset, travel), scrollerThumbOffsetPx(-1f, topInset, travel))+ assertEquals(scrollerThumbOffsetPx(1f, topInset, travel), scrollerThumbOffsetPx(2f, topInset, travel))+ }++ @Test+ fun fullTravelDragReachesTrueListEnd() {+ // One full-travel drag moves progress 0 -> 1 exactly; half travel lands mid-scale+ // on the same offset the pill shows there, so finger and pill never disagree.+ assertTrue(travel > 0)+ val draggedProgress = (0f + travel / travel.toFloat()).coerceIn(0f, 1f)+ assertEquals(1f, draggedProgress)+ assertEquals(+ scrollerThumbOffsetPx(0.5f, topInset, travel),+ topInset + (draggedProgress / 2 * travel).toInt(),+ )+ assertEquals(travel, scrollerThumbOffsetPx(1f, topInset, travel) - scrollerThumbOffsetPx(0f, topInset, travel))+ }++ @Test+ fun degenerateTrackHasNoTravel() {+ // Track shorter than insets + pill: no travel, pill pinned at the top inset.+ val tinyLimit = scrollerBottomLimitPx(300, 0, fabZoneHeightPx(0, clearance))+ assertEquals(0, scrollerTravelPx(tinyLimit, topInset, thumbHeight))+ assertEquals(topInset, scrollerThumbOffsetPx(1f, topInset, 0))+ assertEquals(0, scrollerTravelPx(0, 0, 0))+ }+}