Xamarin Forms Exrin Framework pushing a container as a Modal?

237 Views Asked by At

I've been playing with the Exrin Xamarin Forms framework which I'm liking.

I've come to a blocker where I want to push a container as a Modal. Anyone know any tips on how to do this? I can't find any examples, or a best approach on how to push a container as Modal.

Looking at the Exrin code, might have to change BaseStack.cs, create a NavigationModal ResultType, lifestyle so it doesn't affect already in memory containers, etc...?

Any other ideas?

1

There are 1 best solutions below

4
On BEST ANSWER

The idea behind Exrin and its Stacks, is that a Modal wouldn't be needed. The only reason for Modals, is for a page that you can't just press back from and sits on top of the existing page.

The recommended approach here, is to create a new Stack and just navigate to that. Then go back to the previous stack once finished. It behaves the same way as a Modal, but you don't need to actually use a Modal.

Update

If you must have a Modal, while other ways to support transitions come into play, you can modify your NavigationProxy. Replace the 2 functions below.

 public async Task PopAsync()
    {
        if (_page.Navigation.ModalStack.Count > 0)
        {
            var page = _page.Navigation.ModalStack[0];
            _page_Popped(null, new NavigationEventArgs(page));
            await _page.Navigation.PopModalAsync();

        }
        else
            await _page.PopAsync();
    }

    public async Task PushAsync(object page)
    {
        var xamarinPage = page as Page;

        if (xamarinPage == null)
            throw new Exception("PushAsync can not push a non Xamarin Page");

        if (page is ExrinSample.View.AboutView)
            await _page.Navigation.PushModalAsync(xamarinPage);
        else
            await _page.PushAsync(xamarinPage);
    }

Of course this is manually referencing a specific page in your proxy. If you wanted to clean that up, you could add some methods in your Stack to list pages that are modal, and use that list to push to modal if needed, rather than directly putting the page names inside the proxy.