ListView ItemTapped/ItemSelected is triggered when dragging the side panel of a MasterDetailPage RRS feed

  • Question

  • User395811 posted


    we upgraded Xamarin Forms iOS from 4.2 to 4.7 and observed the following behaviour change in MasterDetailPage:

    We have a MasterDetailPage. Master is a side panel with menu items and in Detail there is a NavigationPage with a list view.

    In Forms 4.2, when the list view in Detail is visible, we could drag with the finger on the screen from left to right to drag the side panel into the screen. When we lift the finger up from the screen, the side panel will be presented fully. We can drag the side panel back again without triggering the itemTapped/itemSelected of the listview in the Detail Screen.

    In Forms 4.7, when we drag with the finger on the list view from left to right and then lift the finger up from the screen, the itemTapped/itemSelected is triggered of the listview for the item where the finger was touched. That's bad. Everytime when I drag in the side panel, I activate an list item and you see the animation to the next page on right area of the screen.

    This behaviour is not desired and I think this is a bug, or? Is there a workaround for it, with CustomRenderers?

    On Android, this is not a problem. The side panel can be dragged in by dragging from the left edge to the right without triggering the itemselected of the list view. This works in Forms 4.2 and 4.7.

    Best regards, Mario

    Friday, July 17, 2020 7:17 PM

All replies

  • User395811 posted

    After lots of testing and analyzing the source code of Xamarin Forms MasterDetailPage, I found now a workaround by writing a custom renderer for iOS phone. I have to set the property "CancelsTouchesInView" of the UIPanGestureRecognizer to "true", so that the touches are not pass through to the underlying listview when panning the side panel.

    ``` using System.Linq; using System.Text; using UIKit; using Xamarin.Forms; using Xamarin.Forms.Platform.iOS; using ETA.iOS; using Foundation;

    [assembly: ExportRenderer(typeof(MasterDetailPage), typeof(CustomMasterDetailRenderer))] namespace ETA.iOS { internal class CustomMasterDetailRenderer : PhoneMasterDetailRenderer { protected override void OnElementChanged(VisualElementChangedEventArgs e) { base.OnElementChanged(e);

            if (NativeView != null && NativeView.GestureRecognizers.Count() > 0 && NativeView.GestureRecognizers[0] != null)
                NativeView.GestureRecognizers[0].CancelsTouchesInView = true;

    } ```

    If there is a better solution for my problem please post it here.

    Can a Xamarin Forms developer please check why this CancelsTouchsInView is set to "false" in PhoneMasterDetailRenderer.cs?

    Sunday, July 19, 2020 7:55 PM