findfamily: restore map panning over the bottom sheet
- Commit
30c105ca7f0ec231aa62ea4b8bfd6bd535cfc3fa- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-06 03:47 UTC (3 hours ago)
- Parents
84fdea4
The FindFamily map could not be panned at all: Material 3's BottomSheetScaffold (the wrapper in library/ui, used only by this page) consumes drag gestures over the whole content area, so CameraState.onGesture never ran. The Compose people overlay follows the camera in Compose while the native basemap re-renders only from the same camera state, so a drag that reached nothing read as "only the icons move"; in practice no drag moved the map. Host the page in the repo's own FreeHeightBottomSheetScaffold instead (the scaffold maps uses over the same map): its drag lives on the sheet itself and leaves content gestures alone. The overlay lift now reads the sheet's visible height (liftPx) against a captured peek baseline, and swapping the panel content passes a contentKey so the sheet re-probes its expansion ceiling. That swap exposed a latent race in FreeHeightSheetState: a host content swap calls resetContentCap before the first onMeasured, installing a [0, 0] Animatable bound that clamped the initial snap to the peek at zero, leaving the sheet collapsed (deterministic under Robolectric). onMeasured now widens the bound to the real expanded height before the initial snap. Regression tests: a Robolectric swipe over the map inside MainPageContent must move the camera (VectorMap alone is the control), a CameraGesturesTest case pins that a pan shifts the projection of a fixed ground point by exactly the drag delta (the single camera source both render paths read), and a FreeHeightSheetStateTest case pins the pre-measure reset race. Verified: :findfamily:testDevUnitTestNative green (incl. the previously blocked panel-tap navigation tests), :findfamily:testDevUnitTest MapPanGestureTest, :library:map CameraGesturesTest, :library:ui FreeHeightSheetStateTest.
Diff
findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageContent.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageContent.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageContent.ktindex 6e5b34129e..f5b94b6964 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageContent.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageContent.kt@@ -9,15 +9,13 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding-import com.vayunmathur.library.ui.BottomSheetDefaults-import com.vayunmathur.library.ui.BottomSheetScaffold import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.ExperimentalMaterial3ExpressiveApi+import com.vayunmathur.library.ui.FreeHeightBottomSheetScaffold import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.SheetValue import com.vayunmathur.library.ui.TopAppBarOverlay import com.vayunmathur.library.ui.dynamicLightColorScheme-import com.vayunmathur.library.ui.rememberBottomSheetScaffoldState+import com.vayunmathur.library.ui.rememberFreeHeightSheetState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.mutableFloatStateOf@@ -45,7 +43,7 @@ fun MainPageContent( personContent: @Composable () -> Unit = {}, waypointContent: @Composable () -> Unit = {}, ) {- val scaffoldState = rememberBottomSheetScaffoldState()+ val sheetState = rememberFreeHeightSheetState() // Under Layoutlib (store-listing previews) there is no frame clock or real layout pass, // so animation/offset-driven effects either no-op or hang the render. Skip them in@@ -54,8 +52,6 @@ fun MainPageContent( // Expanded windows use the side-panel layout below instead of the bottom sheet. val expanded = isExpandedWidth() && !inPreview - // The peek stays NON-ZERO: a peek of 0.dp crashes (Material3 keeps only- // the Expanded anchor while the state targets PartiallyExpanded). val peekHeight = SheetPeekHeight // The FAB sits on top of the always-light map, so color it from a light dynamic@@ -67,21 +63,16 @@ fun MainPageContent( val fabContainerColor = lightScheme.primaryContainer val fabContentColor = lightScheme.onPrimaryContainer - // The sheet's offset when settled at its peek, captured ONCE. Overlays then sit- // at their default position plus (currentSheetOffset - peekOffset), clamped <= 0,- // so they move 1:1 with the sheet. Peek is constant (128) whenever overlays show,- // so a single capture stays correct across list/detail/back-from-history.- val collapsedSheetOffset = remember { mutableFloatStateOf(Float.NaN) }+ // The sheet's visible height when settled at its peek, captured ONCE. Overlays then+ // sit at their default position minus the height the sheet has grown beyond that,+ // clamped <= 0, so they move 1:1 with the sheet. The peek is constant whenever+ // overlays show, so a single capture stays correct across list/detail.+ val collapsedSheetLift = remember { mutableFloatStateOf(Float.NaN) } if (!inPreview) {- LaunchedEffect(scaffoldState) {- snapshotFlow {- val st = scaffoldState.bottomSheetState- val settled = st.currentValue == SheetValue.PartiallyExpanded &&- st.targetValue == SheetValue.PartiallyExpanded- if (settled) runCatching { st.requireOffset() }.getOrNull() else null- }.collect { off ->- if (off != null && collapsedSheetOffset.floatValue.isNaN()) {- collapsedSheetOffset.floatValue = off+ LaunchedEffect(sheetState) {+ snapshotFlow { sheetState.liftPx }.collect { lift ->+ if (lift > 0f && collapsedSheetLift.floatValue.isNaN()) {+ collapsedSheetLift.floatValue = lift } } }@@ -125,14 +116,20 @@ fun MainPageContent( return } - BottomSheetScaffold(- scaffoldState = scaffoldState,+ // The repo's own sheet scaffold, not Material 3's BottomSheetScaffold: the+ // Material 3 scaffold's anchored-draggable sheet consumes the drag gestures+ // over the whole content area, so the map underneath never pans (the people+ // overlay, which follows the camera in Compose, still moved — the basemap+ // did not). FreeHeightBottomSheetScaffold keeps its drag on the sheet itself+ // and leaves the content's gestures alone, which is why maps uses it over+ // the same map.+ FreeHeightBottomSheetScaffold(+ state = sheetState, sheetPeekHeight = peekHeight,- sheetSwipeEnabled = true,- sheetDragHandle = { BottomSheetDefaults.DragHandle() }, sheetContainerColor = MaterialTheme.colorScheme.surfaceContainerLow,- // No top bar: the chrome floats over the map as a TopAppBarOverlay in the content- // slot below, so the map gets the whole window (GitHub #680).+ // Selection swaps the panel content; a new key makes the sheet re-probe+ // how tall the new content may grow instead of capping it at the old.+ contentKey = state.selectedUserId ?: state.selectedWaypointId, sheetContent = { MainSheetContent( state = state,@@ -145,13 +142,12 @@ fun MainPageContent( // Full-bleed map slot; overlays (FAB, history bar) sit just above the collapsed // sheet peek and lift upward as the sheet expands. Box(Modifier.fillMaxSize()) {- // Lift overlays above their peek baseline as the sheet expands:- // (current - settledPeekOffset), clamped to <= 0. Uses the settled peek- // offset (sampled above) so transitions never push overlays off-screen.+ // Lift overlays above their peek baseline as the sheet grows:+ // -(current - settledPeekHeight), clamped to <= 0. Uses the settled peek+ // height (sampled above) so transitions never push overlays off-screen. val sheetLiftPx: () -> Int = {- val base = collapsedSheetOffset.floatValue- val cur = runCatching { scaffoldState.bottomSheetState.requireOffset() }.getOrNull()- if (cur != null && !base.isNaN()) (cur - base).roundToInt().coerceAtMost(0) else 0+ val base = collapsedSheetLift.floatValue+ if (!base.isNaN()) (-(sheetState.liftPx - base)).roundToInt().coerceAtMost(0) else 0 } map()
findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainSheetContent.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainSheetContent.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainSheetContent.ktindex 13de336d37..dd3870ae10 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainSheetContent.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainSheetContent.kt@@ -156,15 +156,11 @@ internal fun MainSheetContent( personContent: @Composable () -> Unit = {}, waypointContent: @Composable () -> Unit = {}, ) {- // The sheet's own content MUST be taller than the peek, or Material3 emits a single- // anchor and the scaffold crashes.- //- // BottomSheetScaffold places PartiallyExpanded at (container - peek) and Expanded at- // (container - sheetHeight). When the content is no taller than the peek those two- // coincide, Material3 keeps only Expanded, and the state - which still targets- // PartiallyExpanded - throws AnchoredDraggableUninitializedException out of the- // measure pass. That is a hard FATAL, and it is reached by an ordinary route: a fresh- // install has no family members, so FamilyListSheet is close to empty.+ // The sheet's own content is kept taller than the peek: the free-height+ // sheet learns its expansion ceiling from how tall its content measures,+ // so content no taller than the peek would leave the sheet unable to grow+ // past it. A fresh install has no family members, so FamilyListSheet is+ // close to empty without this floor. // // Bottom-panel host for the selection routes: Route.PersonSheet / // Route.WaypointSheet swap this panel to the person/waypoint content
findfamily/src/test/java/com/vayunmathur/findfamily/ui/MapPanGestureTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MapPanGestureTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MapPanGestureTest.ktnew file mode 100644index 0000000000..76d21a7388--- /dev/null+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MapPanGestureTest.kt@@ -0,0 +1,86 @@+package com.vayunmathur.findfamily.ui++import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.runtime.remember+import androidx.compose.ui.Modifier+import androidx.compose.ui.geometry.Offset+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onRoot+import androidx.compose.ui.test.performTouchInput+import androidx.compose.ui.test.swipe+import com.vayunmathur.findfamily.platform.FamilyListActions+import com.vayunmathur.findfamily.platform.MainPageActions+import com.vayunmathur.findfamily.platform.MainPageUiState+import com.vayunmathur.library.map.CameraPosition+import com.vayunmathur.library.map.CameraState+import com.vayunmathur.library.map.GeoPoint+import com.vayunmathur.library.map.VectorMap+import com.vayunmathur.library.ui.DynamicTheme+import kotlin.test.Test+import kotlin.test.assertNotEquals+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/**+ * Regression: a drag on the FindFamily map must move the camera.+ *+ * The Material 3 `BottomSheetScaffold` previously hosting this page consumed+ * drag gestures over the whole content area, so `CameraState.onGesture`+ * never ran: the Compose people overlay (positioned from the camera) could+ * move while the native basemap never re-rendered panned, and in practice+ * no drag moved the map at all. `VectorMap` alone always panned (first+ * test, the control); the page host was the blocker.+ */+@RunWith(RobolectricTestRunner::class)+class MapPanGestureTest {+ @get:Rule val rule = createComposeRule()++ @Test fun swipeOnVectorMapAlonePansCamera() {+ var camera: CameraState? = null+ rule.setContent {+ DynamicTheme {+ val cam = remember { CameraState(CameraPosition(GeoPoint(0.0, 0.0), 10.0)) }+ camera = cam+ VectorMap(cameraState = cam)+ }+ }+ rule.waitForIdle()+ val before = camera!!.position.target+ rule.onRoot().performTouchInput {+ swipe(Offset(60f, 200f), Offset(260f, 200f), 400)+ }+ rule.waitForIdle()+ assertNotEquals(before, camera!!.position.target)+ }++ @Test fun swipeOnMapInsideMainPageContentPansCamera() {+ var camera: CameraState? = null+ rule.setContent {+ DynamicTheme {+ val cam = remember { CameraState(CameraPosition(GeoPoint(0.0, 0.0), 10.0)) }+ camera = cam+ MainPageContent(+ state = MainPageUiState(),+ familyActions = FamilyListActions.Noop,+ actions = MainPageActions.Noop,+ map = {+ Box(Modifier.fillMaxSize()) {+ VectorMap(cameraState = cam)+ }+ },+ )+ }+ }+ rule.waitForIdle()+ val before = camera!!.position.target+ // Swipe in the map area above the sheet peek (the sheet rests at+ // the bottom of the window; the map fills the rest).+ rule.onRoot().performTouchInput {+ swipe(Offset(60f, 120f), Offset(260f, 120f), 400)+ }+ rule.waitForIdle()+ assertNotEquals(before, camera!!.position.target)+ }+}
library/map/src/test/java/com/vayunmathur/library/map/CameraGesturesTest.kt
diff --git a/library/map/src/test/java/com/vayunmathur/library/map/CameraGesturesTest.kt b/library/map/src/test/java/com/vayunmathur/library/map/CameraGesturesTest.ktindex 33696872cf..f3b1803b60 100644--- a/library/map/src/test/java/com/vayunmathur/library/map/CameraGesturesTest.kt+++ b/library/map/src/test/java/com/vayunmathur/library/map/CameraGesturesTest.kt@@ -27,6 +27,21 @@ class CameraGesturesTest { assertEquals(10.0, c.position.zoom, absoluteTolerance = 1e-9) } + @Test fun pan_shiftsProjectionByExactlyTheDrag() {+ // One camera source of truth: the native frame and the Compose overlay+ // both derive from this CameraState (renderer pulls `position`,+ // overlays read `projection`), so a pan must shift a fixed ground+ // point's projected screen location by exactly the drag delta. Any+ // divergence here is the "overlay moves, basemap doesn't" split.+ val c = camera()+ val ground = GeoPoint(-122.4194, 37.7749)+ val before = assertNotNull(c.projection).screenLocationFromPosition(ground)+ c.onGesture(Offset(200f, 400f), Offset(40f, 25f), 1f, 0f, 2.0, 20.0, scrollEnabled = true, zoomEnabled = true)+ val after = assertNotNull(c.projection).screenLocationFromPosition(ground)+ assertEquals(40.0, (after.x - before.x).value.toDouble(), absoluteTolerance = 1e-3)+ assertEquals(25.0, (after.y - before.y).value.toDouble(), absoluteTolerance = 1e-3)+ }+ @Test fun pan_disabledWhenScrollOff() { val c = camera() val before = c.position.target
library/ui/src/main/java/com/vayunmathur/library/ui/FreeHeightSheetState.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/FreeHeightSheetState.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/FreeHeightSheetState.ktindex be72552863..cc656c1747 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/FreeHeightSheetState.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/FreeHeightSheetState.kt@@ -119,6 +119,12 @@ class FreeHeightSheetState(private val initialValue: SheetValue) { availablePx = expanded applyBounds(peek) if (!measured) {+ // A host content swap can call `resetContentCap` before the first+ // measurement lands; its `armBounds` then installs a [0, 0] bound+ // (no available height yet), which would clamp this snap to zero+ // and leave the sheet collapsed for good. Widen to the real bound+ // first so the resting height does not depend on effect order.+ offset.updateBounds(0f, expandedPx) offset.snapTo( when (initialValue) { SheetValue.Hidden -> 0f
library/ui/src/test/java/com/vayunmathur/library/ui/FreeHeightSheetStateTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/FreeHeightSheetStateTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/FreeHeightSheetStateTest.ktindex f3cfa23a07..4de5f2a99e 100644--- a/library/ui/src/test/java/com/vayunmathur/library/ui/FreeHeightSheetStateTest.kt+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/FreeHeightSheetStateTest.kt@@ -46,6 +46,17 @@ class FreeHeightSheetStateTest { assertEquals(100f, state.liftPx) } + @Test fun contentCapResetBeforeFirstMeasureStillRestsAtPeek() = scope.runTest {+ // Regression: the host calls `resetContentCap` when its content is+ // swapped in, which can land before the first `onMeasured`. Its+ // `armBounds` installed a [0, 0] bound, and the initial snap to the+ // peek was clamped to zero — the sheet never opened.+ val state = FreeHeightSheetState(SheetValue.PartiallyExpanded)+ state.resetContentCap(peek = 100f)+ state.onMeasured(peek = 100f, expanded = 600f)+ assertEquals(100f, state.offsetPx)+ }+ @Test fun initialHiddenRestsAtZero() = scope.runTest { val state = FreeHeightSheetState(SheetValue.Hidden) state.onMeasured(peek = 100f, expanded = 600f)