Skip to content

Commit

Permalink
fix touch to allow click-and-drag (#902)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinvangelder authored and rozele committed Nov 23, 2016
1 parent b9dca3c commit bea7990
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions ReactWindows/ReactNative.Net46/Touch/TouchHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ private void OnTouchPressed(object sender, TouchEventArgs e)
pointer.IsHorizontalMouseWheel = false;
pointer.IsEraser = false;
pointer.ReactView = reactView;
UpdatePointerForEvent(pointer, rootPoint.Position, viewPoint);
var timestamp = e.Timestamp;
UpdatePointerForEvent(pointer, rootPoint.Position, viewPoint, timestamp);

var pointerIndex = _pointers.Count;
_pointers.Add(pointer);
Expand Down Expand Up @@ -88,7 +89,8 @@ private void OnMouseDown(object sender, MouseButtonEventArgs e)
pointer.IsHorizontalMouseWheel = false;
pointer.IsEraser = false;
pointer.ReactView = reactView;
UpdatePointerForEvent(pointer, rootPoint, viewPoint);
var timestamp = e.Timestamp;
UpdatePointerForEvent(pointer, rootPoint, viewPoint, timestamp);

var pointerIndex = _pointers.Count;
_pointers.Add(pointer);
Expand All @@ -108,11 +110,12 @@ private void OnTouchMoved(object sender, TouchEventArgs e)

private void OnMouseMove(object sender, MouseEventArgs e)
{
if (_pointers != null && _pointers.Count > 0)
var pointerIndex = IndexOfPointerWithId((uint)e.Device.GetHashCode());
if (_pointers != null && pointerIndex >= 0)
{
var pointer = _pointers[0];
var pointer = _pointers[pointerIndex];
UpdatePointerForEvent(pointer, e);
DispatchTouchEvent(TouchEventType.Move, _pointers, 0);
DispatchTouchEvent(TouchEventType.Move, _pointers, pointerIndex);
}
}

Expand Down Expand Up @@ -147,13 +150,14 @@ private void OnTouchConcluded(TouchEventType touchEventType, TouchEventArgs e)

private void OnPointerConcluded(TouchEventType touchEventType, MouseButtonEventArgs e)
{
if (_pointers != null && _pointers.Count > 0)
var pointerIndex = IndexOfPointerWithId((uint)e.Device.GetHashCode());
if (_pointers != null && pointerIndex >= 0)
{
var pointer = _pointers[0];
var pointer = _pointers[pointerIndex];
UpdatePointerForEvent(pointer, e);
DispatchTouchEvent(touchEventType, _pointers, 0);
DispatchTouchEvent(touchEventType, _pointers, pointerIndex);

_pointers.RemoveAt(0);
_pointers.RemoveAt(pointerIndex);

if (_pointers.Count == 0)
{
Expand Down Expand Up @@ -241,24 +245,27 @@ private void UpdatePointerForEvent(ReactPointer pointer, TouchEventArgs e)
{
var rootPoint = e.GetTouchPoint(_view);
var viewPoint = e.GetTouchPoint(pointer.ReactView);
UpdatePointerForEvent(pointer, rootPoint.Position, viewPoint.Position);
var timestamp = e.Timestamp;
UpdatePointerForEvent(pointer, rootPoint.Position, viewPoint.Position, timestamp);
}

private void UpdatePointerForEvent(ReactPointer pointer, MouseButtonEventArgs e)
{
var rootPoint = e.GetPosition(_view);
var viewPoint = e.GetPosition(pointer.ReactView);
UpdatePointerForEvent(pointer, rootPoint, viewPoint);
var timestamp = e.Timestamp;
UpdatePointerForEvent(pointer, rootPoint, viewPoint, timestamp);
}

private void UpdatePointerForEvent(ReactPointer pointer, MouseEventArgs e)
{
var rootPoint = e.GetPosition(_view);
var viewPoint = e.GetPosition(pointer.ReactView);
UpdatePointerForEvent(pointer, rootPoint, viewPoint);
var timestamp = e.Timestamp;
UpdatePointerForEvent(pointer, rootPoint, viewPoint, timestamp);
}

private void UpdatePointerForEvent(ReactPointer pointer, Point rootPoint, Point viewPoint)
private void UpdatePointerForEvent(ReactPointer pointer, Point rootPoint, Point viewPoint, int timestamp)
{
var positionInRoot = rootPoint;
var positionInView = viewPoint;
Expand All @@ -267,6 +274,7 @@ private void UpdatePointerForEvent(ReactPointer pointer, Point rootPoint, Point
pointer.PageY = (float)positionInRoot.Y;
pointer.LocationX = (float)positionInView.X;
pointer.LocationY = (float)positionInView.Y;
pointer.Timestamp = (ulong) timestamp;
}

private void DispatchTouchEvent(TouchEventType touchEventType, List<ReactPointer> activePointers, int pointerIndex)
Expand Down

0 comments on commit bea7990

Please sign in to comment.