question

AbrahamJohn-8020 avatar image
0 Votes"
AbrahamJohn-8020 asked viktorkalder-6663 published

Disable Xamarin Shell Flyout swipe gesture.

I'm using Flyout page using Shell. My home page is a carouselview page. Some times when we swipe the carouselview right, the Flyout page appears. Is there any way to disable swipe gesture for Flyout page so that carouselview can be swiped without any disturbance?

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ColeXia-MSFT avatar image
0 Votes"
ColeXia-MSFT answered AbrahamJohn-8020 commented

Hello,

Welcome to Microsoft Q&A!

We can disable the swipe gesture in custom renderer , but it may need to use Reflection to seek private property.

iOS Solution


[assembly: ExportRenderer(typeof(AppShell), typeof(iOSShellRenderer))]
    namespace TestMenuSwipe.iOS
    {

                    public class iOSShellRenderer : ShellRenderer
                    {
                                    IShellFlyoutRenderer flyoutRenderer;

                                    protected override IShellFlyoutRenderer CreateFlyoutRenderer()
                                    {
                                                    flyoutRenderer = base.CreateFlyoutRenderer(); 
                                                    return flyoutRenderer;
                                    }

                                    public override void ViewWillAppear(bool animated)
                                    {
                                                    base.ViewWillAppear(animated);
                                                    var type = flyoutRenderer.GetType();
                                                    var property = type.GetProperty("PanGestureRecognizer", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                                                    var value = property.GetValue(flyoutRenderer);

                                                    UIPanGestureRecognizer recognizer = value as UIPanGestureRecognizer;
                                                    recognizer.Enabled = false;


                                    }
                    }
    }

Android Solution


[assembly: ExportRenderer(typeof(AppShell), typeof(AndroidShellRenderer))]
    namespace TestMenuSwipe.Droid
    {
                    public class AndroidShellRenderer : ShellRenderer
                    {

                                    public AndroidShellRenderer(Context context) : base(context)
                                    {                                              
                                    }

                                    protected override IShellFlyoutRenderer CreateShellFlyoutRenderer()
                                    {
                                                    var flyoutRenderer = base.CreateShellFlyoutRenderer();
                                                    flyoutRenderer.AndroidView.Touch += AndroidView_Touch;                                        
                                                    return flyoutRenderer;
                                    }

                                    private void AndroidView_Touch(object sender, Android.Views.View.TouchEventArgs e)
                                    {
                                                    if (e.Event.Action == MotionEventActions.Move)
                                                                    e.Handled = true;
                                                    else
                                                                    e.Handled = false;
                                    }
                    }
    }


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks.

It'll be very helpful if there is a simple statement such as SwipeGesture="False". Hope to see it in future updates.

2 Votes 2 ·
jeanie77 avatar image
0 Votes"
jeanie77 answered jeanie77 edited

@ColeXia-MSFT

I have the same problem (I guess), but the suggested solution doesn't disable swipe between tabs.
Here is my AppShell content with the suggested renderer:

 <?xml version="1.0" encoding="UTF-8"?>
 <Shell xmlns="http://xamarin.com/schemas/2014/forms" 
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        x:Class="com.company.AppShell"
        ...> 
    
     <!-- tabbed topbar -->
     <FlyoutItem Title="Routes" Icon="maps.png">
         <Tab>
             <ShellContent Title="Summary"
                           ContentTemplate="{DataTemplate views:SummaryPage}" Route="SummaryPage" />
             <ShellContent Title="Directions"
                           ContentTemplate="{DataTemplate views:DirectionsPage}" />
         </Tab>
     </FlyoutItem>
    
     <MenuItem Text="Logout" Icon="logout.png" Clicked="onLogoutClicked" />
    
 </Shell>


Updated:
I tried to follow these guidelines to override CreateShellSectionRenderer in the suggested Shell renderer, but I don't know where to attach the Touch event, in order to disable swipe between section contents. Could you please provide a sample, if this is supported? Thank you.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

jeanie77 avatar image
0 Votes"
jeanie77 answered

anybody there?...

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

viktorkalder-6663 avatar image
0 Votes"
viktorkalder-6663 answered viktorkalder-6663 published

<ContentPage
.....
Shell.FlyoutBehavior="Disabled"
....
/>

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.