Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ class HomeViewModel @Inject constructor(
focusedTrips = trips
presentedRoutes = trips.mapTo(linkedSetOf(), FocusedTrip::routeDirection)
val preserveViewport = pendingMapFocus && preserveViewportForPendingMapFocus
// Frame the selected route only when this load is the initial (restore/deep-link) focus
// establishment; an ordinary arrivals poll must refresh the presentation without reframing the
// camera to the whole route (#1895). A restore carrying a saved viewport already declines to frame.
val frameSelectedRoute = pendingMapFocus && !preserveViewportForPendingMapFocus
if (pendingMapFocus) {
pendingMapFocus = false
preserveViewportForPendingMapFocus = false
Expand All @@ -323,7 +327,7 @@ class HomeViewModel @Inject constructor(
MapDirective.ShowRoute(
it.target(focus.stop.id).toRequest(),
stopScoped = true,
frameRoute = !preserveViewport,
frameRoute = frameSelectedRoute,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,32 @@ class HomeViewModelTest {
mapJob.cancel()
}

@Test
fun `an ordinary arrivals poll refreshes the selected route without reframing`() = runTest {
val vm = viewModel()
val map = MapDirectiveRecorder(vm)
val mapJob = launch { map.collect() }
advanceUntilIdle()
vm.onStopFocused(FocusedStop("stop", "Main St", "100", 47.6, -122.3))
advanceUntilIdle()
vm.selectArrivalRoute(
request = ShowRouteRequest("65", directionStopId = "stop", initialDirectionId = 0),
shortName = "65",
headsign = "Downtown",
)
advanceUntilIdle()
// Selecting the route frames it once.
assertEquals(true, map.routeCommands.single().frameRoute)
map.sent.clear()

// A subsequent arrivals poll (no pending focus) re-shows the selected route but must not reframe.
vm.onArrivalsLoaded(ObaStopElement("stop", 47.6, -122.3, "Main St", "100"), emptyList(), emptySet())
advanceUntilIdle()

assertEquals(false, map.routeCommands.single().frameRoute)
mapJob.cancel()
}

@Test
fun `drawer route selection and continuation remain subordinate to stop focus`() = runTest {
val savedState = SavedStateHandle()
Expand Down