Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(iOS): recenter on vehicle from new stop details #580

Merged
merged 6 commits into from
Dec 12, 2024

Conversation

boringcactus
Copy link
Member

Summary

Ticket: Combined Stop + Trip Details: Recenter on vehicle button

Moving the map's global data into the MapViewModel felt a little bit weird, but making the ContentView load its own global data would've felt weirder. I think the Android approach of putting these buttons structurally within the map is nicer, but I don't want to refactor iOS to match that in this PR.

iOS

  • If you added any user-facing strings on iOS, are they included in Localizable.xcstrings?
    • Add temporary machine translations, marked "Needs Review"

android

  • All user-facing strings added to strings resource

Testing

Manually validated that the button uses the subway/bus/CR icon for subway/bus/CR routes (since ferries don't get realtime info right now, I can't test that, but presumably it'd work if that changed). No unit test for the vehicle recenter button, since there's no unit test for the self recenter button.

@boringcactus boringcactus requested a review from a team as a code owner December 11, 2024 16:58
.navigationStack.lastSafe(),
let selectedVehicle = mapVM.selectedVehicle, let globalData = mapVM.globalData,
let stop = nearbyVM.getTargetStop(global: globalData), let routeId = stopFilter?.routeId,
let route = globalData.routes[routeId] else { return nil }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work for GL because its filter "routeId" is actually the line ID. I think you could use the one from the vehicle instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about using the vehicle's route ID but decided not to because the vehicle's route may not actually be the currently selected route. This was silly, though, because buses will not spontaneously become trains. However, if the vehicle does not have a route assigned at all, it'd be nice if this button kept working; I'm not sure what conditions would cause that to happen, but there appear to currently be zero vehicles with no route, so it should be rare enough that we can get away with falling back to the stop filter route ID.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I wonder if it's possible for the vehicles to have a null route when coming from a garage or being in between routes. I ran into basically the same issue with the trip details card and created TripRouteAccents for just the general display related components of a route, maybe it's worth splitting that out into its own file and using it here too, though it seems much less risky in this case that someone will get confused and attempt to use the route for something that requires that it be the correct trip route.

}.frame(maxWidth: .infinity, alignment: .topTrailing)
}
if !searchObserver.isSearching, !viewportProvider.viewport.isOverview,
let (routeType, selectedVehicle, stop) = recenterOnVehicleButtonInfo() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes some weird behavior when you tap between single route+direction stops on the map, when the viewport is moving to the new stop overview, the vehicle recenter button flickers in for a second. Not certain why, but I think it might be when the old selected vehicle is still set but the viewport is set to the position of the new stop, before the auto trip filter has loaded and set the new vehicle, which sets the viewport to overview once it changes. You might be able to include a check that selectedVehicle.id == tripFilter.vehicleId?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That appears to work. Good catch.

@boringcactus boringcactus merged commit 511b016 into main Dec 12, 2024
7 checks passed
@boringcactus boringcactus deleted the mth-recenter-vehicle branch December 12, 2024 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants