Bug 36832 - [Android] Handling Touch on a Cells Android.Views.View prevents tap animation and selection
Summary: [Android] Handling Touch on a Cells Android.Views.View prevents tap animation...
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.0.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Paul DiPietro [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2015-12-10 15:51 UTC by Michael Rumpler
Modified: 2017-09-07 21:10 UTC (History)
11 users (show)

Tags: ac, android, viewcell, listview, gestures
Is this bug a regression?: ---
Last known good build:


Attachments
repro project (59.35 KB, application/x-zip-compressed)
2015-12-10 15:51 UTC, Michael Rumpler
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 36832 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Michael Rumpler 2015-12-10 15:51:25 UTC
Created attachment 14224 [details]
repro project

Usually when you tap on a Cell in a ListView, then that cell is highlighted. Also while the finger is on the Cell, there is an animation around the touch. The ListItems ItemTapped and ItemSelected events are raised when an item was tapped.

If the Cell has a custom renderer which handles the Touch event, then the highlighting, animation, ItemTapped and ItemSelected don't work. This can easily be seen with this code in the renderer:

	public class MyViewCellRenderer : Xamarin.Forms.Platform.Android.ViewCellRenderer
	{
		protected override Android.Views.View GetCellCore(Cell item, Android.Views.View convertView, ViewGroup parent, Context context)
		{
			var view = base.GetCellCore(item, convertView, parent, context);
			view.Touch += (s, e) => { };    // do nothing - remove this line to make it work
			return view;
		}
	}

If you comment out the line with view.Touch, then it works.

Similarly if you don't use a custom renderer but a TapGestureRecognizer within a ViewCell, it does not work either. I expect the TapGestureRecognizer also handles Touch.

	<ListView ItemsSource="{Binding}" ItemTapped="ListItem_Tapped">
		<ListView.ItemTemplate>
			<DataTemplate>
				<ViewCell>
					<Label Text="{Binding}">
						<Label.GestureRecognizers>
							<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" />
						</Label.GestureRecognizers>
					</Label>
				</ViewCell>
			</DataTemplate>
		</ListView.ItemTemplate>
	</ListView>

ListItem_Tapped is never called in this example. If you comment out the Label.GestureRecognizers, then it works.

This happens on my Nexus 10 with Android 5.1.1 without AppCompat, but I heard from others who used different configurations and have the same problem.
Comment 1 Chris King 2017-01-04 17:44:10 UTC
Michael, trying to foresee (and test) all custom renderer permutations is challenging and so whenever possible we prefer to pull the missing functionality into our renderer. To that end, can you tell us why ItemTapped and\or ItemSelected do not fulfill your needs? If we cannot generalize it then we'll return to figuring a way to achieve your goal with a custom renderer. 

Warm regards,
XFT
Comment 2 Michael Rumpler 2017-01-05 13:14:04 UTC
ItemTapped only handles taps, but I want to handle all kinds of touch events like pan, swipe or long press. Therefore I need the Android.Views.MotionEvent which is part of the Android.Views.View.TouchEventArgs. I don't get those Android specific objects from the Xamarin.Forms event ItemTapped.
Comment 3 Pete 2017-02-07 23:11:16 UTC
I also am trying to handle Swipe events in the Xamarin Forms ListView, and running into this same issue.
Comment 4 Florian Marchal 2017-03-15 10:25:34 UTC
This Android issue also makes my "ItemSelected" event of my ListView to not be triggered because of the touch gestures I have set on my ViewCell.
The workaround is to bind your "itemSelected" command on the "Tapped" or the "Down" event of the ViewCell.
Comment 5 Paul DiPietro [MSFT] 2017-03-20 04:47:22 UTC
The reproduction still behaves the same as of the latest 2.3.5.71-nightly -- I'll try to get some attention on this issue and get feedback from other team members.