maps: move Street View to a top-level route (#nav)
- Commit
52b594ed4f2a36cf3733a6fd788d94b1e3adc73c- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-16 18:59 UTC (19 days ago)
- Parents
1a165bf
Street View was a full-screen viewer held in a remember inside StreetViewPegman (audit M12): a pano state swapped the map for the viewer outside any back stack, so back, restore and deep-linking could not see it. Add Route.StreetView(lat, lon) with FullscreenPage metadata. The pegman still resolves coverage on drop (no imagery still shows the unavailable message and opens nothing); on success it now pushes the route with the drop coordinates instead of holding the pano. The new StreetViewRoute entry re-resolves the nearest pano at those coordinates, shows a loading spinner on black, closes straight back when there is none, and otherwise hosts the unchanged StreetViewScreen, whose close pops the stack. Verified: ./gradlew :maps:compileDevKotlin :maps:testDevUnitTest green on devvm21958.
Diff
maps/src/main/java/com/vayunmathur/maps/MainActivity.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/MainActivity.kt b/maps/src/main/java/com/vayunmathur/maps/MainActivity.ktindex 49ec3f77ef..397df534b7 100644--- a/maps/src/main/java/com/vayunmathur/maps/MainActivity.kt+++ b/maps/src/main/java/com/vayunmathur/maps/MainActivity.kt@@ -16,6 +16,7 @@ import com.vayunmathur.library.ui.AppPermissionsSpec import com.vayunmathur.library.ui.DynamicTheme import com.vayunmathur.library.ui.MaActivity import com.vayunmathur.library.ui.PermissionRequirement+import com.vayunmathur.library.util.FullscreenPage import com.vayunmathur.library.util.ListDetailPage import com.vayunmathur.library.util.ListPage import com.vayunmathur.library.util.OfflineAware@@ -331,6 +332,9 @@ sealed interface Route: NavKey { /** Singleton holding saved places page state and operations. */ @Serializable data object SavedPlacesPage: Route+ /** Full-screen Street View viewer for the nearest pano to a point. */+ @Serializable+ data class StreetView(val lat: Double, val lon: Double): Route } @Composable@@ -366,5 +370,10 @@ fun Navigation( entry<Route.SavedPlacesPage>(metadata = ListDetailPage()) { SavedPlacesPage(backStack, savedPlacesViewModel) }+ entry<Route.StreetView>(metadata = FullscreenPage()) { route ->+ com.vayunmathur.maps.ui.streetview.StreetViewRoute(+ lat = route.lat, lon = route.lon, onClose = { backStack.pop() },+ )+ } } }
maps/src/main/java/com/vayunmathur/maps/ui/MapContentBox.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MapContentBox.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MapContentBox.ktindex 408e999995..dd3f8dcb10 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapContentBox.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapContentBox.kt@@ -102,7 +102,7 @@ internal fun MapPageScope.MapContentBox( // this box: while search is up, a drop in the bottom third lands on the sheet // rather than the map, and half a working drag is worse than no peg. // Also gated on the Google services opt-in: no opt-in, no peg, no tiles.- if (browsing && searchRequest == null && googleServices) StreetViewPegman(camera)+ if (browsing && searchRequest == null && googleServices) StreetViewPegman(camera, onOpenStreetView = { lat, lon -> backStack.add(com.vayunmathur.maps.Route.StreetView(lat, lon)) }) // The chrome's inset, in one place. `windowInsetsPadding` *consumes* what it // applies, so the pieces below that inset themselves — the FAB stack, the scale
maps/src/main/java/com/vayunmathur/maps/ui/streetview/StreetViewPegman.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/streetview/StreetViewPegman.kt b/maps/src/main/java/com/vayunmathur/maps/ui/streetview/StreetViewPegman.ktindex 55400b5e5f..1cafde49b9 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/streetview/StreetViewPegman.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/streetview/StreetViewPegman.kt@@ -29,8 +29,6 @@ import androidx.compose.ui.semantics.semantics import androidx.compose.ui.unit.DpOffset import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp-import androidx.compose.ui.window.Dialog-import androidx.compose.ui.window.DialogProperties import com.vayunmathur.library.map.CameraState import com.vayunmathur.library.ui.CircularProgressIndicator import com.vayunmathur.library.ui.IconDirectionsWalk@@ -39,7 +37,6 @@ import com.vayunmathur.library.ui.Surface import com.vayunmathur.library.ui.rememberMessenger import com.vayunmathur.maps.R import com.vayunmathur.maps.data.google.StreetViewDataSource-import com.vayunmathur.maps.data.google.StreetViewPano import com.vayunmathur.maps.ui.theme.MapChromeMetrics import kotlinx.coroutines.launch @@ -62,7 +59,7 @@ private val PEG_SIZE = 48.dp * than opening an empty viewer. */ @Composable-fun BoxScope.StreetViewPegman(camera: CameraState, modifier: Modifier = Modifier) {+fun BoxScope.StreetViewPegman(camera: CameraState, onOpenStreetView: (Double, Double) -> Unit = { _, _ -> }, modifier: Modifier = Modifier) { val density = LocalDensity.current val scope = rememberCoroutineScope() val messenger = rememberMessenger()@@ -76,7 +73,6 @@ fun BoxScope.StreetViewPegman(camera: CameraState, modifier: Modifier = Modifier // Where the finger is, in this box's coordinates. Null when not dragging. var dragPoint by remember { mutableStateOf<Offset?>(null) } var resolving by remember { mutableStateOf(false) }- var pano by remember { mutableStateOf<StreetViewPano?>(null) } fun drop(point: Offset) { val projection = camera.projection ?: return@@ -87,7 +83,7 @@ fun BoxScope.StreetViewPegman(camera: CameraState, modifier: Modifier = Modifier scope.launch { val found = StreetViewDataSource.nearest(target.latitude, target.longitude) resolving = false- if (found == null) messenger.show(noImagery) else pano = found+ if (found == null) messenger.show(noImagery) else onOpenStreetView(target.latitude, target.longitude) } } @@ -128,14 +124,6 @@ fun BoxScope.StreetViewPegman(camera: CameraState, modifier: Modifier = Modifier CircularProgressIndicator(Modifier.align(Alignment.Center)) } - pano?.let { p ->- Dialog(- onDismissRequest = { pano = null },- properties = DialogProperties(usePlatformDefaultWidth = false),- ) {- StreetViewScreen(initialPano = p, onClose = { pano = null })- }- } } }
maps/src/main/java/com/vayunmathur/maps/ui/streetview/StreetViewScreen.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/streetview/StreetViewScreen.kt b/maps/src/main/java/com/vayunmathur/maps/ui/streetview/StreetViewScreen.ktindex ee3c19fbf4..8d242ad67f 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/streetview/StreetViewScreen.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/streetview/StreetViewScreen.kt@@ -43,6 +43,28 @@ import kotlinx.coroutines.launch * NAVIGATION: arrows drawn into the scene by [StreetViewArrows], one per walkable * neighbour, pinned to their compass bearings. Tapping one travels there. */+/**+ * Route entry for Street View: resolves the nearest pano to [lat]/[lon],+ * then hosts [StreetViewScreen]. No imagery nearby closes straight back.+ */+@Composable+fun StreetViewRoute(lat: Double, lon: Double, onClose: () -> Unit) {+ var pano by remember { mutableStateOf<StreetViewPano?>(null) }+ var resolved by remember { mutableStateOf(false) }+ LaunchedEffect(lat, lon) {+ pano = StreetViewDataSource.nearest(lat, lon)+ resolved = true+ if (pano == null) onClose()+ }+ when {+ pano != null -> StreetViewScreen(initialPano = pano!!, onClose = onClose)+ !resolved -> Box(Modifier.fillMaxSize().background(Color.Black)) {+ CircularProgressIndicator(Modifier.align(Alignment.Center), color = Color.White)+ }+ else -> Unit+ }+}+ @Composable fun StreetViewScreen(initialPano: StreetViewPano, onClose: () -> Unit) { var pano by remember { mutableStateOf(initialPano) }