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: reset nearby transit scroll position #116

Merged
merged 1 commit into from
Apr 12, 2024

Conversation

BrandonTR
Copy link
Contributor

Summary

Ticket: Nearby Transit scroll position shouldn't always persist

Reset the nearby transit scroll position when the map is panned or the app returns from the background. The solution isn't entirely ideal. I would've liked to use a PassthroughSubject so that we don't have to clear a state after it is consumed but since NearbyTransitView is re-initialized several times a second the .onReceive modifier was not getting the ID from the publisher. There was also an issue where the .top anchor was not actually scrolling to the top of the view but a custom UnitPoint does.

Testing

Added ViewInspector unit tests to ensure scrollPosition is being set when expected.

@BrandonTR BrandonTR requested a review from a team as a code owner April 5, 2024 20:22
@BrandonTR BrandonTR requested a review from KaylaBrady April 5, 2024 20:22
@@ -63,6 +65,7 @@ struct NearbyTransitView: View {
leavePredictions()
} else if newPhase == .active {
joinPredictions()
scrollToTop()
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems that this will scrollToTop whether or not the list of nearby routes has changed. Based on the AC, we only need to reset the scroll position if the list of routes has changed. That way, if I scroll to the bottom of the list to see the redline, background the app to check my texts quickly, then come back to the app, it will still be scrolled to the bottom (unless the list of routes has been reordered/changed).

Can this function call depend on the list of routes changing rather than the location + backgrounding?

@@ -21,31 +21,27 @@ struct NearbyTransitView: View {
@ObservedObject var scheduleFetcher: ScheduleFetcher
@ObservedObject var predictionsFetcher: PredictionsFetcher
@ObservedObject var alertsFetcher: AlertsFetcher
@State var nearbyWithRealtimeInfo: [StopAssociatedRoute]?
Copy link
Collaborator

Choose a reason for hiding this comment

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

question (non-blocking): For my own learning, why move this to state?

Copy link
Contributor Author

@BrandonTR BrandonTR Apr 10, 2024

Choose a reason for hiding this comment

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

Before we were doing this association with every render of the view and if we store the value this way we don't need to re-run the association with realtime info every render, only when one of the onChange/onReceive modifiers triggers it. Just a small optimization

Note: using the `.top` anchor does not actually bring you to the top
of the view as expected but using this custom UnitPoint does
*/
proxy.scrollTo(id, anchor: UnitPoint(x: 0, y: -1))
Copy link
Collaborator

@KaylaBrady KaylaBrady Apr 10, 2024

Choose a reason for hiding this comment

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

question (non-blocking): I notice that when the sheet is at the small detent and I pan the map, I sometimes get stuck scrolled to the top item with the route out of view. Is there a straightforward fix? I don't think fixing that needs to block merging this PR, but maybe worth a check with product about fixing as a follow-up if it seems non-trivial to do.
https://github.com/mbta/mobile_app/assets/31781298/a6ad3535-4e86-43ba-9ed1-c6824fff70f8

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very strange that this is happening only for the small detent. I tried a few things to see if I can mitigate this but I think this is ultimately a bug with SwiftUI. I enabled the grabber on the sheet for now so users won't get stuck. Gonna ping the team channel about this

@BrandonTR BrandonTR force-pushed the br-nearby-transit-scroll-reset branch 4 times, most recently from 3d04cd1 to 9636b92 Compare April 12, 2024 13:20
@BrandonTR BrandonTR force-pushed the br-nearby-transit-scroll-reset branch from 9636b92 to df7fe98 Compare April 12, 2024 13:43
@BrandonTR BrandonTR merged commit 3338e4f into main Apr 12, 2024
5 checks passed
@BrandonTR BrandonTR deleted the br-nearby-transit-scroll-reset branch April 12, 2024 14:11
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