Reputation: 84744
It appears that MvxTabsFragmentActivity
does not call the Init()
method on fragment view models as the tab is selected (nor at all). This was confirmed by taking a look at the source for MvxTabsFragmentActivity.
This is slightly annoying since it breaks the Init / Start model that view models are meant to implement (if they are to remain unaware that they are being used as tabs).
What is the recommended pattern around handling initialization (and other life-cycle stages for that matter) for view models that are used with tag fragments?
Upvotes: 0
Views: 229
Reputation: 66882
The MvxTabsFragmentActivity
works on pre-built view models - the ViewModel is passed to it using APIs like:
protected void AddTab<TFragment>(string tagAndSpecName, string tabName, Bundle args,
IMvxViewModel viewModel)
The responsibility of creating ViewModel's is the caller - if the caller uses new
to create them, then Init()
and Start()
won't be called. If the caller uses IMvxViewModelLoader.Load()
then Init()
and Start()
will be called.
Upvotes: 1