Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue34296.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 34296, "TapGestureRecognizer on GraphicsView causes a crash on Android devices", PlatformAffected.Android)]
public class Issue34296 : ContentPage
{
readonly Label _statusLabel;
int _tapCount;

public Issue34296()
{
_statusLabel = new Label
{
AutomationId = "Issue34296StatusLabel",
Text = "TapCount:0"
};

var graphicsView = new GraphicsView
{
AutomationId = "Issue34296GraphicsView",
WidthRequest = 200,
HeightRequest = 200,
Drawable = new Issue34296Drawable(),
BackgroundColor = Colors.Transparent
};

var tapGesture = new TapGestureRecognizer
{
NumberOfTapsRequired = 1
};

tapGesture.Tapped += OnGraphicsViewTapped;
graphicsView.GestureRecognizers.Add(tapGesture);

Content = new VerticalStackLayout
{
Padding = new Thickness(20),
Children =
{
_statusLabel,
graphicsView
}
};
}

void OnGraphicsViewTapped(object sender, TappedEventArgs e)
{
#if ANDROID
if (sender is GraphicsView graphicsView &&
graphicsView.Handler?.PlatformView is Microsoft.Maui.Platform.PlatformTouchGraphicsView platformView)
{
platformView.TouchesBegan(Array.Empty<PointF>());
platformView.TouchesMoved(new[] { new PointF(10, 10) });
}
#endif
Comment on lines +53 to +54
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This page is intended to exercise the specific Android crash path by calling TouchesBegan(Array.Empty<PointF>()) followed by TouchesMoved(...). Right now, if graphicsView.Handler/PlatformView isn’t the expected PlatformTouchGraphicsView for any reason, the test will still pass and won’t actually validate the fix. Consider making this explicit (e.g., update the status label to an error state or throw in DEBUG when the platform view isn’t found) so the UITest can fail if the reproduction path wasn’t executed.

Suggested change
}
#endif
}
else
{
#if DEBUG
throw new InvalidOperationException("Issue34296: Expected PlatformTouchGraphicsView as PlatformView but it was not found.");
#else
_statusLabel.Text = "Error: PlatformTouchGraphicsView not found";
return;
#endif
}
#endif

Copilot uses AI. Check for mistakes.

_tapCount++;
_statusLabel.Text = $"TapCount:{_tapCount}";
}
}

class Issue34296Drawable : IDrawable
{
public void Draw(ICanvas canvas, RectF dirtyRect)
{
var size = Math.Min(dirtyRect.Width, dirtyRect.Height);
var radius = size / 2;
var center = new PointF(radius, radius);

canvas.FillColor = Colors.Purple;
canvas.FillCircle(center, radius);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue34296 : _IssuesUITest
{
public override string Issue => "TapGestureRecognizer on GraphicsView causes a crash on Android devices";

public Issue34296(TestDevice device) : base(device)
{
}

[Test]
[Category(UITestCategories.GraphicsView)]
public void TapGestureOnGraphicsViewShouldNotCrash()
{
App.WaitForElement("Issue34296StatusLabel");
App.WaitForElement("Issue34296GraphicsView");

App.Tap("Issue34296GraphicsView");
App.WaitForElement("Issue34296StatusLabel");

App.Tap("Issue34296GraphicsView");

Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To reduce UI test flakiness, consider waiting for the label to reach the expected value after the second tap (e.g., WaitForTextToBePresentInElement on Issue34296StatusLabel with TapCount:2) before calling GetText() and asserting. Reading immediately after App.Tap can race the UI update on slower devices.

Suggested change
App.WaitForTextToBePresentInElement("Issue34296StatusLabel", "TapCount:2");

Copilot uses AI. Check for mistakes.
var statusText = App.FindElement("Issue34296StatusLabel").GetText();
Assert.That(statusText, Is.EqualTo("TapCount:2"));
}
}
2 changes: 1 addition & 1 deletion src/Core/src/Platform/Android/PlatformTouchGraphicsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void TouchesMoved(PointF[] points)
{
if (!_dragStarted)
{
if (points.Length == 1)
if (_lastMovedViewPoints.Length > 0)
{
float deltaX = _lastMovedViewPoints[0].X - points[0].X;
float deltaY = _lastMovedViewPoints[0].Y - points[0].Y;
Expand Down
Loading