Allow a single place to handle back button requests with Async support

kaelkael ZAMember
edited July 2017 in Xamarin.Forms

Summary

Currently there are different ways to handle the back button request (understandable), but for example on Android one must handle the hardware and software button separably(software one is a bit hacky). Can we look into a possible solution to bring all these into one callback? i.e. App.cs OnBackButton event or virtual method.

API Changes

A addition of a virtual Task of bool method on App.cs

protected override Task OnBackButtonAsync(BackButtonArgs args)
{
return OnBackButtonAsync(args);
}

Or a Request page Pop method on on App.cs

protected override Task OnPagePoppingAsync(Page page)
{
return OnPagePoppingAsync(page);
}

Intended Use Case

To check if there are any unsaved changes on a page by either method :

protected override async Task OnBackButtonAsync(BackButtonArgs args)
{
var page = Args.Page;

    var viewmodel = page.BindingContext as Viewmodel;

    var result = await viewmodel.CheckUnSavedChangesAsync();

    return result ;
    }

Or a Request page Pop method on on App.cs

protected override async Task OnPagePoppingAsync(Page page)
{
var viewmodel = page.BindingContext as Viewmodel;

    var result = await viewmodel.CheckUnSavedChangesAsync();

    return result ;
    }
Tagged:

Open · Last Updated

Posts

Sign In or Register to comment.