Disable Xamarin Shell Flyout swipe gesture.

Abraham John 111 Reputation points
2021-03-09T20:08:08.46+00:00

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?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,297 questions
0 comments No comments
{count} votes

Accepted answer
  1. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,751 Reputation points
    2021-03-10T02:15:57.517+00:00

    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.


3 additional answers

Sort by: Most helpful
  1. jeanie77 1 Reputation point
    2021-08-25T10:29:00.543+00:00

    @Cole Xia (Shanghai Wicresoft Co,.Ltd.)

    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.

    0 comments No comments

  2. jeanie77 1 Reputation point
    2021-09-15T14:07:13.297+00:00

    anybody there?...

    0 comments No comments

  3. viktor kalder 1 Reputation point
    2021-12-03T17:55:47.683+00:00

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

    0 comments No comments