Skip to content

Commit eb3f002

Browse files
https://github.com/AndreiMisiukevich/TouchEffect/issues/58
1 parent 4780d56 commit eb3f002

File tree

12 files changed

+217
-52
lines changed

12 files changed

+217
-52
lines changed

TouchEffect.Droid/PlatformTouchEff.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ private void OnTouch(object sender, AView.TouchEventArgs e)
133133
IsCanceled = false;
134134
_startX = e.Event.GetX();
135135
_startY = e.Event.GetY();
136+
_effect?.HandleUserInteraction(UserInteractionState.Running);
136137
_effect?.HandleTouch(TouchStatus.Started);
137138
StartRipple(e.Event.GetX(), e.Event.GetY());
138139
if (_effect.DisallowTouchThreshold > 0)
@@ -215,6 +216,7 @@ private void HandleEnd(TouchStatus status)
215216
Group.Parent?.RequestDisallowInterceptTouchEvent(false);
216217
}
217218
_effect?.HandleTouch(status);
219+
_effect?.HandleUserInteraction(UserInteractionState.Idle);
218220
EndRipple();
219221
}
220222

TouchEffect.Mac/PlatformTouchEff.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public override void MouseDown(NSEvent mouseEvent)
134134
{
135135
if (_effect?.IsDisabled ?? true) return;
136136

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

152153
_effect?.HandleTouch(status);
153154
}
155+
_effect?.HandleUserInteraction(UserInteractionState.Idle);
156+
154157
base.MouseUp(mouseEvent);
155158
}
156159

TouchEffect.UWP/PlatformTouchEff.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ private void OnPointerCanceled(object sender, PointerRoutedEventArgs e)
131131

132132
_pressed = false;
133133
_effect?.HandleTouch(TouchStatus.Canceled);
134+
_effect?.HandleUserInteraction(UserInteractionState.Idle);
134135
_effect?.HandleHover(HoverStatus.Exited);
135136
AnimateTilt(_pointerUpStoryboard);
136137
}
@@ -145,6 +146,7 @@ private void OnPointerCaptureLost(object sender, PointerRoutedEventArgs e)
145146
{
146147
_effect?.HandleTouch(TouchStatus.Canceled);
147148
}
149+
_effect?.HandleUserInteraction(UserInteractionState.Idle);
148150
if (_effect.HoverStatus != HoverStatus.Exited)
149151
{
150152
_effect?.HandleHover(HoverStatus.Exited);
@@ -168,6 +170,7 @@ private void OnPointerReleased(object sender, PointerRoutedEventArgs e)
168170
AnimateTilt(_pointerUpStoryboard);
169171
}
170172

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

179182
_pressed = true;
180183
Container.CapturePointer(e.Pointer);
184+
_effect?.HandleUserInteraction(UserInteractionState.Running);
181185
_effect?.HandleTouch(TouchStatus.Started);
182186
AnimateTilt(_pointerDownStoryboard);
183187
_intentionalCaptureLoss = false;

TouchEffect.iOS/PlatformTouchEff.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ public override void TouchesBegan(NSSet touches, UIEvent evt)
7373

7474
IsCanceled = false;
7575
_startPoint = GetTouchPoint(touches);
76-
HandleTouch(TouchStatus.Started);
76+
HandleTouch(TouchStatus.Started, UserInteractionState.Running);
7777
base.TouchesBegan(touches, evt);
7878
}
7979

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

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

93-
HandleTouch(TouchStatus.Canceled);
93+
HandleTouch(TouchStatus.Canceled, UserInteractionState.Idle);
9494
IsCanceled = true;
9595
base.TouchesCancelled(touches, evt);
9696
}
@@ -108,7 +108,7 @@ public override void TouchesMoved(NSSet touches, UIEvent evt)
108108
var maxDiff = Max(diffX, diffY);
109109
if (maxDiff > disallowTouchThreshold)
110110
{
111-
HandleTouch(TouchStatus.Canceled);
111+
HandleTouch(TouchStatus.Canceled, UserInteractionState.Idle);
112112
IsCanceled = true;
113113
base.TouchesMoved(touches, evt);
114114
return;
@@ -140,7 +140,7 @@ protected override void Dispose(bool disposing)
140140
private CGPoint? GetTouchPoint(NSSet touches)
141141
=> Renderer != null ? (touches?.AnyObject as UITouch)?.LocationInView(Renderer) : null;
142142

143-
public void HandleTouch(TouchStatus status)
143+
public void HandleTouch(TouchStatus status, UserInteractionState? userInteractionState = null)
144144
{
145145
if (IsCanceled || _effect == null)
146146
{
@@ -149,7 +149,12 @@ public void HandleTouch(TouchStatus status)
149149

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

152-
_effect?.HandleTouch(status);
152+
_effect.HandleTouch(status);
153+
if (userInteractionState.HasValue)
154+
{
155+
_effect.HandleUserInteraction(userInteractionState.Value);
156+
}
157+
153158
if (_effect == null || !_effect.NativeAnimation || !_effect.CanExecute)
154159
{
155160
return;
@@ -196,7 +201,7 @@ public override bool ShouldRecognizeSimultaneously(UIGestureRecognizer gestureRe
196201
if (gestureRecognizer is TouchUITapGestureRecognizer touchGesture && otherGestureRecognizer is UIPanGestureRecognizer &&
197202
otherGestureRecognizer.State == UIGestureRecognizerState.Began)
198203
{
199-
touchGesture.HandleTouch(TouchStatus.Canceled);
204+
touchGesture.HandleTouch(TouchStatus.Canceled, UserInteractionState.Idle);
200205
touchGesture.IsCanceled = true;
201206
}
202207

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using TouchEffect.EventArgs;
2+
using Xamarin.Forms;
3+
4+
namespace TouchEffect.Delegates
5+
{
6+
public delegate void TEffectUserInteractionStateChangedHandler(VisualElement sender, UserInteractionStateChangedEventArgs args);
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+

2+
namespace TouchEffect.Enums
3+
{
4+
public enum UserInteractionState
5+
{
6+
Idle,
7+
Running
8+
}
9+
}

TouchEffect/EventArgs/TouchStateChangedEventArgs.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ public TouchStateChangedEventArgs(TouchState state)
1010

1111
public TouchState State { get; }
1212
}
13+
1314
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using TouchEffect.Enums;
2+
namespace TouchEffect.EventArgs
3+
{
4+
public class UserInteractionStateChangedEventArgs : System.EventArgs
5+
{
6+
public UserInteractionStateChangedEventArgs(UserInteractionState userInteractionstate)
7+
{
8+
UserInteractionState = userInteractionstate;
9+
}
10+
11+
public UserInteractionState UserInteractionState { get; }
12+
}
13+
}

0 commit comments

Comments
 (0)