-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] GraphicsView: prevent TapGesture crash when previous touch points are empty #34348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
||
| _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"); | ||||||||
|
|
||||||||
|
||||||||
| App.WaitForTextToBePresentInElement("Issue34296StatusLabel", "TapCount:2"); |
There was a problem hiding this comment.
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 byTouchesMoved(...). Right now, ifgraphicsView.Handler/PlatformViewisn’t the expectedPlatformTouchGraphicsViewfor 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.