Skip to content

TapGestureRecognizer on GraphicsView causes a crash on Android devices #34296

@Tim-Rasmussen

Description

@Tim-Rasmussen

Description

A TapGestureRecognizer attached to a GraphicsView can cause an Android app to crash when the GraphicsView is tapped. This started to occur in Microsoft.Maui.Controls version 10.0.40 and occurs in 10.0.41 as well (version 10.0.31 worked fine).

It only seems to be an issue on physical Android devices (e.g. Samsung Galaxy A10 with Android 11, Nokia 310 with Android 10) and not on Android emulators. iOS devices and Windows seem unaffected by the issue.

Steps to Reproduce

  1. Create a new .NET MAUI App.
  2. Create a simple GraphicsView, e.g.
public partial class CircularGraphicsView : IDrawable
{
	public void Draw(ICanvas canvas, RectF rectangle)
	{
		float size = Math.Min(rectangle.Width, rectangle.Height);
		float radius = size / 2;
		PointF centre = new(radius, radius);

		// Draw a filled circle
		canvas.FillColor = Colors.Purple;
		canvas.FillCircle(centre, radius);
	}
}
  1. Replace the contents of the MainPage.xaml with the simple GraphicsView and attach a TapGestureRecognizer, e.g.
	<Grid BackgroundColor="White">
		<VerticalStackLayout>
			<GraphicsView Drawable="{Binding CircularGraphicsView}" WidthRequest="100" HeightRequest="100" Margin="0,0,1,0">
				<GraphicsView.GestureRecognizers>
					<TapGestureRecognizer Tapped="CircularGraphicsView_Tapped" NumberOfTapsRequired="1" />
				</GraphicsView.GestureRecognizers>
			</GraphicsView>
		</VerticalStackLayout>
	</Grid>
  1. Add a TapGestureRecognizer event handler in MainPage.xaml.cs (which won't be called because the app crashes when the GraphicsView is tapped).

Expected behaviour: the TapGestureRecognizer event handler should be called when the GraphicsView is tapped.
Actual behaviour: the app crashes.

Link to public reproduction project repository

https://github.com/Tim-Rasmussen/GraphicsViewTapGestureRecognizer.git

Version with bug

10.0.40

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

10.0.30

Affected platforms

Android

Affected platform versions

We've only been able to test on Android 11 and 10 devices but it may happen on later versions.

Did you find any workaround?

The workaround is to use the GrahicsView StartInteraction event in place of the TapGestureRecognizer but the latter event seems to fire later than the former which makes the workaround unusable in our commercial app which has GraphicsViews within a CollectionView (each CollectionView item has an attached TapGestureRecognizer which fires before the GraphicsView StartInteraction event but we need to intercept the GraphicsView being tapped).

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-drawingShapes, Borders, Shadows, Graphics, BoxView, custom drawingi/regressionThis issue described a confirmed regression on a currently supported versionplatform/androidregressed-in-10.0.40s/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions