Skip to content

Commit

Permalink
Improved pointer handling on UWP and Hover events (#27)
Browse files Browse the repository at this point in the history
* Update Xamarin.Forms

* Correct handling of UWP pointer events

* Add hover events (Android and UWP) and sample page

* Hover status improvements

* hover improvements

* Add HoverStateChanged and HoverStatusChanged

* refactor hover on android

* Add _inrange check to android

* code style fixes

* Revert "Update Xamarin.Forms"

This reverts commit a81f963.

* fix TouchEffect.csproj + fix hoverpage + fix UWP pointerreleased pressed state

* fix tap without movement on android (inrange enabled on down)

* requested code style changes

* revert changes

* remove unecessary spaces

* Remove Hover events from TouchView.cs

* fix formatting
  • Loading branch information
piersdeseilligny authored and AndreiMisiukevich committed Nov 14, 2019
1 parent 2bd952c commit 51de2b2
Show file tree
Hide file tree
Showing 20 changed files with 12,255 additions and 7,622 deletions.
43 changes: 41 additions & 2 deletions TouchEffect.Droid/PlatformTouchEff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,64 @@ protected override void OnDetached()
Control.Touch -= OnTouch;
}
}
catch(ObjectDisposedException)
catch (ObjectDisposedException)
{
//suppress exception
}
}

bool inRange;
private int[] _viewLocation = new int[2];
private void OnTouch(object sender, AView.TouchEventArgs e)
{
var senderView = sender as AView;

switch (e.Event.ActionMasked)
{
case MotionEventActions.Down:
inRange = true;
Element.GetTouchEff().HandleTouch(TouchStatus.Started);
break;

case MotionEventActions.Up:
Element.GetTouchEff().HandleTouch(TouchStatus.Completed);
if (inRange)
{
Element.GetTouchEff().HandleTouch(TouchStatus.Completed);
inRange = false;
}
else
{
Element.GetTouchEff().HandleTouch(TouchStatus.Canceled);
}
break;
case MotionEventActions.Cancel:
Element.GetTouchEff().HandleTouch(TouchStatus.Canceled);
break;

case MotionEventActions.HoverEnter:
Element.GetTouchEff().HandleHover(HoverStatus.Entered);
break;
case MotionEventActions.HoverExit:
Element.GetTouchEff().HandleHover(HoverStatus.Exited);
break;
case MotionEventActions.Move:
senderView.GetLocationOnScreen(_viewLocation);
var screenPointerCoords = new Point(_viewLocation[0] + e.Event.GetX(), _viewLocation[1] + e.Event.GetY());
Rectangle viewRect = new Rectangle(_viewLocation[0], _viewLocation[1], senderView.Width, senderView.Height);

if (viewRect.Contains(screenPointerCoords))
{
if (!inRange)
Element.GetTouchEff().HandleTouch(TouchStatus.Started);
inRange = true;

}
else
{
inRange = false;
Element.GetTouchEff().HandleTouch(TouchStatus.Canceled);
}
break;
}
e.Handled = true;
}
Expand Down
Loading

0 comments on commit 51de2b2

Please sign in to comment.