Xamarin.forms: [Bug] [Android] SwipeView used in a CollectionView fires the SelectionChangedCommand unintentionally

Created on 1 Sep 2020  路  2Comments  路  Source: xamarin/Xamarin.Forms

Description

On Android (as of XF 4.7 and still in XF 4.8 sr1), using a SwipeView as a root container for a CollectionView DataTemplate, if the CollectionView uses the SelectionChangedCommand and the content of the SwipeView (ItemSource bound to a list of viewmodels) has some element (eg Button) with a command responding to the user tapping, the tap on that element improperly fires the SelectionChangedCommand on the CV (either completely ignoring the element tapped or firing both the element command and the CV SelectionChangedCommand).
See attached sample project.

Steps to Reproduce

  1. Have a CollectionView using a SelectionChangedCommand, also bind its ItemSource to a viewmodel that has a command to be later bound to an interactive element such as a button, etc...
  2. As its DataTemplate root element use a SwipeView.
  3. Inside the SwipeView add an input element such as a Button and bind that to the command in the viewmodel.

Expected Behavior

When the element inside the SwipeView is tapped you would expect to just fire the command of the viewmodel just like when you do not have a SwipeView, but most importantly you would not expect the SelectionChangedCommand of the CV to be fired at all.

Actual Behavior

The SelectionChangedCommand is always fired. Also, the button Command is not always fired (it seems to be fired if you tap on the rightmost side).

Basic Information

  • Version with issue: XF 4.7, still happens in XF 4.8 sr1
  • Last known good version: N/A
  • IDE: Visual Studio Pro for Mac 8.7.4
  • Platform Target Frameworks:

    • Android: tested on Android 9 and 10.

Reproduction Link

Attached sample project (in MainPage.xaml comment/uncomment with/without SwipeView to see the two behaviours)
SwipeViewBug1.zip

Workaround

Using the SwipeView not as a DataTemplate root element but as a child element that is contained inside a Grid/etc... seems to solve the problem, but it is not ideal.

collectionview swipeview blocker 5 in-progress Android bug

Most helpful comment

@inimirpaz Thanks for the example where to reproduce the issue!. I have sent a PR with the fix: https://github.com/xamarin/Xamarin.Forms/pull/12736

All 2 comments

I am seeing the same thing on a Pixel 3 emulator (api 28). If I use a Pixel 3a emulator (api 28), the problem of a command inside the swipeview (like a button) not firing is a non-issue.

I was not able to work around this by making the swipeview a child to a grid element.

The bigger issue for me is that the button inside of the swipeview doesn't fire its command when tapped. In the emulator if I click in a very specific column of pixels on the button, then I can get it to fire the command.

@inimirpaz Thanks for the example where to reproduce the issue!. I have sent a PR with the fix: https://github.com/xamarin/Xamarin.Forms/pull/12736

Was this page helpful?
0 / 5 - 0 ratings