-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix(Android): reset nearby transit state on pan/recenter #635
Merged
+35
−12
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4edcb83
fix(Android): reset nearby transit state on pan/recenter
boringcactus b461a63
only reset predictions if actually needed
boringcactus 07ba4c5
Merge branch 'main' into mth-android-reset-nearby
boringcactus 27c34a5
expose PredictionsViewModel directly for explicit resets
boringcactus 4d6e2b3
Merge branch 'main' into mth-android-reset-nearby
boringcactus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ import com.mbta.tid.mbta_app.android.map.IMapViewModel | |
import com.mbta.tid.mbta_app.android.map.MapViewModel | ||
import com.mbta.tid.mbta_app.android.nearbyTransit.NearbyTransitTabViewModel | ||
import com.mbta.tid.mbta_app.android.nearbyTransit.NearbyTransitView | ||
import com.mbta.tid.mbta_app.android.nearbyTransit.NearbyTransitViewModel | ||
import com.mbta.tid.mbta_app.android.nearbyTransit.NoNearbyStopsView | ||
import com.mbta.tid.mbta_app.android.search.SearchBarOverlay | ||
import com.mbta.tid.mbta_app.android.state.subscribeToVehicles | ||
|
@@ -64,6 +65,7 @@ import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.FlowPreview | ||
import kotlinx.coroutines.flow.debounce | ||
import kotlinx.coroutines.launch | ||
import org.koin.androidx.compose.koinViewModel | ||
import org.koin.compose.koinInject | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
|
@@ -216,6 +218,8 @@ fun NearbyTransitPage( | |
} | ||
} | ||
composable<SheetRoutes.NearbyTransit> { | ||
// for ViewModel reasons, must be within the `composable` to be the same instance | ||
val nearbyViewModel: NearbyTransitViewModel = koinViewModel() | ||
LaunchedEffect(true) { | ||
if (!navBarVisible) { | ||
showNavBar() | ||
|
@@ -234,13 +238,13 @@ fun NearbyTransitPage( | |
} | ||
LaunchedEffect(nearbyTransit.viewportProvider.isManuallyCentering) { | ||
if (nearbyTransit.viewportProvider.isManuallyCentering) { | ||
// TODO reset view model | ||
nearbyViewModel.reset() | ||
Comment on lines
-237
to
+241
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love a good TODO -> done |
||
targetLocation = null | ||
} | ||
} | ||
LaunchedEffect(nearbyTransit.viewportProvider.isFollowingPuck) { | ||
if (nearbyTransit.viewportProvider.isFollowingPuck) { | ||
// TODO reset view model | ||
nearbyViewModel.reset() | ||
targetLocation = null | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally, I had
nearbyViewModel: NearbyTransitViewModel = koinViewModel()
as an argument toNearbyTransitPage
, but since navigation states can own ViewModels, callingkoinViewModel()
outside thiscomposable
creates a different instance than the one that's created as an argument inNearbyTransitView
, but calling it here gives the same instance. This was absolutely miserable to try to debug.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is tricky. To clarify my own understanding, that would be an issue even if we weren't using koin and were instantiating the view models directly, is that right? I haven't been using koinViewModel regularly, and wondering about differences / benefits we get with it aside from test defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that this is inherent to the Android ViewModel subsystem and not specific to Koin's integration with it. My understanding is that using
koinViewModel
lets us pass repositories via Koin into the ViewModel without having to define a customViewModelProvider.Factory
or deal withCreationExtras
.