xamarin/Xamarin.Forms

[Android] Adding both TapGestureRecognizer and ContextActions to ViewCell will result in ContextActions not responding

Aperta

#1932 aperta il 20 feb 2018

 (20 commenti) (0 reazioni) (0 assegnatari)C# (1926 fork)batch import
a/gestures 🖖a/listviewe/6 :clock6:help wantedp/Androidt/bug :bug:up-for-grabs

Metriche repository

Star
 (5644 stelle)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

Description

When working with ViewCells, adding ContextAction by itself will result in a successful build and expected functionality. However when both a TapGestureRecognizer and ContextActions is set on the same ViewCell, only the TapGestureRecognizer will respond and ContextActions no longer work.

A previous bug has been reported but apparently resolved:

https://bugzilla.xamarin.com/show_bug.cgi?id=46363

Steps to Reproduce

  1. Create a ViewCell with TapGestureRecognizer and ContextAction as so:

The following is a simple example that demonstrates the issue:

public class TableViewCellIssuePage : ContentPage
    {
        #region Constructors
        public TableViewCellIssuePage()
        {
           TapGestureRecognizer tap = new TapGestureRecognizer();
            ViewCell viewCell = new ViewCell()
            {
                View = new Label() { Text = "Cell" }
            };

            viewCell.ContextActions.Add(new MenuItem() { Text = "Never Shows" });

            // If you remove this gesture recognizer then the context action will work.
            viewCell.View.GestureRecognizers.Add(tap);

            this.Content = new StackLayout()
            {
                Children =
                {
                    new TableView()
                    {
                        Root = new TableRoot()
                        {
                            new TableSection()
                            {
                                viewCell
                            }
                        }
                    }
                }
            };
        }
        #endregion
    }

  1. Build and deploy application to Android or iOS Emulator
  2. Notice how long press does no respond while TapGestureRecognizer is. See commented code above to remove GestureRecognizer to have ContextActions work again.

Expected Behavior

Both TapGestureRecognizer and ContextActions should respond when both being added to a single ViewCell.

Actual Behavior

ContextActions do not respond when adding a TapGestureRecognizer to the same ViewCell.

Basic Information

Microsoft Visual Studio Enterprise 2017 Version 15.5.4 VisualStudio.15.Release/15.5.4+27130.2024 Microsoft .NET Framework Version 4.7.02556

Installed Version: Enterprise

Xamarin 4.8.0.757 (7f9ec2a) Xamarin.Android SDK 8.1.3.0 (HEAD/ef47226b7) Xamarin.iOS and Xamarin.Mac SDK 11.6.1.2 (6857dfc)

NUGET: Xamarin.Forms - 2.5.0.280555

Guida contributor