Skip to content

Commit 5e01170

Browse files
jhonatanfernandoAndreiMisiukevich
authored andcommitted
fixup (+1 squashed commit)
Squashed commits: [8b0c379] fixup (+1 squashed commit) Squashed commits: [08e8609] #40 (+1 squashed commit) Squashed commits: [aa00d2d] When using it on Image component, getting exception for Android (#41) * When using it on Image component, getting exception for Android * Update PlatformTouchEff.cs * Update TouchEffectSample.sln * Update TouchEffectSample.iOS.csproj
1 parent a89bdd4 commit 5e01170

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

TouchEffect.Droid/PlatformTouchEff.cs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class PlatformTouchEff : PlatformEffect
2424
{
2525
public static void Preserve() { }
2626

27-
27+
2828
private TouchEff _effect;
2929
private bool _isHoverSupported;
3030
private RippleDrawable _ripple;
@@ -49,7 +49,7 @@ protected override void OnAttached()
4949
Control.Touch += OnTouch;
5050
}
5151

52-
if(_effect.NativeAnimation)
52+
if (_effect.NativeAnimation)
5353
{
5454
View.Clickable = true;
5555
View.LongClickable = true;
@@ -64,8 +64,10 @@ protected override void OnAttached()
6464
_ripple = CreateRipple();
6565
_ripple.Radius = (int)(View.Context.Resources.DisplayMetrics.Density * _effect.NativeAnimationRadius);
6666
_viewOverlay.Background = _ripple;
67-
68-
Container.AddView(_viewOverlay);
67+
if (Container != null)
68+
{
69+
Container.AddView(_viewOverlay);
70+
}
6971
_viewOverlay.BringToFront();
7072
}
7173
}
@@ -76,18 +78,26 @@ protected override void OnDetached()
7678
{
7779
_effect.Control = null;
7880
_effect = null;
79-
Container.LayoutChange -= LayoutChange;
81+
8082
if (Container != null)
8183
{
84+
Container.LayoutChange -= LayoutChange;
8285
Container.Touch -= OnTouch;
8386
}
87+
8488
if (Control != null)
8589
{
90+
Control.LayoutChange -= LayoutChange;
8691
Control.Touch -= OnTouch;
8792
}
93+
8894
if (_viewOverlay != null)
8995
{
90-
Container.RemoveView(_viewOverlay);
96+
if (Container != null)
97+
{
98+
Container.RemoveView(_viewOverlay);
99+
}
100+
91101
_viewOverlay.Pressed = false;
92102
_viewOverlay.Foreground = null;
93103
_viewOverlay.Dispose();
@@ -104,6 +114,7 @@ protected override void OnDetached()
104114
private void OnTouch(object sender, AView.TouchEventArgs e)
105115
{
106116
e.Handled = true;
117+
107118
switch (e.Event.ActionMasked)
108119
{
109120
case MotionEventActions.Down:
@@ -124,12 +135,12 @@ private void OnTouch(object sender, AView.TouchEventArgs e)
124135
HandleEnd(TouchStatus.Canceled);
125136
break;
126137
case MotionEventActions.Move:
127-
if(_canceled)
138+
if (_canceled)
128139
{
129140
return;
130141
}
131-
var diffX = Abs(e.Event.GetX() - _startX) / Container.Context.Resources.DisplayMetrics.Density;
132-
var diffY = Abs(e.Event.GetY() - _startY) / Container.Context.Resources.DisplayMetrics.Density;
142+
var diffX = Abs(e.Event.GetX() - _startX) / View.Context.Resources.DisplayMetrics.Density;
143+
var diffY = Abs(e.Event.GetY() - _startY) / View.Context.Resources.DisplayMetrics.Density;
133144
var maxDiff = Max(diffX, diffY);
134145
var disallowTouchThreshold = _effect.DisallowTouchThreshold;
135146
if (disallowTouchThreshold > 0 && maxDiff > disallowTouchThreshold)
@@ -152,7 +163,7 @@ private void OnTouch(object sender, AView.TouchEventArgs e)
152163
if (Element.GetTouchEff().Status != status)
153164
{
154165
Element.GetTouchEff().HandleTouch(status);
155-
if(status == TouchStatus.Started)
166+
if (status == TouchStatus.Started)
156167
StartRipple(e.Event.GetX(), e.Event.GetY());
157168
if (status == TouchStatus.Canceled)
158169
EndRipple();
@@ -174,7 +185,7 @@ private void OnTouch(object sender, AView.TouchEventArgs e)
174185

175186
private void HandleEnd(TouchStatus status)
176187
{
177-
if(_canceled)
188+
if (_canceled)
178189
{
179190
return;
180191
}

TouchEffectSample.sln

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio 15
3-
VisualStudioVersion = 15.0.28307.136
2+
# Visual Studio Version 15
3+
VisualStudioVersion = 15.0.2837.136
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchEffectSample.Android", "TouchEffectSample.Android\TouchEffectSample.Android.csproj", "{9EED875F-F3C4-4753-9064-39DF7CD222AA}"
66
EndProject
@@ -639,4 +639,4 @@ Global
639639
GlobalSection(ExtensibilityGlobals) = postSolution
640640
SolutionGuid = {ADEA45D4-665F-46B4-A93C-24985213924B}
641641
EndGlobalSection
642-
EndGlobal
642+
EndGlobal

0 commit comments

Comments
 (0)