Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit f07f488

Browse files
AndreiMisiukevichjsuarezruizpictosTheCodeTraveler
authored
[UWP] TouchEffect OnPointerReleased crash (#1088)
* Fixed TouchEffect UWP crash * Touch Effect more nullRef fixes * fixed build * fix build Co-authored-by: Javier Suárez <[email protected]> Co-authored-by: Pedro Jesus <[email protected]> Co-authored-by: Brandon Minnick <[email protected]>
1 parent 36f4173 commit f07f488

File tree

5 files changed

+46
-50
lines changed

5 files changed

+46
-50
lines changed

src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.android.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ void OnTouchMove(object? sender, AView.TouchEventArgs e)
243243

244244
if (isHoverSupported && ((status == TouchStatus.Canceled && effect?.HoverStatus == HoverStatus.Entered)
245245
|| (status == TouchStatus.Started && effect?.HoverStatus == HoverStatus.Exited)))
246-
effect.HandleHover(status == TouchStatus.Started ? HoverStatus.Entered : HoverStatus.Exited);
246+
effect?.HandleHover(status == TouchStatus.Started ? HoverStatus.Entered : HoverStatus.Exited);
247247

248248
if (effect?.Status != status)
249249
{
@@ -259,17 +259,13 @@ void OnTouchMove(object? sender, AView.TouchEventArgs e)
259259
void OnHoverEnter()
260260
{
261261
isHoverSupported = true;
262-
263-
if (effect != null)
264-
effect.HandleHover(HoverStatus.Entered);
262+
effect?.HandleHover(HoverStatus.Entered);
265263
}
266264

267265
void OnHoverExit()
268266
{
269267
isHoverSupported = true;
270-
271-
if (effect != null)
272-
effect.HandleHover(HoverStatus.Exited);
268+
effect?.HandleHover(HoverStatus.Exited);
273269
}
274270

275271
void OnClick(object? sender, EventArgs args)

src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.ios.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ void OnHover()
8888
{
8989
case UIGestureRecognizerState.Began:
9090
case UIGestureRecognizerState.Changed:
91-
effect.HandleHover(HoverStatus.Entered);
91+
effect?.HandleHover(HoverStatus.Entered);
9292
break;
9393
case UIGestureRecognizerState.Ended:
94-
effect.HandleHover(HoverStatus.Exited);
94+
effect?.HandleHover(HoverStatus.Exited);
9595
break;
9696
}
9797
}

src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.macos.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,18 @@ public override void UpdateTrackingAreas()
7979

8080
public override void MouseEntered(NSEvent theEvent)
8181
{
82-
if (effect == null || effect.IsDisabled)
82+
if (effect?.Element == null || effect.IsDisabled)
8383
return;
8484

85-
effect.HandleHover(HoverStatus.Entered);
85+
effect?.HandleHover(HoverStatus.Entered);
8686
}
8787

8888
public override void MouseExited(NSEvent theEvent)
8989
{
90-
if (effect == null || effect.IsDisabled)
90+
if (effect?.Element == null || effect.IsDisabled)
9191
return;
9292

93-
effect.HandleHover(HoverStatus.Exited);
93+
effect?.HandleHover(HoverStatus.Exited);
9494
}
9595

9696
protected override void Dispose(bool disposing)
@@ -139,18 +139,18 @@ Rectangle ViewRect
139139

140140
public override void MouseDown(NSEvent mouseEvent)
141141
{
142-
if (effect == null || effect.IsDisabled)
142+
if (effect?.Element == null || effect.IsDisabled)
143143
return;
144144

145-
effect.HandleUserInteraction(TouchInteractionStatus.Started);
146-
effect.HandleTouch(TouchStatus.Started);
145+
effect?.HandleUserInteraction(TouchInteractionStatus.Started);
146+
effect?.HandleTouch(TouchStatus.Started);
147147

148148
base.MouseDown(mouseEvent);
149149
}
150150

151151
public override void MouseUp(NSEvent mouseEvent)
152152
{
153-
if (effect == null || effect.IsDisabled)
153+
if (effect?.Element == null || effect.IsDisabled)
154154
return;
155155

156156
if (effect.HoverStatus == HoverStatus.Entered)
@@ -160,26 +160,26 @@ public override void MouseUp(NSEvent mouseEvent)
160160
? TouchStatus.Completed
161161
: TouchStatus.Canceled;
162162

163-
effect.HandleTouch(status);
163+
effect?.HandleTouch(status);
164164
}
165-
effect.HandleUserInteraction(TouchInteractionStatus.Completed);
165+
effect?.HandleUserInteraction(TouchInteractionStatus.Completed);
166166

167167
base.MouseUp(mouseEvent);
168168
}
169169

170170
public override void MouseDragged(NSEvent mouseEvent)
171171
{
172-
if (effect == null || effect.IsDisabled)
172+
if (effect?.Element == null || effect.IsDisabled)
173173
return;
174174

175175
var status = ViewRect.Contains(mouseEvent.LocationInWindow.ToPoint()) ? TouchStatus.Started : TouchStatus.Canceled;
176176

177177
if ((status == TouchStatus.Canceled && effect.HoverStatus == HoverStatus.Entered) ||
178178
(status == TouchStatus.Started && effect.HoverStatus == HoverStatus.Exited))
179-
effect.HandleHover(status == TouchStatus.Started ? HoverStatus.Entered : HoverStatus.Exited);
179+
effect?.HandleHover(status == TouchStatus.Started ? HoverStatus.Entered : HoverStatus.Exited);
180180

181-
if (effect.Status != status)
182-
effect.HandleTouch(status);
181+
if (effect?.Status != status)
182+
effect?.HandleTouch(status);
183183

184184
base.MouseDragged(mouseEvent);
185185
}

src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.tizen.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ public void HandleTouch(TouchStatus status, TouchInteractionStatus? touchInterac
124124

125125
if (touchInteractionStatus == TouchInteractionStatus.Started)
126126
{
127-
effect.HandleUserInteraction(TouchInteractionStatus.Started);
127+
effect?.HandleUserInteraction(TouchInteractionStatus.Started);
128128
touchInteractionStatus = null;
129129
}
130130

131-
effect.HandleTouch(status);
131+
effect?.HandleTouch(status);
132132
if (touchInteractionStatus.HasValue)
133-
effect.HandleUserInteraction(touchInteractionStatus.Value);
133+
effect?.HandleUserInteraction(touchInteractionStatus.Value);
134134

135-
if (!effect.NativeAnimation)
135+
if (effect == null || !effect.NativeAnimation)
136136
return;
137137

138138
if (longTapStarted && !tapCompleted)

src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.uwp.cs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,26 @@ protected override void OnDetached()
109109

110110
void OnPointerEntered(object? sender, PointerRoutedEventArgs e)
111111
{
112-
if (effect == null || effect.IsDisabled)
112+
if (effect?.Element == null || effect.IsDisabled)
113113
return;
114114

115-
effect.HandleHover(HoverStatus.Entered);
115+
effect?.HandleHover(HoverStatus.Entered);
116116

117117
if (isPressed)
118118
{
119-
effect.HandleTouch(TouchStatus.Started);
119+
effect?.HandleTouch(TouchStatus.Started);
120120
AnimateTilt(pointerDownStoryboard);
121121
}
122122
}
123123

124124
void OnPointerExited(object? sender, PointerRoutedEventArgs e)
125125
{
126-
if (effect == null || effect.IsDisabled)
126+
if (effect?.Element == null || effect.IsDisabled)
127127
return;
128128

129129
if (isPressed)
130130
{
131-
effect.HandleTouch(TouchStatus.Canceled);
131+
effect?.HandleTouch(TouchStatus.Canceled);
132132
AnimateTilt(pointerUpStoryboard);
133133
}
134134

@@ -137,72 +137,72 @@ void OnPointerExited(object? sender, PointerRoutedEventArgs e)
137137

138138
void OnPointerCanceled(object? sender, PointerRoutedEventArgs e)
139139
{
140-
if (effect == null || effect.IsDisabled)
140+
if (effect?.Element == null || effect.IsDisabled)
141141
return;
142142

143143
isPressed = false;
144144

145-
effect.HandleTouch(TouchStatus.Canceled);
146-
effect.HandleUserInteraction(TouchInteractionStatus.Completed);
147-
effect.HandleHover(HoverStatus.Exited);
145+
effect?.HandleTouch(TouchStatus.Canceled);
146+
effect?.HandleUserInteraction(TouchInteractionStatus.Completed);
147+
effect?.HandleHover(HoverStatus.Exited);
148148

149149
AnimateTilt(pointerUpStoryboard);
150150
}
151151

152152
void OnPointerCaptureLost(object? sender, PointerRoutedEventArgs e)
153153
{
154-
if (effect == null || effect.IsDisabled)
154+
if (effect?.Element == null || effect.IsDisabled)
155155
return;
156156

157157
if (isIntentionalCaptureLoss)
158158
return;
159159

160160
isPressed = false;
161161

162-
if (effect.Status != TouchStatus.Canceled)
163-
effect.HandleTouch(TouchStatus.Canceled);
162+
if (effect?.Status != TouchStatus.Canceled)
163+
effect?.HandleTouch(TouchStatus.Canceled);
164164

165-
effect.HandleUserInteraction(TouchInteractionStatus.Completed);
165+
effect?.HandleUserInteraction(TouchInteractionStatus.Completed);
166166

167-
if (effect.HoverStatus != HoverStatus.Exited)
168-
effect.HandleHover(HoverStatus.Exited);
167+
if (effect?.HoverStatus != HoverStatus.Exited)
168+
effect?.HandleHover(HoverStatus.Exited);
169169

170170
AnimateTilt(pointerUpStoryboard);
171171
}
172172

173173
void OnPointerReleased(object? sender, PointerRoutedEventArgs e)
174174
{
175-
if (effect == null || effect.IsDisabled)
175+
if (effect?.Element == null || effect.IsDisabled)
176176
return;
177177

178178
if (isPressed && (effect.HoverStatus == HoverStatus.Entered))
179179
{
180-
effect.HandleTouch(TouchStatus.Completed);
180+
effect?.HandleTouch(TouchStatus.Completed);
181181
AnimateTilt(pointerUpStoryboard);
182182
}
183183
else if (effect.HoverStatus != HoverStatus.Exited)
184184
{
185-
effect.HandleTouch(TouchStatus.Canceled);
185+
effect?.HandleTouch(TouchStatus.Canceled);
186186
AnimateTilt(pointerUpStoryboard);
187187
}
188188

189-
effect.HandleUserInteraction(TouchInteractionStatus.Completed);
189+
effect?.HandleUserInteraction(TouchInteractionStatus.Completed);
190190

191191
isPressed = false;
192192
isIntentionalCaptureLoss = true;
193193
}
194194

195195
void OnPointerPressed(object? sender, PointerRoutedEventArgs e)
196196
{
197-
if (effect == null || effect.IsDisabled)
197+
if (effect?.Element == null || effect.IsDisabled)
198198
return;
199199

200200
isPressed = true;
201201

202202
Container.CapturePointer(e.Pointer);
203203

204-
effect.HandleUserInteraction(TouchInteractionStatus.Started);
205-
effect.HandleTouch(TouchStatus.Started);
204+
effect?.HandleUserInteraction(TouchInteractionStatus.Started);
205+
effect?.HandleTouch(TouchStatus.Started);
206206

207207
AnimateTilt(pointerDownStoryboard);
208208

@@ -211,7 +211,7 @@ void OnPointerPressed(object? sender, PointerRoutedEventArgs e)
211211

212212
void AnimateTilt(Storyboard? storyboard)
213213
{
214-
if (storyboard != null && effect != null && effect.NativeAnimation)
214+
if (storyboard != null && effect?.Element != null && effect.NativeAnimation)
215215
{
216216
try
217217
{

0 commit comments

Comments
 (0)