Open yamir-godil opened 1 year ago
Still reproduce
I assume you use Transitions API, there is a known bug that cause this. https://github.com/adrielcafe/voyager/issues/106
In the latest 1.1.0-beta02
we have introduce a new experimental API that make the ScreenTransition handle disposing, this should be fixed by providing disposeScreenAfterTransitionEnd = true
.
Checkout the docs for more details. https://voyager.adriel.cafe/transitions-api/
Background I'm seeing an issue with pressing back on all my voyager screens which have transitions. I have a SlideTransition for my navigator, so the composable
Content
function is called several times both on pushing and popping of screens.Issue I've noticed that during the last stage of the transition, I get a new instance of the view model because Voyager clears out the lifecycle store in
onDispose
. This causes my view model to trigger a network load call to fetch data on a back press transition.Here's how my code is set up:
I see this log statements when I press back from this child screen to the parent screen:
Upon investigation, I see that the local view model store owner actually has the view model reference that Koin returns but upon back press, Voyager navigator clears out the store in its dispose, which causes Koin to return a new view model instance. This causes the side effect of my view model to trigger a data load
How to handle this? I can put a short circuit by checking the navigator's lastItem and returning from the composable if the screen's don't match but that is not scalable as it would cause each screen to have this hack. It also doesn't animate properly when back is pressed with this workaround
To me this is a bug in Voyager, as it should call dispose only when transition ends.