Prism icon indicating copy to clipboard operation
Prism copied to clipboard

[XF] Determine how a VM was navigated to

Open brianlagunas opened this issue 10 years ago • 15 comments

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.

brianlagunas avatar Nov 22 '16 20:11 brianlagunas

Might be good to also call the INavigationAware methods when the app is going to sleep and being resumed.

brianlagunas avatar Nov 23 '16 00:11 brianlagunas

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.

brianlagunas avatar Nov 23 '16 00:11 brianlagunas

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?

brianlagunas avatar Nov 23 '16 01:11 brianlagunas

Much better practice to have granular interfaces.

IApplicationLifecycle is my vote.

Best,

Karl

ghost avatar Nov 23 '16 01:11 ghost

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

alexjacostal avatar Nov 23 '16 02:11 alexjacostal

I'd like to vote for the granular approach as well.

timahrentlov avatar Nov 23 '16 07:11 timahrentlov

IApplicationLifecycle has my vote too.

nicolaiarocci avatar Nov 23 '16 08:11 nicolaiarocci

Totally agree. Great stuff!! .

StanleyBroo avatar Nov 23 '16 09:11 StanleyBroo

Agree with Karl, IAppLifecycle provides better granularity. My vote goes to it.

corradocavalli avatar Nov 23 '16 10:11 corradocavalli

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?

thomashagstrom avatar Nov 23 '16 12:11 thomashagstrom

IApplicationLifeCycle +1

Willjobs94 avatar Nov 23 '16 13:11 Willjobs94

For me, the IAppLifecycle approach is the natural way to handle Application Life Cycle... IAppLifecycle +1

angelobelchior avatar Nov 23 '16 19:11 angelobelchior

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.

mackayn avatar Nov 24 '16 11:11 mackayn

Thanks for all the feedback. this has been implemented in PR #852

brianlagunas avatar Nov 24 '16 16:11 brianlagunas

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.

lock[bot] avatar Jan 30 '20 20:01 lock[bot]