xamarin/Xamarin.Forms

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

Ouverte

#1 932 ouverte le 20 févr. 2018

 (20 commentaires) (0 réaction) (0 personne assignée)C# (1 926 forks)batch import
a/gestures 🖖a/listviewe/6 :clock6:help wantedp/Androidt/bug :bug:up-for-grabs

Métriques du dépôt

Stars
 (5 644 étoiles)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

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

Guide contributeur