xamarin/Xamarin.Forms

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

开放

#1,932 创建于 2018年2月20日

 (20 条评论) (0 个反应) (0 位负责人)C# (1,926 个派生)batch import
a/gestures 🖖a/listviewe/6 :clock6:help wantedp/Androidt/bug :bug:up-for-grabs

仓库指标

星标
 (5,644 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

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

贡献者指南