-
Notifications
You must be signed in to change notification settings - Fork 665
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
ViewModels reinitialize after view changes #50
Comments
Using So it could be a potential improvement, at least it's keeping things in place for me. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First of all, thanks for all the work put onto this project. I'm building a project based off of this and it's looking really good, but I am encountering some issues that I explain below.
To summarize:
ViewA
navigates toViewB
. To achieve this, I implement aNavigationLink(destination: ViewB(viewModel: ViewBViewModel()))
. When insideViewB
, some app state is modified, whichViewA
receives with aonReceive
. In theonReceive
callback,ViewA
makes some changes to its view like disabling a button. This causesViewA
to recalculate itself, which initializesViewBViewModel
again, losing all the changes, including all loaded data from the repository, leaving the user onViewB
with allLoadable
set to.notRequested
, and all viewModel state lost.This also happens if the app state is implemented through a
EnvironmentObject
. If I modify some environment object fromViewB
thatViewA
uses,ViewA
recreates itself, losing all the state onViewBViewModel
.I am also having some issues related to this when navigating back from a view to its predecessor. In some cases, if I navigate from some view
ViewA
to other viewViewB
, when dismissingViewB
,ViewA
gets recalculated, which initializesViewBViewModel
again.Has anyone encountered this behaviour and came to a solution?
The text was updated successfully, but these errors were encountered: