maps: contact address opens location directly; fix blank map after back from search
- Commit
fc6095132731b3302b87fe30071a55e0cff962a5- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-17 23:51 UTC (3 months ago)
- Parents
288a172
Bug 1+2: picking a contact address now geocodes it and opens the place directly (fly + peek pane) instead of prefilling the search bar. Add MapsSearchViewModel.resolveAndSelect (resolves an address string via GoogleSearchDataSource.search on IO, no _query/_results mutation) and wire ContactAddressButton to viewModel.selectAndFocus; brief toast when nothing resolves. Bug 3: MaplibreMap now uses TextureView render mode. The default SurfaceView renders in a separate surface and went black + stopped taking input after MapPage is disposed on push to SearchPage and recomposed on the back-pop through Nav3's AnimatedContent transition, repainting only when a later recomposition forced a relayout. TextureView draws in the normal view hierarchy, so the map stays live + interactive across the transition.
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 60d2f7e649..0ee4b0f99c 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt@@ -404,26 +404,34 @@ fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel, modifier = Modifier.weight(1f).padding(horizontal = 8.dp), maxLines = 1, )- // Contact address shortcut (P17): pick a contact's postal- // address, run the P3 Google search and auto-select the- // first hit โ same path as tapping a search result.+ // Contact address shortcut (P17/P31): pick a contact's+ // postal address, GEOCODE it and open the resolved place+ // DIRECTLY (fly there + peek pane) โ never through the+ // search box (no query prefill, no results list). ContactAddressButton(onAddress = { address -> val bbox = camera.projection?.queryVisibleBoundingBox() val nearLat = ((bbox?.north ?: 85.0) + (bbox?.south ?: -85.0)) / 2.0 val nearLon = ((bbox?.east ?: 180.0) + (bbox?.west ?: -180.0)) / 2.0- searchViewModel.searchAndSelectFirst(address, nearLat, nearLon) { first ->- if (first != null) {+ searchViewModel.resolveAndSelect(address, nearLat, nearLon) { place ->+ if (place != null) { if (selectedFeature is SpecificFeature.Route) { viewModel.setInactiveNavigation(selectedFeature as SpecificFeature.Route) }- // 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.+ // Fly to the resolved place + open the peek pane+ // (Vela place-card), the same direct-open path as+ // a geo:/maps deep link. viewModel.selectAndFocus(- searchViewModel.toFeature(first),+ place, zoom = maxOf(camera.position.zoom, 14.0), )+ } else {+ runCatching {+ android.widget.Toast.makeText(+ context,+ context.getString(MapsR.string.no_results_found),+ android.widget.Toast.LENGTH_SHORT,+ ).show()+ } } } })@@ -449,7 +457,17 @@ fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel, BaseStyle.Json(json), camera, options = MapOptions(- RenderOptions(),+ // TextureView (not the default SurfaceView): a+ // SurfaceView renders into a separate surface and goes+ // black + stops taking input after this composable is+ // disposed on push to SearchPage and recomposed on the+ // back-pop through Nav3's AnimatedContent transition+ // (it only repaints once a later recomposition forces a+ // relayout). TextureView draws in the normal view+ // hierarchy, so it composites + stays interactive across+ // the transition, restoring a live map immediately on+ // back.+ RenderOptions(renderMode = RenderOptions.RenderMode.TextureView), GestureOptions.Standard, OrnamentOptions.AllDisabled ),
maps/src/main/java/com/vayunmathur/maps/util/MapsSearchViewModel.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/MapsSearchViewModel.kt b/maps/src/main/java/com/vayunmathur/maps/util/MapsSearchViewModel.ktindex 239c8f4774..9efc0ae288 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/MapsSearchViewModel.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/MapsSearchViewModel.kt@@ -117,6 +117,47 @@ class MapsSearchViewModel(application: Application) : AndroidViewModel(applicati } } + /**+ * Resolve a free-text [address] (e.g. a picked contact postal address) to a+ * single place and hand it back โ WITHOUT touching the query text or the+ * result list. The contact-address shortcut (P17/P31) opens the place+ * directly instead of going through the search box, so this must NOT set+ * [_query] or populate [_results] (that would prefill the search bar and+ * draw the search-result pins).+ *+ * A full address string is resolved via the Google text [GoogleSearchDataSource.search]+ * (the only path that maps a string to a coordinate; [reverseGeocode] takes a+ * coordinate, not an address). The search does its own [Dispatchers.IO] and+ * never throws; [onResolved] fires on the main thread so the caller can+ * safely drive [SelectedFeatureViewModel.selectAndFocus]. Returns null when+ * nothing resolves.+ */+ fun resolveAndSelect(+ address: String,+ nearLat: Double,+ nearLon: Double,+ onResolved: (SpecificFeature.GenericPlace?) -> Unit,+ ) {+ if (address.isBlank()) {+ onResolved(null)+ return+ }+ viewModelScope.launch {+ val hit = GoogleSearchDataSource.search(address, nearLat, nearLon).firstOrNull()+ onResolved(+ hit?.let {+ SpecificFeature.GenericPlace(+ name = it.name.ifBlank { it.address ?: address },+ phone = null,+ website = null,+ openingHours = null,+ position = Position(it.lng, it.lat),+ )+ }+ )+ }+ }+ /** Resets the search state (keeps recents). */ fun reset() { searchJob?.cancel()