Modern Apps git

← Modern-Apps.git

maps: keep the layers FAB out, riding above the sheet

Commit
40193ff124e35b0033b300249cf26478ff5ed1c1
Author
vayun-mathur <[email protected]>
When
2026-08-24 20:25 UTC (3 months ago)
Parents
74bf674

Diff

library/ui/src/main/java/com/vayunmathur/library/ui/FreeHeightBottomSheet.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/FreeHeightBottomSheet.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/FreeHeightBottomSheet.ktindex 33503e8f8e..039d4273c1 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/FreeHeightBottomSheet.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/FreeHeightBottomSheet.kt@@ -89,6 +89,22 @@ class FreeHeightSheetState(private val initialValue: SheetValue) {     internal val offsetPx: Float         get() = offset.value +    /**+     * How far above its resting place map chrome must sit to clear the sheet, in+     * pixels. `0` while the sheet is hidden.+     *+     * **This is a height, not a distance from the top of the window** — the opposite+     * of Material's `SheetState.requireOffset`, so a caller offsets by the *negation*+     * of it (`IntOffset(0, -lift)`) and needs no baseline to difference against.+     *+     * There is also nothing to sample a baseline from: this sheet has no anchors, so+     * a fling rests wherever the decay stops and there is no settled "peek" position.+     * The value is read inside a layout lambda rather than observed, so chrome tracks+     * the sheet every frame without recomposing.+     */+    val liftPx: Float+        get() = offset.value+     internal val expandedHeightPx: Float         get() = expandedPx 
maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.ktindex 57c6b2a769..5658fce9f7 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt@@ -49,6 +49,7 @@ import com.vayunmathur.maps.util.PoiIndex import com.vayunmathur.maps.util.SavedPlacesViewModel import com.vayunmathur.maps.util.SelectedFeatureViewModel import com.vayunmathur.maps.util.visibleBoundsOrWorld+import kotlin.math.roundToInt import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext@@ -299,50 +300,50 @@ fun MapPage(                     )                 } -                // Browse controls only: navigation owns its own, and a selected place hands the-                // bottom half of the screen to the sheet.-                if (browsing) {-                    MapFabStack(-                        zoom = camera.position.zoom,-                        latitude = camera.position.target.latitude,-                        bearing = camera.position.bearing,-                        onResetNorth = {-                            coroutineScope.launch {-                                camera.animateTo(camera.position.copy(bearing = 0.0, tilt = 0.0))-                            }-                        },-                        onLayers = { chrome.show(MapOverlay.Layers) },-                        onParking = {-                            val spot = parkingSpot-                            if (spot == null) {-                                val position = userPosition-                                if (position.latitude != 0.0 || position.longitude != 0.0) {-                                    parkingViewModel.saveParking(position.latitude, position.longitude)-                                }-                            } else {-                                coroutineScope.launch {-                                    camera.animateTo(-                                        camera.position.copy(-                                            target = Position(spot.lon, spot.lat),-                                            zoom = maxOf(camera.position.zoom, 15.0),-                                        )-                                    )-                                }-                                chrome.show(MapOverlay.Parking)+                // Browse controls, plus the layers button, which stays out while a place is+                // selected and rides above the sheet — see [MapFabStack].+                MapFabStack(+                    zoom = camera.position.zoom,+                    latitude = camera.position.target.latitude,+                    bearing = camera.position.bearing,+                    browsing = browsing,+                    lift = { sheetState.liftPx.roundToInt() },+                    onResetNorth = {+                        coroutineScope.launch {+                            camera.animateTo(camera.position.copy(bearing = 0.0, tilt = 0.0))+                        }+                    },+                    onLayers = { chrome.show(MapOverlay.Layers) },+                    onParking = {+                        val spot = parkingSpot+                        if (spot == null) {+                            val position = userPosition+                            if (position.latitude != 0.0 || position.longitude != 0.0) {+                                parkingViewModel.saveParking(position.latitude, position.longitude)                             }-                        },-                        onMyLocation = {+                        } else {                             coroutineScope.launch {                                 camera.animateTo(                                     camera.position.copy(-                                        target = userPosition,+                                        target = Position(spot.lon, spot.lat),                                         zoom = maxOf(camera.position.zoom, 15.0),                                     )                                 )                             }-                        },-                    )-                }+                            chrome.show(MapOverlay.Parking)+                        }+                    },+                    onMyLocation = {+                        coroutineScope.launch {+                            camera.animateTo(+                                camera.position.copy(+                                    target = userPosition,+                                    zoom = maxOf(camera.position.zoom, 15.0),+                                )+                            )+                        }+                    },+                )                  NavigationOverlay(                     navState = navState,
maps/src/main/java/com/vayunmathur/maps/ui/map/MapFabStack.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapFabStack.kt b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapFabStack.ktindex 2e372b1a6a..a2d79197cd 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapFabStack.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapFabStack.kt@@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.BoxScope import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.WindowInsets+import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.systemBars import androidx.compose.foundation.layout.windowInsetsPadding@@ -11,6 +12,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.IntOffset import com.vayunmathur.library.ui.FloatingActionButton import com.vayunmathur.library.ui.IconMyLocation import com.vayunmathur.library.ui.Text@@ -21,33 +23,49 @@ import com.vayunmathur.maps.ui.theme.MapChromeMetrics import com.vayunmathur.maps.R as MapsR  /**- * The browse-mode map controls: a scale bar bottom-left, a FAB stack bottom-right.+ * The map controls: a scale bar bottom-left, a FAB stack bottom-right.  *  * Stateless — every action is a lambda, so this file has no idea what a parking spot is or how- * to animate a camera. Shown only while browsing; navigation has its own controls and a- * selected place hands the bottom half of the screen to the sheet.+ * to animate a camera.+ *+ * Most of it is browse-only: navigation has its own controls, and a selected place hands the+ * bottom half of the screen to the sheet. **Layers is the exception** — which basemap and which+ * overlays are on is a question you also ask while looking at a place, so it stays and rides+ * above the sheet via [lift]. Keeping it in this one column rather than as its own floating+ * button is what preserves its position in the stack while browsing.  */ @Composable fun BoxScope.MapFabStack(     zoom: Double,     latitude: Double,     bearing: Double,+    /** Whether the browse-only controls are shown. Layers is drawn either way. */+    browsing: Boolean,+    /**+     * Pixels the sheet currently covers, from `FreeHeightSheetState.liftPx`. A lambda,+     * and read during layout, so tracking the sheet costs no recomposition.+     */+    lift: () -> Int,     onResetNorth: () -> Unit,     onLayers: () -> Unit,     onParking: () -> Unit,     onMyLocation: () -> Unit, ) {-    MapScaleBar(-        zoom = zoom,-        latitude = latitude,-        modifier = Modifier-            .align(Alignment.BottomStart)-            .windowInsetsPadding(WindowInsets.systemBars)-            .padding(MapChromeMetrics.chromeMargin),-    )+    if (browsing) {+        MapScaleBar(+            zoom = zoom,+            latitude = latitude,+            modifier = Modifier+                .align(Alignment.BottomStart)+                .windowInsetsPadding(WindowInsets.systemBars)+                .padding(MapChromeMetrics.chromeMargin),+        )+    }     Column(         modifier = Modifier             .align(Alignment.BottomEnd)+            // Negated: liftPx is the sheet's visible height, not a distance from the top.+            .offset { IntOffset(0, -lift()) }             .windowInsetsPadding(WindowInsets.systemBars)             .padding(MapChromeMetrics.chromeMargin),         horizontalAlignment = Alignment.End,@@ -55,16 +73,20 @@ fun BoxScope.MapFabStack(     ) {         // Compass on top and only while the map is rotated; layers in the middle;         // my-location is the primary action, so it sits closest to the thumb.-        CompassButton(bearing = bearing, onResetNorth = onResetNorth)-        LayersButton(onClick = onLayers)-        // Parking memory (P9): with no saved spot a tap saves the current location; with one,-        // it recenters and opens the sheet ("find my car"). Both live in [onParking] because-        // which one happens depends on state this component does not own.-        FloatingActionButton(onClick = onParking) {-            Text(stringResource(MapsR.string.parking_pin_glyph))+        if (browsing) {+            CompassButton(bearing = bearing, onResetNorth = onResetNorth)         }-        FloatingActionButton(onClick = onMyLocation) {-            IconMyLocation()+        LayersButton(onClick = onLayers)+        if (browsing) {+            // Parking memory (P9): with no saved spot a tap saves the current location; with one,+            // it recenters and opens the sheet ("find my car"). Both live in [onParking] because+            // which one happens depends on state this component does not own.+            FloatingActionButton(onClick = onParking) {+                Text(stringResource(MapsR.string.parking_pin_glyph))+            }+            FloatingActionButton(onClick = onMyLocation) {+                IconMyLocation()+            }         }     } }