Skip to content
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

Ensure no crashing for < iOS 12 due to PointerGesture incompatibility #11589

Merged
merged 1 commit into from
Nov 25, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ static void ProcessRecognizerHandlerTap(
}

var pointerGestureRecognizer = recognizer as PointerGestureRecognizer;
if (pointerGestureRecognizer != null)

if (pointerGestureRecognizer != null && OperatingSystem.IsIOSVersionAtLeast(13))
{
var uiRecognizer = CreatePointerRecognizer(r =>
{
Expand Down Expand Up @@ -405,6 +406,8 @@ UISwipeGestureRecognizer CreateSwipeRecognizer(SwipeDirection direction, Action<
return result;
}

[SupportedOSPlatform("ios13.0")]
[SupportedOSPlatform("maccatalyst13.0")]
CustomHoverGestureRecognizer CreatePointerRecognizer(Action<UIHoverGestureRecognizer> action)
{
var result = new CustomHoverGestureRecognizer(action);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
using System;
using System.Runtime.Versioning;
using Foundation;
using ObjCRuntime;
using UIKit;
using PreserveAttribute = Microsoft.Maui.Controls.Internals.PreserveAttribute;

namespace Microsoft.Maui.Controls.Platform.iOS;

[SupportedOSPlatform("ios13.0")]
[SupportedOSPlatform("maccatalyst13.0")]
internal class CustomHoverGestureRecognizer : UIHoverGestureRecognizer
{
NSObject _target;

#pragma warning disable CA1416

public CustomHoverGestureRecognizer(NSObject target, Selector action) : base(target, action)
{
_target = target;
}
#pragma warning restore CA1416

#pragma warning disable CA1416
internal CustomHoverGestureRecognizer(Action<UIHoverGestureRecognizer> action)
: this(new Callback(action), Selector.FromHandle(Selector.GetHandle("target:"))!) { }
#pragma warning restore CA1416

[Register("__UIHoverGestureRecognizer")]
class Callback : Token
Expand Down