The49.Maui.BottomSheet icon indicating copy to clipboard operation
The49.Maui.BottomSheet copied to clipboard

dismissing with the left swipe gesture on android does not close the modal dialog (HasBackdrop is true)

Open softlion opened this issue 1 year ago • 1 comments

Dismissing with the left swipe gesture on android does not close the dialog (HasBackdrop is set to true).

Instead it triggers a back on the page displayed behind the dialog, which is not expected.

On normal content page, you can ovveride OnBackButtonPressed like this:

        protected override bool OnBackButtonPressed()

But that is unavailable on BottomSheet because it's a contentview not a contentpage.

Note that using the hardware back button on older Android versions also triggers OnBackButtonPressed().

softlion avatar Apr 03 '24 07:04 softlion

I worked around by creating a dummy transparent page on android and intercept the back button there.

I implemtented something better than that, but you get the idea:

#if ANDROID
        var page = new DummyPage();
        page.OnBackButtonPressedEvent += (_,_) => {
             await popup.DismissAsync();
        };

        await navigation.PushModalAsync(page, false);
        await popup.ShowAsync(page.Window!);

//I'm awaiting a TaskCompletionSource object here. to detect when the popup is closed by any mean.
...
        //Time to close the dummy page too
        await navigation.PopModalAsync(false);
...


public class DummyPage : ContentPage
{
   public event EventHandler<EventArgs> OnBackButtonPressedEvent;

     public DummyPage()
    {
        BackgroundColor = Colors.Transparent;
    }
    
    /// <summary>
    /// For android back button
    /// </summary>
    protected override bool OnBackButtonPressed()
    {
        OnBackButtonPressedEvent?.Invoke(this, EventArgs.Empty);
        return true;
    }
}
#endif

softlion avatar Apr 03 '24 08:04 softlion