Skip to content

MAUI Gesture Recognizer Auto-Breadcrumbs #4124

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

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Added `CaptureFeedback` overload with `configureScope` parameter ([#4073](https://github.com/getsentry/sentry-dotnet/pull/4073))
- Custom SessionReplay masks in MAUI Android apps ([#4121](https://github.com/getsentry/sentry-dotnet/pull/4121))
- Auto breadcrumbs now include all .NET MAUI gesture recognizer events ([#4124](https://github.com/getsentry/sentry-dotnet/pull/4124))

### Fixes

Expand Down
6 changes: 5 additions & 1 deletion samples/Sentry.Samples.Maui/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
sentry:SessionReplay.Mask="Unmask"
SemanticProperties.Description="Cute dot net bot waving hi to you!"
HeightRequest="200"
HorizontalOptions="Center" />
HorizontalOptions="Center">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_OnTapped" />
</Image.GestureRecognizers>
</Image>

<Label
Text="Hello, World!"
Expand Down
4 changes: 4 additions & 0 deletions samples/Sentry.Samples.Maui/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,8 @@ private async void OnFeedbackClicked(object sender, EventArgs e)
{
await Navigation.PushModalAsync(new SubmitFeedback());
}

private void TapGestureRecognizer_OnTapped(object sender, TappedEventArgs e)
{
}
}
197 changes: 197 additions & 0 deletions src/Sentry.Maui/Internal/MauiGestureRecognizerEventsBinder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
namespace Sentry.Maui.Internal;

/// <summary>
/// Detects and breadcrumbs any gesture recognizers attached to the visual element
/// </summary>
public class MauiGestureRecognizerEventsBinder : IMauiElementEventBinder
{
private static Action<BreadcrumbEvent>? _addBreadcrumb = null!;

/// <summary>
/// Searches VisualElement for gesture recognizers to bind to
/// </summary>
public void Bind(VisualElement element, Action<BreadcrumbEvent> addBreadcrumb)
{
_addBreadcrumb ??= addBreadcrumb; // this is fine... it's the same callback for everyone and it never changes
TryBind(element, true);
}


/// <summary>
/// Searches VisualElement for gesture recognizers to unbind from
/// </summary>
/// <param name="element"></param>
public void UnBind(VisualElement element)
{
_addBreadcrumb = null;
TryBind(element, false);
}

private static void TryBind(VisualElement element, bool bind)
{
if (element is IGestureRecognizers recognizers)
{
foreach (var recognizer in recognizers.GestureRecognizers)
{
SetHooks(recognizer, bind);
}
}
}


private static void SetHooks(IGestureRecognizer recognizer, bool bind)
{
switch (recognizer)
{
case TapGestureRecognizer tap:
tap.Tapped -= OnTapGesture;

if (bind)
{
tap.Tapped += OnTapGesture;
}
break;

case SwipeGestureRecognizer swipe:
swipe.Swiped -= OnSwipeGesture;

if (bind)
{
swipe.Swiped += OnSwipeGesture;
}
break;

case PinchGestureRecognizer pinch:
pinch.PinchUpdated -= OnPinchGesture;

if (bind)
{
pinch.PinchUpdated += OnPinchGesture;
}
break;

case DragGestureRecognizer drag:
drag.DragStarting -= OnDragStartingGesture;
drag.DropCompleted -= OnDropCompletedGesture;

if (bind)
{
drag.DragStarting += OnDragStartingGesture;
drag.DropCompleted += OnDropCompletedGesture;
}
break;

case PanGestureRecognizer pan:
pan.PanUpdated -= OnPanGesture;

if (bind)
{
pan.PanUpdated += OnPanGesture;
}
break;

case PointerGestureRecognizer pointer:
pointer.PointerEntered -= OnPointerEnteredGesture;
pointer.PointerExited -= OnPointerExitedGesture;
pointer.PointerMoved -= OnPointerMovedGesture;
pointer.PointerPressed -= OnPointerPressedGesture;
pointer.PointerReleased -= OnPointerReleasedGesture;

if (bind)
{
pointer.PointerEntered += OnPointerEnteredGesture;
pointer.PointerExited += OnPointerExitedGesture;
pointer.PointerMoved += OnPointerMovedGesture;
pointer.PointerPressed += OnPointerPressedGesture;
pointer.PointerReleased += OnPointerReleasedGesture;
}
break;
}
}

private static void OnPointerReleasedGesture(object? sender, PointerEventArgs e) => _addBreadcrumb?.Invoke(new(
sender,
nameof(PointerGestureRecognizer.PointerReleased),
ToPointerData(e)
));

private static void OnPointerPressedGesture(object? sender, PointerEventArgs e) => _addBreadcrumb?.Invoke(new(
sender,
nameof(PointerGestureRecognizer.PointerPressed),
ToPointerData(e)
));

private static void OnPointerMovedGesture(object? sender, PointerEventArgs e) => _addBreadcrumb?.Invoke(new(
sender,
nameof(PointerGestureRecognizer.PointerMoved),
ToPointerData(e)
));

private static void OnPointerExitedGesture(object? sender, PointerEventArgs e) => _addBreadcrumb?.Invoke(new(
sender,
nameof(PointerGestureRecognizer.PointerExited),
ToPointerData(e)
));

private static void OnPointerEnteredGesture(object? sender, PointerEventArgs e) => _addBreadcrumb?.Invoke(new(
sender,
nameof(PointerGestureRecognizer.PointerEntered),
ToPointerData(e)
));

private static IEnumerable<(string Key, string Value)> ToPointerData(PointerEventArgs e) =>
[
// some of the data here may have some challenges being pulled out
#if ANDROID
("MotionEventAction", e.PlatformArgs?.MotionEvent.Action.ToString() ?? string.Empty)
//("MotionEventActionButton", e.PlatformArgs?.MotionEvent.ActionButton.ToString() ?? String.Empty)
#elif IOS
("State", e.PlatformArgs?.GestureRecognizer.State.ToString() ?? string.Empty),
//("ButtonMask", e.PlatformArgs?.GestureRecognizer.ButtonMask.ToString() ?? String.Empty)
#endif
];

private static void OnPanGesture(object? sender, PanUpdatedEventArgs e) => _addBreadcrumb?.Invoke(new(
sender,
nameof(PanGestureRecognizer.PanUpdated),
[
("GestureId", e.GestureId.ToString()),
("StatusType", e.StatusType.ToString()),
("TotalX", e.TotalX.ToString()),
("TotalY", e.TotalY.ToString())
]
));

private static void OnDropCompletedGesture(object? sender, DropCompletedEventArgs e) => _addBreadcrumb?.Invoke(new(
sender,
nameof(DragGestureRecognizer.DropCompleted)
));

private static void OnDragStartingGesture(object? sender, DragStartingEventArgs e) => _addBreadcrumb?.Invoke(new(
sender,
nameof(DragGestureRecognizer.DragStarting)
));


private static void OnPinchGesture(object? sender, PinchGestureUpdatedEventArgs e) => _addBreadcrumb?.Invoke(new(
sender,
nameof(PinchGestureRecognizer.PinchUpdated),
[
("GestureStatus", e.Status.ToString()),
("Scale", e.Scale.ToString()),
("ScaleOrigin", e.ScaleOrigin.ToString())
]
));

private static void OnSwipeGesture(object? sender, SwipedEventArgs e) => _addBreadcrumb?.Invoke(new(
sender,
nameof(SwipeGestureRecognizer.Swiped),
[("Direction", e.Direction.ToString())]
));

private static void OnTapGesture(object? sender, TappedEventArgs e) => _addBreadcrumb?.Invoke(new(
sender,
nameof(TapGestureRecognizer.Tapped),
[("ButtonMask", e.Buttons.ToString())]
));
}
1 change: 1 addition & 0 deletions src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static MauiAppBuilder UseSentry(this MauiAppBuilder builder,

services.AddSingleton<IMauiElementEventBinder, MauiButtonEventsBinder>();
services.AddSingleton<IMauiElementEventBinder, MauiImageButtonEventsBinder>();
services.AddSingleton<IMauiElementEventBinder, MauiGestureRecognizerEventsBinder>();
services.AddSingleton<IMauiElementEventBinder, MauiVisualElementEventsBinder>();
services.TryAddSingleton<IMauiEventsBinder, MauiEventsBinder>();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using Sentry.Maui.Internal;

namespace Sentry.Maui.Tests;

public partial class MauiEventsBinderTests
{
[Fact]
public void TapGestureRecognizer_LifecycleEvents_AddsBreadcrumb()
{
var gesture = new TapGestureRecognizer();
TestGestureRecognizer(

Check failure on line 11 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (ubuntu-22.04)

Sentry.Maui.Tests.MauiEventsBinderTests.TapGestureRecognizer_LifecycleEvents_AddsBreadcrumb

Assert.Single() Failure: The collection was empty

Check failure on line 11 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (windows-latest)

Sentry.Maui.Tests.MauiEventsBinderTests.TapGestureRecognizer_LifecycleEvents_AddsBreadcrumb

Assert.Single() Failure: The collection was empty

Check failure on line 11 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (macos-15)

Sentry.Maui.Tests.MauiEventsBinderTests.TapGestureRecognizer_LifecycleEvents_AddsBreadcrumb

Assert.Single() Failure: The collection was empty
gesture,
nameof(TapGestureRecognizer.Tapped),
new TappedEventArgs(gesture)
);
}


[Fact]
public void SwipeGestureRecognizer_LifecycleEvents_AddsBreadcrumb()
{
var gesture = new SwipeGestureRecognizer();
TestGestureRecognizer(
gesture,
nameof(SwipeGestureRecognizer.Swiped),
new SwipedEventArgs(gesture, SwipeDirection.Down)
);
}

[Fact]
public void PinchGestureRecognizer_LifecycleEvents_AddsBreadcrumb()
{
TestGestureRecognizer(

Check failure on line 33 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (ubuntu-22.04)

Sentry.Maui.Tests.MauiEventsBinderTests.PinchGestureRecognizer_LifecycleEvents_AddsBreadcrumb

Assert.Single() Failure: The collection was empty

Check failure on line 33 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (macos-15)

Sentry.Maui.Tests.MauiEventsBinderTests.PinchGestureRecognizer_LifecycleEvents_AddsBreadcrumb

Assert.Single() Failure: The collection was empty
new PinchGestureRecognizer(),
nameof(PinchGestureRecognizer.PinchUpdated),
new PinchGestureUpdatedEventArgs(GestureStatus.Completed, 0, Point.Zero)
);
}

[Theory]
[InlineData(nameof(DragGestureRecognizer.DragStarting))]
[InlineData(nameof(DragGestureRecognizer.DropCompleted))]
public void DragGestureRecognizer_LifecycleEvents_AddsBreadcrumb(string eventName)
{
TestGestureRecognizer(

Check failure on line 45 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (ubuntu-22.04)

Sentry.Maui.Tests.MauiEventsBinderTests.DragGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "DropCompleted")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.DropCompletedEventArgs'.

Check failure on line 45 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (ubuntu-22.04)

Sentry.Maui.Tests.MauiEventsBinderTests.DragGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "DragStarting")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.DragStartingEventArgs'.

Check failure on line 45 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (windows-latest)

Sentry.Maui.Tests.MauiEventsBinderTests.DragGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "DropCompleted")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.DropCompletedEventArgs'.

Check failure on line 45 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (windows-latest)

Sentry.Maui.Tests.MauiEventsBinderTests.DragGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "DragStarting")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.DragStartingEventArgs'.

Check failure on line 45 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (macos-15)

Sentry.Maui.Tests.MauiEventsBinderTests.DragGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "DropCompleted")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.DropCompletedEventArgs'.

Check failure on line 45 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (macos-15)

Sentry.Maui.Tests.MauiEventsBinderTests.DragGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "DragStarting")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.DragStartingEventArgs'.
new DragGestureRecognizer(),
eventName,
DragStartingEventArgs.Empty
);
}

[Fact]
public void PanGestureRecognizer_LifecycleEvents_AddsBreadcrumb()
{
TestGestureRecognizer(

Check failure on line 55 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (ubuntu-22.04)

Sentry.Maui.Tests.MauiEventsBinderTests.PanGestureRecognizer_LifecycleEvents_AddsBreadcrumb

Assert.Single() Failure: The collection was empty

Check failure on line 55 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (windows-latest)

Sentry.Maui.Tests.MauiEventsBinderTests.PanGestureRecognizer_LifecycleEvents_AddsBreadcrumb

Assert.Single() Failure: The collection was empty

Check failure on line 55 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (macos-15)

Sentry.Maui.Tests.MauiEventsBinderTests.PanGestureRecognizer_LifecycleEvents_AddsBreadcrumb

Assert.Single() Failure: The collection was empty
new PanGestureRecognizer(),
nameof(PanGestureRecognizer.PanUpdated),
new PanUpdatedEventArgs(GestureStatus.Completed, 1, 0, 0)
);
}

[Theory]
[InlineData(nameof(PointerGestureRecognizer.PointerEntered))]
[InlineData(nameof(PointerGestureRecognizer.PointerExited))]
[InlineData(nameof(PointerGestureRecognizer.PointerMoved))]
[InlineData(nameof(PointerGestureRecognizer.PointerPressed))]
[InlineData(nameof(PointerGestureRecognizer.PointerReleased))]
public void PointerGestureRecognizer_LifecycleEvents_AddsBreadcrumb(string eventName)
{
TestGestureRecognizer(

Check failure on line 70 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (ubuntu-22.04)

Sentry.Maui.Tests.MauiEventsBinderTests.PointerGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "PointerEntered")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.PointerEventArgs'.

Check failure on line 70 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (ubuntu-22.04)

Sentry.Maui.Tests.MauiEventsBinderTests.PointerGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "PointerMoved")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.PointerEventArgs'.

Check failure on line 70 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (ubuntu-22.04)

Sentry.Maui.Tests.MauiEventsBinderTests.PointerGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "PointerExited")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.PointerEventArgs'.

Check failure on line 70 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (ubuntu-22.04)

Sentry.Maui.Tests.MauiEventsBinderTests.PointerGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "PointerReleased")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.PointerEventArgs'.

Check failure on line 70 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (ubuntu-22.04)

Sentry.Maui.Tests.MauiEventsBinderTests.PointerGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "PointerPressed")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.PointerEventArgs'.

Check failure on line 70 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (windows-latest)

Sentry.Maui.Tests.MauiEventsBinderTests.PointerGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "PointerEntered")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.PointerEventArgs'.

Check failure on line 70 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (windows-latest)

Sentry.Maui.Tests.MauiEventsBinderTests.PointerGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "PointerMoved")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.PointerEventArgs'.

Check failure on line 70 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (windows-latest)

Sentry.Maui.Tests.MauiEventsBinderTests.PointerGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "PointerExited")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.PointerEventArgs'.

Check failure on line 70 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (windows-latest)

Sentry.Maui.Tests.MauiEventsBinderTests.PointerGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "PointerReleased")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.PointerEventArgs'.

Check failure on line 70 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (windows-latest)

Sentry.Maui.Tests.MauiEventsBinderTests.PointerGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "PointerPressed")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.PointerEventArgs'.

Check failure on line 70 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (macos-15)

Sentry.Maui.Tests.MauiEventsBinderTests.PointerGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "PointerEntered")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.PointerEventArgs'.

Check failure on line 70 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (macos-15)

Sentry.Maui.Tests.MauiEventsBinderTests.PointerGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "PointerMoved")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.PointerEventArgs'.

Check failure on line 70 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (macos-15)

Sentry.Maui.Tests.MauiEventsBinderTests.PointerGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "PointerExited")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.PointerEventArgs'.

Check failure on line 70 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (macos-15)

Sentry.Maui.Tests.MauiEventsBinderTests.PointerGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "PointerReleased")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.PointerEventArgs'.

Check failure on line 70 in test/Sentry.Maui.Tests/MauiEventsBinderTests.GestureRecognizers.cs

View workflow job for this annotation

GitHub Actions / .NET (macos-15)

Sentry.Maui.Tests.MauiEventsBinderTests.PointerGestureRecognizer_LifecycleEvents_AddsBreadcrumb(eventName: "PointerPressed")

System.ArgumentException : Object of type 'System.EventArgs' cannot be converted to type 'Microsoft.Maui.Controls.PointerEventArgs'.
new PointerGestureRecognizer(),
eventName,
PointerEventArgs.Empty
);
}


private void TestGestureRecognizer(GestureRecognizer gesture, string eventName, object eventArgs)
{
var image = new Image();
image.GestureRecognizers.Add(gesture);

var args = new ElementEventArgs(image);
_fixture.Binder.OnApplicationOnDescendantAdded(null, args);

// Act
gesture.RaiseEvent(eventName, eventArgs);

// Assert
var crumb = Assert.Single(_fixture.Scope.Breadcrumbs);
Assert.Equal($"{gesture.GetType().Name}.{eventName}", crumb.Message);
Assert.Equal(BreadcrumbLevel.Info, crumb.Level);
Assert.Equal(MauiEventsBinder.SystemType, crumb.Type);
Assert.Equal(MauiEventsBinder.LifecycleCategory, crumb.Category);
// crumb.Data.Should().Contain($"{gesture.GetType().Name}.Name", "tapgesturerecognizer");
}
}
3 changes: 2 additions & 1 deletion test/Sentry.Maui.Tests/MauiEventsBinderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public Fixture()
options,
[
new MauiButtonEventsBinder(),
new MauiImageButtonEventsBinder()
new MauiImageButtonEventsBinder(),
new MauiGestureRecognizerEventsBinder()
]
);
}
Expand Down
Loading