Skip to content

Instantly share code, notes, and snippets.

@PureWeen
Last active August 2, 2018 23:40
Show Gist options
  • Save PureWeen/3912fbaea40d82f848107eed863e093d to your computer and use it in GitHub Desktop.
Save PureWeen/3912fbaea40d82f848107eed863e093d to your computer and use it in GitHub Desktop.

GestureEventArgs Spec

Additional telemetery data that will be added to Updated events.

Note: Nothing in this specification is guaranteed to be final; all features, implementations, and interfaces are subject to change.

Touch

public class Touch
{
	public int TouchId { get; set; }
	public Point ViewPosition { get; set; }
	public Point PagePosition { get; set; }
	public Point ScreenPosition { get; set; }
	public GestureStatusType StatusType { get; set; }
	View Target { get; }
}

Properties

API Description
TouchId A unique identifier for a specific finger in contact with the screen.
ViewPosition The relative Position of this touch for the given view the gesture is attached to.
PagePosition The relative Position of this touch to the parent page
ScreenPosition The absolute Position of the touch on the screen.
GestureStatusType The state of the touch. This is mainly used when inspecting ChangedTouches to see how said touches have changed
Target The view associated with this Gesture.

TouchEvent

public class TouchEvent
{
	public IReadOnlyList<Touch> Touches { get; set; }
	public IReadOnlyList<Touch> ChangedTouches { get; set; }
	public IReadOnlyList<Touch> TargetTouches { get; set; }
	View Target { get; }
}

Properties

API Description
Touches All active touches and their positions. This will include touches that are happening outside this view
ChangedTouches All touches that changed from the last event.
TargetTouches All touches affecting this view

GestureEventArgs

Eventually all of the gestures eventargs will inherit from GestureEventArgs. Initially it'll just be LongPressGestureRecognizer

public class GestureEventArgs : EventArgs
{
	public TouchEvent TouchEvent { get; private set; }
}

Properties

API Description
TouchEvent Information about the touch event that caused an update on a gesture.

Examples

public class LongPressContainer : ContentView
{
  BoxView touchView;
  
  public LongPressContainer ()
  {
    var longPressGesture = new LongPressGestureRecognizer ();
    longPressGesture.LongPressUpdated += OnLongPressUpdated;
    GestureRecognizers.Add (longPressGesture);
    
    touchView = new BoxView {WidthRequest = 20, HeightRequest = 20, Color = Color.Red};
  }

  void OnLongPressUpdated (object sender, LongPressUpdatedEventArgs e)
  {
    TouchEvent data = e.TouchEvent;
    if(e.StatusType == GestureStatus.Started || e.StatusType == GestureStatus.Running)
    {
    	var touch = data.TargetTouches[0].ViewPosition;
	AbsoluteLayout.SetLayoutBounds (touchView, new Rectangle (touch.X, touch.Y, 20, 20));
	touchView.Color = Color.Red;
	touchView.IsVisible = true;
    }
    else 
    {
    	touchView.IsVisible = false;
    }
  }
}

This example demonstrates a user long pressing a ContentView which will cause a red BoxView to appear under the finger. Now as the user moves their finger around on the screen the box will follow the finger. Once they lift their finger the BoxView will vanish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment