-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
228deef
Create MauiGestureRecognizerEventsBinder.cs
aritchie e66308c
Wireup
aritchie d2cb84f
Format code
getsentry-bot 24248da
Cleanup and fix code due stupid bot
aritchie 98a9789
I'm not an animal - I can save mem
aritchie 35e769c
Format code
getsentry-bot 6586050
Update MauiGestureRecognizerEventsBinder.cs
aritchie d1d5089
Create MauiEventsBinderTests.GestureRecognizers.cs
aritchie efcd673
Update MauiEventsBinderTests.GestureRecognizers.cs
aritchie 08a82bc
Merge branch 'main' into maui_gestures_breadcrumbs
aritchie 054041f
Merge branch 'main' into maui_gestures_breadcrumbs
aritchie 1fba474
Update MauiEventsBinderTests.cs
aritchie 8ef9aca
Update CHANGELOG.md
aritchie 559c8e0
Format code
getsentry-bot a71375a
WIP
aritchie ba54096
Merge branch 'maui_gestures_breadcrumbs' of https://github.com/getsen…
aritchie e14e5c2
Merge branch 'main' into maui_gestures_breadcrumbs
aritchie 66adf29
Update CHANGELOG.md
aritchie e7a5a9b
Merge branch 'main' into maui_gestures_breadcrumbs
aritchie d0c58f4
Bring over device tests to improve setup, fix gesture tests
aritchie 56e6d12
These run every time in the visual runner
aritchie ed4bb20
If working strictly from slnf - these don't get built and are depende…
aritchie a79dc8f
Finally got these to generate
aritchie ff6c52b
Format code
getsentry-bot c8d545c
Update MauiEventsBinderTests.GestureRecognizers.cs
aritchie b4f77b1
Merge branch 'maui_gestures_breadcrumbs' of https://github.com/getsen…
aritchie c10f2f0
Improve testing setup
aritchie 28a4993
Update src/Sentry.Maui/Internal/MauiGestureRecognizerEventsBinder.cs
aritchie 8e32be7
Merge branch 'main' into maui_gestures_breadcrumbs
aritchie 28c2205
Update MauiGestureRecognizerEventsBinder.cs
aritchie 09c6df9
Simplified conditional compilation of visual tests
jamescrosswell 501ae1f
Simplified TFMs in Maui.Device.TestApp
jamescrosswell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
194 changes: 194 additions & 0 deletions
194
src/Sentry.Maui/Internal/MauiGestureRecognizerEventsBinder.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| namespace Sentry.Maui.Internal; | ||
|
|
||
| /// <summary> | ||
| /// Detects and adds breadcrumbs for 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) => | ||
| [ | ||
| #if ANDROID | ||
| ("MotionEventAction", e.PlatformArgs?.MotionEvent.Action.ToString() ?? string.Empty) | ||
| #elif IOS | ||
| ("State", e.PlatformArgs?.GestureRecognizer.State.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())] | ||
| )); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
issue: Two
Featuressection.