Skip to content

Commit

Permalink
https://github.com/AndreiMisiukevich/TouchEffect/issues/58
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiMisiukevich committed Oct 27, 2020
1 parent 4780d56 commit eb3f002
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 52 deletions.
2 changes: 2 additions & 0 deletions TouchEffect.Droid/PlatformTouchEff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ private void OnTouch(object sender, AView.TouchEventArgs e)
IsCanceled = false;
_startX = e.Event.GetX();
_startY = e.Event.GetY();
_effect?.HandleUserInteraction(UserInteractionState.Running);
_effect?.HandleTouch(TouchStatus.Started);
StartRipple(e.Event.GetX(), e.Event.GetY());
if (_effect.DisallowTouchThreshold > 0)
Expand Down Expand Up @@ -215,6 +216,7 @@ private void HandleEnd(TouchStatus status)
Group.Parent?.RequestDisallowInterceptTouchEvent(false);
}
_effect?.HandleTouch(status);
_effect?.HandleUserInteraction(UserInteractionState.Idle);
EndRipple();
}

Expand Down
3 changes: 3 additions & 0 deletions TouchEffect.Mac/PlatformTouchEff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public override void MouseDown(NSEvent mouseEvent)
{
if (_effect?.IsDisabled ?? true) return;

_effect?.HandleUserInteraction(UserInteractionState.Running);
_effect?.HandleTouch(TouchStatus.Started);
base.MouseDown(mouseEvent);
}
Expand All @@ -151,6 +152,8 @@ public override void MouseUp(NSEvent mouseEvent)

_effect?.HandleTouch(status);
}
_effect?.HandleUserInteraction(UserInteractionState.Idle);

base.MouseUp(mouseEvent);
}

Expand Down
4 changes: 4 additions & 0 deletions TouchEffect.UWP/PlatformTouchEff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ private void OnPointerCanceled(object sender, PointerRoutedEventArgs e)

_pressed = false;
_effect?.HandleTouch(TouchStatus.Canceled);
_effect?.HandleUserInteraction(UserInteractionState.Idle);
_effect?.HandleHover(HoverStatus.Exited);
AnimateTilt(_pointerUpStoryboard);
}
Expand All @@ -145,6 +146,7 @@ private void OnPointerCaptureLost(object sender, PointerRoutedEventArgs e)
{
_effect?.HandleTouch(TouchStatus.Canceled);
}
_effect?.HandleUserInteraction(UserInteractionState.Idle);
if (_effect.HoverStatus != HoverStatus.Exited)
{
_effect?.HandleHover(HoverStatus.Exited);
Expand All @@ -168,6 +170,7 @@ private void OnPointerReleased(object sender, PointerRoutedEventArgs e)
AnimateTilt(_pointerUpStoryboard);
}

_effect?.HandleUserInteraction(UserInteractionState.Idle);
_pressed = false;
_intentionalCaptureLoss = true;
}
Expand All @@ -178,6 +181,7 @@ private void OnPointerPressed(object sender, PointerRoutedEventArgs e)

_pressed = true;
Container.CapturePointer(e.Pointer);
_effect?.HandleUserInteraction(UserInteractionState.Running);
_effect?.HandleTouch(TouchStatus.Started);
AnimateTilt(_pointerDownStoryboard);
_intentionalCaptureLoss = false;
Expand Down
19 changes: 12 additions & 7 deletions TouchEffect.iOS/PlatformTouchEff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ public override void TouchesBegan(NSSet touches, UIEvent evt)

IsCanceled = false;
_startPoint = GetTouchPoint(touches);
HandleTouch(TouchStatus.Started);
HandleTouch(TouchStatus.Started, UserInteractionState.Running);
base.TouchesBegan(touches, evt);
}

public override void TouchesEnded(NSSet touches, UIEvent evt)
{
if (_effect?.IsDisabled ?? true) return;

HandleTouch(_effect?.Status == TouchStatus.Started ? TouchStatus.Completed : TouchStatus.Canceled);
HandleTouch(_effect?.Status == TouchStatus.Started ? TouchStatus.Completed : TouchStatus.Canceled, UserInteractionState.Idle);
IsCanceled = true;
base.TouchesEnded(touches, evt);
}
Expand All @@ -90,7 +90,7 @@ public override void TouchesCancelled(NSSet touches, UIEvent evt)
{
if (_effect?.IsDisabled ?? true) return;

HandleTouch(TouchStatus.Canceled);
HandleTouch(TouchStatus.Canceled, UserInteractionState.Idle);
IsCanceled = true;
base.TouchesCancelled(touches, evt);
}
Expand All @@ -108,7 +108,7 @@ public override void TouchesMoved(NSSet touches, UIEvent evt)
var maxDiff = Max(diffX, diffY);
if (maxDiff > disallowTouchThreshold)
{
HandleTouch(TouchStatus.Canceled);
HandleTouch(TouchStatus.Canceled, UserInteractionState.Idle);
IsCanceled = true;
base.TouchesMoved(touches, evt);
return;
Expand Down Expand Up @@ -140,7 +140,7 @@ protected override void Dispose(bool disposing)
private CGPoint? GetTouchPoint(NSSet touches)
=> Renderer != null ? (touches?.AnyObject as UITouch)?.LocationInView(Renderer) : null;

public void HandleTouch(TouchStatus status)
public void HandleTouch(TouchStatus status, UserInteractionState? userInteractionState = null)
{
if (IsCanceled || _effect == null)
{
Expand All @@ -149,7 +149,12 @@ public void HandleTouch(TouchStatus status)

if (_effect?.IsDisabled ?? true) return;

_effect?.HandleTouch(status);
_effect.HandleTouch(status);
if (userInteractionState.HasValue)
{
_effect.HandleUserInteraction(userInteractionState.Value);
}

if (_effect == null || !_effect.NativeAnimation || !_effect.CanExecute)
{
return;
Expand Down Expand Up @@ -196,7 +201,7 @@ public override bool ShouldRecognizeSimultaneously(UIGestureRecognizer gestureRe
if (gestureRecognizer is TouchUITapGestureRecognizer touchGesture && otherGestureRecognizer is UIPanGestureRecognizer &&
otherGestureRecognizer.State == UIGestureRecognizerState.Began)
{
touchGesture.HandleTouch(TouchStatus.Canceled);
touchGesture.HandleTouch(TouchStatus.Canceled, UserInteractionState.Idle);
touchGesture.IsCanceled = true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using TouchEffect.EventArgs;
using Xamarin.Forms;

namespace TouchEffect.Delegates
{
public delegate void TEffectUserInteractionStateChangedHandler(VisualElement sender, UserInteractionStateChangedEventArgs args);
}
9 changes: 9 additions & 0 deletions TouchEffect/Enums/UserInteractionState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

namespace TouchEffect.Enums
{
public enum UserInteractionState
{
Idle,
Running
}
}
1 change: 1 addition & 0 deletions TouchEffect/EventArgs/TouchStateChangedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public TouchStateChangedEventArgs(TouchState state)

public TouchState State { get; }
}

}
13 changes: 13 additions & 0 deletions TouchEffect/EventArgs/UserInteractionStateChangedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using TouchEffect.Enums;
namespace TouchEffect.EventArgs
{
public class UserInteractionStateChangedEventArgs : System.EventArgs
{
public UserInteractionStateChangedEventArgs(UserInteractionState userInteractionstate)
{
UserInteractionState = userInteractionstate;
}

public UserInteractionState UserInteractionState { get; }
}
}
Loading

0 comments on commit eb3f002

Please sign in to comment.