[XF] Determine how a VM was navigated to
It would be nice if I could determine how a VM was navigated to. I would like to be able to check a known parameter in the NavigationParameters in the INavigationAware methods to see if I was navigating forward, or back.
Might be good to also call the INavigationAware methods when the app is going to sleep and being resumed.
Should I use the INavigationAware methods and just pass the NavigationMode in the params, or should I create a new interface like IApplicationLifecycleAware with OnResume and OnSleep? I'm not sure which direction to go here.
If I reuse the INavigationAware methods, then everytime you suspend and resume the methods will be invoked and you would have to always check the NavigationMode in order to control what code gets executed:
public void OnNavigatingTo(NavigationParameters parameters)
{
var navigationMode = parameters.GetNavigationMode();
if (navigationMode == NavigationMode.Back)
Title = "Went Back";
else if (navigationMode == NavigationMode.New)
Title = "Went to New Page";
else if (navigationMode == NavigationMode.Sleep)
Title = "App when to sleep";
else if (navigationMode == NavigationMode.Resume)
Title = "App resumed";
}
This might get a little annoying. I am thinking that maybe we do not mix navigation concepts with application lifecycle events. Instead have this:
public interface IAppLifecycle
{
void OnSleep();
void OnResume();
}
This will allow the developer to handle these specific application lifecycle events separately.
Thoughts?
Much better practice to have granular interfaces.
IApplicationLifecycle is my vote.
Best,
Karl
My vote is for the IApplicationLifecycle, it is a pattern that is needed regularly and very useful, and most probably it gonna be use in one or two sites and not in all the VM that use the inavaware
I'd like to vote for the granular approach as well.
IApplicationLifecycle has my vote too.
Totally agree. Great stuff!! .
Agree with Karl, IAppLifecycle provides better granularity. My vote goes to it.
how would this work in relation to the app lifecycle? Some kind of deep linking?
Otherwise I would just listen to App.OnResume and navigate to the appropriate (last viewed) page?
IApplicationLifeCycle +1
For me, the IAppLifecycle approach is the natural way to handle Application Life Cycle...
IAppLifecycle +1
IApplicationLifecycle gets my vote.
Knowing the direction of navigation would be good, I haven't tested but sometimes OnAppearing fires when you pop the device dialer or mail client, it's been inconsistent in Forms since I started with Forms 1.3. I currently check if certain parameters exist to determine who called the page.
Thanks for all the feedback. this has been implemented in PR #852
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.