Skip to content
Merged
Changes from 2 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
143 changes: 24 additions & 119 deletions src/UIKit/UIGestureRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using CoreGraphics;

namespace UIKit {

public partial class UIGestureRecognizer {
//
// Tracks the targets (NSObject, which we always enforce to be Token) to the Selector the point to, used when disposing
Expand Down Expand Up @@ -76,6 +77,21 @@ public Token ()
}
}

[Register ("__UIGestureRecognizerGenericCB")]
internal class Callback<T> : Token where T: UIGestureRecognizer {
Action<T> action;

internal Callback (Action<T> action)
{
this.action = action;
}

[Export ("target:")]
[Preserve (Conditional = true)]
public void Activated (T sender) => action (sender);

}

[Register ("__UIGestureRecognizerParameterlessToken")]
public class ParameterlessDispatch : Token {
Action action;
Expand Down Expand Up @@ -159,163 +175,52 @@ public IEnumerable<Token> GetTargets ()
#if !TVOS
public partial class UIRotationGestureRecognizer : UIGestureRecognizer {
public UIRotationGestureRecognizer (Action action) : base (action) {}
public UIRotationGestureRecognizer (Action<UIRotationGestureRecognizer> action) : base (Selector.GetHandle (UIGestureRecognizer.parametrized_selector), new Callback (action)) {}
public UIRotationGestureRecognizer (Action<UIRotationGestureRecognizer> action) : base (Selector.GetHandle (UIGestureRecognizer.parametrized_selector), new Callback<UIRotationGestureRecognizer>(action)) {}

[Register ("__UIRotationGestureRecognizer")]
class Callback : Token {
Action<UIRotationGestureRecognizer> action;

internal Callback (Action<UIRotationGestureRecognizer> action)
{
this.action = action;
}

[Export ("target:")]
[Preserve (Conditional = true)]
public void Activated (UIRotationGestureRecognizer sender)
{
action (sender);
}
}
}
#endif

public partial class UILongPressGestureRecognizer : UIGestureRecognizer {
public UILongPressGestureRecognizer (Action action) : base (action) {}
public UILongPressGestureRecognizer (Action<UILongPressGestureRecognizer> action) : base (Selector.GetHandle (UIGestureRecognizer.parametrized_selector), new Callback (action)) {}
public UILongPressGestureRecognizer (Action<UILongPressGestureRecognizer> action) : base (Selector.GetHandle (UIGestureRecognizer.parametrized_selector), new Callback<UILongPressGestureRecognizer>(action)) {}

[Register ("__UILongPressGestureRecognizer")]
class Callback : Token {
Action<UILongPressGestureRecognizer> action;

internal Callback (Action<UILongPressGestureRecognizer> action)
{
this.action = action;
}

[Export ("target:")]
[Preserve (Conditional = true)]
public void Activated (UILongPressGestureRecognizer sender)
{
action (sender);
}
}
}

public partial class UITapGestureRecognizer : UIGestureRecognizer {
public UITapGestureRecognizer (Action action) : base (action) {}
public UITapGestureRecognizer (Action<UITapGestureRecognizer> action) : base (Selector.GetHandle (UIGestureRecognizer.parametrized_selector), new Callback (action)) {}
public UITapGestureRecognizer (Action<UITapGestureRecognizer> action) : base (Selector.GetHandle (UIGestureRecognizer.parametrized_selector), new Callback<UITapGestureRecognizer>(action)) {}

[Register ("__UITapGestureRecognizer")]
class Callback : Token {
Action<UITapGestureRecognizer> action;

internal Callback (Action<UITapGestureRecognizer> action)
{
this.action = action;
}

[Export ("target:")]
[Preserve (Conditional = true)]
public void Activated (UITapGestureRecognizer sender)
{
action (sender);
}
}
}

public partial class UIPanGestureRecognizer : UIGestureRecognizer {
public UIPanGestureRecognizer (Action action) : base (action) {}
public UIPanGestureRecognizer (Action<UIPanGestureRecognizer> action) : base (Selector.GetHandle (UIGestureRecognizer.parametrized_selector), new Callback (action)) {}
public UIPanGestureRecognizer (Action<UIPanGestureRecognizer> action) : base (Selector.GetHandle (UIGestureRecognizer.parametrized_selector), new Callback<UIPanGestureRecognizer>(action)) {}

internal UIPanGestureRecognizer (IntPtr sel, Token token) : base (token, sel) {}

[Register ("__UIPanGestureRecognizer")]
class Callback : Token {
Action<UIPanGestureRecognizer> action;

internal Callback (Action<UIPanGestureRecognizer> action)
{
this.action = action;
}

[Export ("target:")]
[Preserve (Conditional = true)]
public void Activated (UIPanGestureRecognizer sender)
{
action (sender);
}
}
}

#if !TVOS
public partial class UIPinchGestureRecognizer : UIGestureRecognizer {
public UIPinchGestureRecognizer (Action action) : base (action) {}
public UIPinchGestureRecognizer (Action<UIPinchGestureRecognizer> action) : base (Selector.GetHandle (UIGestureRecognizer.parametrized_selector), new Callback (action)) {}
public UIPinchGestureRecognizer (Action<UIPinchGestureRecognizer> action) : base (Selector.GetHandle (UIGestureRecognizer.parametrized_selector), new Callback<UIPinchGestureRecognizer>(action)) {}

[Register ("__UIPinchGestureRecognizer")]
class Callback : Token {
Action<UIPinchGestureRecognizer> action;

internal Callback (Action<UIPinchGestureRecognizer> action)
{
this.action = action;
}

[Export ("target:")]
[Preserve (Conditional = true)]
public void Activated (UIPinchGestureRecognizer sender)
{
action (sender);
}
}
}
#endif

public partial class UISwipeGestureRecognizer : UIGestureRecognizer {
public UISwipeGestureRecognizer (Action action) : base (action) {}
public UISwipeGestureRecognizer (Action<UISwipeGestureRecognizer> action) : base (Selector.GetHandle (UIGestureRecognizer.parametrized_selector), new Callback (action)) {}
public UISwipeGestureRecognizer (Action<UISwipeGestureRecognizer> action) : base (Selector.GetHandle (UIGestureRecognizer.parametrized_selector), new Callback<UISwipeGestureRecognizer>(action)) {}

[Register ("__UISwipeGestureRecognizer")]
class Callback : Token {
Action<UISwipeGestureRecognizer> action;

internal Callback (Action<UISwipeGestureRecognizer> action)
{
this.action = action;
}

[Export ("target:")]
[Preserve (Conditional = true)]
public void Activated (UISwipeGestureRecognizer sender)
{
action (sender);
}
}
}

#if !TVOS
public partial class UIScreenEdgePanGestureRecognizer : UIPanGestureRecognizer {
public UIScreenEdgePanGestureRecognizer (Action action) : base (action) {}
public UIScreenEdgePanGestureRecognizer (Action<UIScreenEdgePanGestureRecognizer> action) : base (Selector.GetHandle (UIGestureRecognizer.parametrized_selector), new Callback (action)) {}

[Register ("__UIScreenEdgePanGestureRecognizer")]
class Callback : Token {
Action<UIScreenEdgePanGestureRecognizer> action;
public UIScreenEdgePanGestureRecognizer (Action<UIScreenEdgePanGestureRecognizer> action) : base (Selector.GetHandle (UIGestureRecognizer.parametrized_selector), new Callback<UIScreenEdgePanGestureRecognizer>(action)) {}

internal Callback (Action<UIScreenEdgePanGestureRecognizer> action)
{
this.action = action;
}

[Export ("target:")]
[Preserve (Conditional = true)]
public void Activated (UIScreenEdgePanGestureRecognizer sender)
{
action (sender);
}
}
}

#endif
}

Expand Down