C# – fragment initialization sequence in mvvmcross 5 navigation service

I have questions about the navigation service introduced in mvvmcross 5

In version 4:

> I use Showviewmodel< viewmodel> () to navigate to the fragment > then call the Init method of ViewModel > then call the OnCreateView method of Fragment > where I can manipulate views based on ViewModel data (for example, add specific elements to the view).

In version 5:

>I wait for NavigationService. Navigate < ViewModel > () > first call oncreateview > of the fragment, followed by the initialize method of ViewModel. > when creating the fragment view, this will not end with ViewModel data

Is this an error or an asynchronous navigation function? If necessary, is there a better way to manipulate the fragment view based on ViewModel data?

resolvent:

This is the design, but has been revised since then (v5.0.4), see the flow changes below

Using v5.0.4 should produce the behavior you expect. It should be completed before the initialize() of ViewModel waits for the navigation service to complete and before starting the view life cycle event

MvvmCross v5.0.0 – v5.0.3

The behavior you see appears in mvvmcross 5.0.0-5.0.3. The process is as follows:

>ViewModel. Ctor > (select navigation call) init (parameter) (reflection is not recommended, but type safe initialization) > (selected navigation call) ViewModel. Reloadstate (savedstate) > (selected navigation call) ViewModel. Start() > beforenavigation (NavigationService event) > * viewdispatcher. Showviewmodel() (trigger view lifecycle) > * ViewModel. Initialize()) >Afternavigate (NavigationService event) > beforeclose (NavigationService event) > viewdispatcher. Changepresentation() > afterclose (NavigationService event)

MvvmCross v5.0.4

V5.0.4 improved the process and changed the navigation order:

>ViewModel. Ctor > beforenavigate (NavigationService event) > * ViewModel. Initialize() > init (parameter) (reflection is not recommended, but type safe initialize) > ViewModel. Reloadstate (savedstate) > ViewModel. Start() > * viewdispatcher. Showviewmodel() (trigger view lifecycle) > afternavigate (NavigationService event) > beforeclose (NavigationService event) > viewdispatcher. Changepresentation() > afterclose (NavigationService event)

Additional information

You can view the GitHub problem recorded in the navigation order (#1968). In addition, you can view the pull request of the initialization sequence of the updated version 5.0.4 (#1971)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>