Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MasterDetailPage Master page wont open with IsGestureEnabled set to false Xamarin.Forms Android

I have a master detail page operating on my app. The standard method for opening the master page is to either select the burger menu icon or slide from the left. One of my detail pages happens to use a carousel page. The swiping from the left can therefore either open the master page or slide the carousel to the left (rather irritating if the wrong event occurs).

In order to stop the Master page appearing when sliding from the left, I've set IsGestureEnabled to false. However this stops the Master Page from appearing at all. Despite their being haptic feedback when pressing the burger menu icon, it does nothing.

Is there a way to force the slide gesture to be ignored on a MasterDetailPage and not the tap gesture on the icon?

Here's a very simple app that has a MasterDetailPage and IsGestureEnabled set to false. The Master page will not open. https://www.dropbox.com/s/rkm5eph3vr38avm/MasterDetailPageTest.zip?dl=0

like image 430
Richard Pike Avatar asked Nov 03 '16 15:11

Richard Pike


1 Answers

I've come up with a bit of a workaround by creating a custom renderer for MasterDetailPage. It should suit my needs for now.

public class MyMasterDetailPageRenderer : Xamarin.Forms.Platform.Android.AppCompat.MasterDetailPageRenderer
{
    public override bool OnTouchEvent(MotionEvent e)
    {
        if (IsDrawerOpen(Android.Support.V4.View.GravityCompat.Start))
            return base.OnTouchEvent(e);
        else
        {
            if (e.Action == MotionEventActions.Up || e.Action == MotionEventActions.Down)
                return base.OnTouchEvent(e);
            else
            {
                CloseDrawers();
                return true;
            }
        }
    }
}

The assembly line needs to be added outside of the namespace:

[assembly: ExportRenderer(typeof(MyMasterDetailPage), typeof(MyMasterDetailPageRenderer))]

This doesn't completely solve the issue, but the master page does not open when swiping anymore.

like image 173
Richard Pike Avatar answered Oct 20 '22 16:10

Richard Pike