Modern Apps git

← Modern-Apps.git

maps: search auto-select opens the Vela-style place bottom pane

Commit
973e9d509450c4f674dd0247bee86023662beb68
Author
vayun-mathur <[email protected]>
When
2026-08-17 22:23 UTC (3 months ago)
Parents
0d829e6
Contact-address (P17) and any search+auto-select-first now use
SelectedFeatureViewModel.selectAndFocus(): select the first result, fly
the camera there, and open the bottom PANE (partialExpand/peek) instead
of a full-screen sheet, matching Vela's place card. Selecting the
GenericPlace triggers currentPoiInfo enrichment so the pane fills in.
A StateFlow-backed pendingFocus survives a cold start so a place
selected before MapPage composes still peeks once the map is ready.

Diff

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 6689f451fa..60d2f7e649 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt@@ -256,7 +256,29 @@ fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel,     )      LaunchedEffect(Unit) {-        if(selectedFeature != null) scaffoldState.bottomSheetState.expand()+        // Restore-on-recompose: raise the sheet if something is already selected โ€”+        // unless a deep link / auto-select is about to open the compact PANE instead+        // (handled by the pendingFocus effect below), so we don't full-expand first.+        if (selectedFeature != null && viewModel.pendingFocus.value == null) {+            scaffoldState.bottomSheetState.expand()+        }+    }++    // Search auto-select (P17 contact address) + external geo:/maps deep links land+    // here: fly to the place and open the Vela-style bottom PANE (partial/peek), not a+    // full-screen sheet. A StateFlow-backed request survives a cold start, so a link+    // that selected a place before the map composed still animates + peeks once ready.+    val pendingFocus by viewModel.pendingFocus.collectAsState()+    LaunchedEffect(pendingFocus) {+        val req = pendingFocus ?: return@LaunchedEffect+        camera.animateTo(+            camera.position.copy(+                target = req.position,+                zoom = req.zoom ?: maxOf(camera.position.zoom, 14.0),+            )+        )+        scaffoldState.bottomSheetState.partialExpand()+        viewModel.consumeFocus()     }      suspend fun hide() {@@ -394,16 +416,14 @@ fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel,                                     if (selectedFeature is SpecificFeature.Route) {                                         viewModel.setInactiveNavigation(selectedFeature as SpecificFeature.Route)                                     }-                                    viewModel.set(searchViewModel.toFeature(first))-                                    coroutineScope.launch {-                                        camera.animateTo(-                                            camera.position.copy(-                                                target = Position(first.lon, first.lat),-                                                zoom = maxOf(camera.position.zoom, 14.0),-                                            )-                                        )-                                    }-                                    coroutineScope.launch { scaffoldState.bottomSheetState.expand() }+                                    // Select the top hit + fly there + open the place PANE+                                    // (peek), the Vela place-card behaviour. The callback fires+                                    // after the (possibly delayed) scrape resolves, so late+                                    // results still land correctly.+                                    viewModel.selectAndFocus(+                                        searchViewModel.toFeature(first),+                                        zoom = maxOf(camera.position.zoom, 14.0),+                                    )                                 }                             }                         })
maps/src/main/java/com/vayunmathur/maps/util/SelectedFeatureViewModel.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/SelectedFeatureViewModel.kt b/maps/src/main/java/com/vayunmathur/maps/util/SelectedFeatureViewModel.ktindex 95c9740415..f891cbe3fd 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/SelectedFeatureViewModel.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/SelectedFeatureViewModel.kt@@ -18,6 +18,15 @@ class SelectedFeatureViewModel(application: Application): AndroidViewModel(appli     private val _inactiveNavigation = MutableStateFlow<SpecificFeature.Route?>(null)     val inactiveNavigation = _inactiveNavigation.asStateFlow() +    /** A pending request for the map to fly to [position] (at [zoom] when set) and+     *  show the place bottom PANE (peek), the Vela-style place card. Backed by a+     *  StateFlow so a request made before MapPage is composed (a cold-start deep+     *  link) survives until the map consumes it via [consumeFocus]. */+    data class PlaceFocus(val position: Position, val zoom: Double? = null)++    private val _pendingFocus = MutableStateFlow<PlaceFocus?>(null)+    val pendingFocus = _pendingFocus.asStateFlow()+     private val _userPosition = MutableStateFlow(Position(0.0, 0.0))     val userPosition = _userPosition.asStateFlow() @@ -53,6 +62,24 @@ class SelectedFeatureViewModel(application: Application): AndroidViewModel(appli         _selectedFeature.value = feature     } +    /**+     * Select [feature] AND ask the map to fly to it and open the place bottom pane+     * (peek). This is the single "search โ†’ auto-select first / deep link โ†’ open a+     * place" path shared by the contact-address shortcut (P17) and the external+     * intent handler (geo:/maps links). Selecting a [SpecificFeature.RoutableFeature]+     * triggers [currentPoiInfo] enrichment so the pane fills with details.+     */+    fun selectAndFocus(feature: SpecificFeature, zoom: Double? = null) {+        _selectedFeature.value = feature+        val pos = (feature as? SpecificFeature.RoutableFeature)?.position+        _pendingFocus.value = pos?.let { PlaceFocus(it, zoom) }+    }++    /** Clear a consumed [pendingFocus] once the map has flown there + opened the pane. */+    fun consumeFocus() {+        _pendingFocus.value = null+    }+     fun setInactiveNavigation(route: SpecificFeature.Route?) {         _inactiveNavigation.value = route     }