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

[UWP] TouchEffect OnPointerReleased crash #1088

Merged
merged 9 commits into from
Mar 19, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void OnTouchMove(object? sender, AView.TouchEventArgs e)

if (isHoverSupported && ((status == TouchStatus.Canceled && effect?.HoverStatus == HoverStatus.Entered)
|| (status == TouchStatus.Started && effect?.HoverStatus == HoverStatus.Exited)))
effect.HandleHover(status == TouchStatus.Started ? HoverStatus.Entered : HoverStatus.Exited);
effect?.HandleHover(status == TouchStatus.Started ? HoverStatus.Entered : HoverStatus.Exited);

if (effect?.Status != status)
{
Expand All @@ -259,17 +259,13 @@ void OnTouchMove(object? sender, AView.TouchEventArgs e)
void OnHoverEnter()
{
isHoverSupported = true;

if (effect != null)
effect.HandleHover(HoverStatus.Entered);
effect?.HandleHover(HoverStatus.Entered);
}

void OnHoverExit()
{
isHoverSupported = true;

if (effect != null)
effect.HandleHover(HoverStatus.Exited);
effect?.HandleHover(HoverStatus.Exited);
}

void OnClick(object? sender, EventArgs args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ void OnHover()
{
case UIGestureRecognizerState.Began:
case UIGestureRecognizerState.Changed:
effect.HandleHover(HoverStatus.Entered);
effect?.HandleHover(HoverStatus.Entered);
break;
case UIGestureRecognizerState.Ended:
effect.HandleHover(HoverStatus.Exited);
effect?.HandleHover(HoverStatus.Exited);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ public override void UpdateTrackingAreas()

public override void MouseEntered(NSEvent theEvent)
{
if (effect == null || effect.IsDisabled)
if (effect?.Element == null || effect.IsDisabled)
return;

effect.HandleHover(HoverStatus.Entered);
effect?.HandleHover(HoverStatus.Entered);
}

public override void MouseExited(NSEvent theEvent)
{
if (effect == null || effect.IsDisabled)
if (effect?.Element == null || effect.IsDisabled)
return;

effect.HandleHover(HoverStatus.Exited);
effect?.HandleHover(HoverStatus.Exited);
}

protected override void Dispose(bool disposing)
Expand Down Expand Up @@ -139,18 +139,18 @@ Rectangle ViewRect

public override void MouseDown(NSEvent mouseEvent)
{
if (effect == null || effect.IsDisabled)
if (effect?.Element == null || effect.IsDisabled)
return;

effect.HandleUserInteraction(TouchInteractionStatus.Started);
effect.HandleTouch(TouchStatus.Started);
effect?.HandleUserInteraction(TouchInteractionStatus.Started);
effect?.HandleTouch(TouchStatus.Started);

base.MouseDown(mouseEvent);
}

public override void MouseUp(NSEvent mouseEvent)
{
if (effect == null || effect.IsDisabled)
if (effect?.Element == null || effect.IsDisabled)
return;

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

effect.HandleTouch(status);
effect?.HandleTouch(status);
}
effect.HandleUserInteraction(TouchInteractionStatus.Completed);
effect?.HandleUserInteraction(TouchInteractionStatus.Completed);

base.MouseUp(mouseEvent);
}

public override void MouseDragged(NSEvent mouseEvent)
{
if (effect == null || effect.IsDisabled)
if (effect?.Element == null || effect.IsDisabled)
return;

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

if ((status == TouchStatus.Canceled && effect.HoverStatus == HoverStatus.Entered) ||
(status == TouchStatus.Started && effect.HoverStatus == HoverStatus.Exited))
effect.HandleHover(status == TouchStatus.Started ? HoverStatus.Entered : HoverStatus.Exited);
effect?.HandleHover(status == TouchStatus.Started ? HoverStatus.Entered : HoverStatus.Exited);

if (effect.Status != status)
effect.HandleTouch(status);
if (effect?.Status != status)
effect?.HandleTouch(status);

base.MouseDragged(mouseEvent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ public void HandleTouch(TouchStatus status, TouchInteractionStatus? touchInterac

if (touchInteractionStatus == TouchInteractionStatus.Started)
{
effect.HandleUserInteraction(TouchInteractionStatus.Started);
effect?.HandleUserInteraction(TouchInteractionStatus.Started);
touchInteractionStatus = null;
}

effect.HandleTouch(status);
effect?.HandleTouch(status);
if (touchInteractionStatus.HasValue)
effect.HandleUserInteraction(touchInteractionStatus.Value);
effect?.HandleUserInteraction(touchInteractionStatus.Value);

if (!effect.NativeAnimation)
if (effect == null || !effect.NativeAnimation)
return;

if (longTapStarted && !tapCompleted)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,26 @@ protected override void OnDetached()

void OnPointerEntered(object? sender, PointerRoutedEventArgs e)
{
if (effect == null || effect.IsDisabled)
if (effect?.Element == null || effect.IsDisabled)
return;

effect.HandleHover(HoverStatus.Entered);
effect?.HandleHover(HoverStatus.Entered);

if (isPressed)
{
effect.HandleTouch(TouchStatus.Started);
effect?.HandleTouch(TouchStatus.Started);
AnimateTilt(pointerDownStoryboard);
}
}

void OnPointerExited(object? sender, PointerRoutedEventArgs e)
{
if (effect == null || effect.IsDisabled)
if (effect?.Element == null || effect.IsDisabled)
return;

if (isPressed)
{
effect.HandleTouch(TouchStatus.Canceled);
effect?.HandleTouch(TouchStatus.Canceled);
AnimateTilt(pointerUpStoryboard);
}

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

void OnPointerCanceled(object? sender, PointerRoutedEventArgs e)
{
if (effect == null || effect.IsDisabled)
if (effect?.Element == null || effect.IsDisabled)
return;

isPressed = false;

effect.HandleTouch(TouchStatus.Canceled);
effect.HandleUserInteraction(TouchInteractionStatus.Completed);
effect.HandleHover(HoverStatus.Exited);
effect?.HandleTouch(TouchStatus.Canceled);
effect?.HandleUserInteraction(TouchInteractionStatus.Completed);
effect?.HandleHover(HoverStatus.Exited);

AnimateTilt(pointerUpStoryboard);
}

void OnPointerCaptureLost(object? sender, PointerRoutedEventArgs e)
{
if (effect == null || effect.IsDisabled)
if (effect?.Element == null || effect.IsDisabled)
return;

if (isIntentionalCaptureLoss)
return;

isPressed = false;

if (effect.Status != TouchStatus.Canceled)
effect.HandleTouch(TouchStatus.Canceled);
if (effect?.Status != TouchStatus.Canceled)
effect?.HandleTouch(TouchStatus.Canceled);

effect.HandleUserInteraction(TouchInteractionStatus.Completed);
effect?.HandleUserInteraction(TouchInteractionStatus.Completed);

if (effect.HoverStatus != HoverStatus.Exited)
effect.HandleHover(HoverStatus.Exited);
if (effect?.HoverStatus != HoverStatus.Exited)
effect?.HandleHover(HoverStatus.Exited);

AnimateTilt(pointerUpStoryboard);
}

void OnPointerReleased(object? sender, PointerRoutedEventArgs e)
{
if (effect == null || effect.IsDisabled)
if (effect?.Element == null || effect.IsDisabled)
return;

if (isPressed && (effect.HoverStatus == HoverStatus.Entered))
{
effect.HandleTouch(TouchStatus.Completed);
effect?.HandleTouch(TouchStatus.Completed);
AnimateTilt(pointerUpStoryboard);
}
else if (effect.HoverStatus != HoverStatus.Exited)
{
effect.HandleTouch(TouchStatus.Canceled);
effect?.HandleTouch(TouchStatus.Canceled);
AnimateTilt(pointerUpStoryboard);
}

effect.HandleUserInteraction(TouchInteractionStatus.Completed);
effect?.HandleUserInteraction(TouchInteractionStatus.Completed);

isPressed = false;
isIntentionalCaptureLoss = true;
}

void OnPointerPressed(object? sender, PointerRoutedEventArgs e)
{
if (effect == null || effect.IsDisabled)
if (effect?.Element == null || effect.IsDisabled)
return;

isPressed = true;

Container.CapturePointer(e.Pointer);

effect.HandleUserInteraction(TouchInteractionStatus.Started);
effect.HandleTouch(TouchStatus.Started);
effect?.HandleUserInteraction(TouchInteractionStatus.Started);
effect?.HandleTouch(TouchStatus.Started);

AnimateTilt(pointerDownStoryboard);

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

void AnimateTilt(Storyboard? storyboard)
{
if (storyboard != null && effect != null && effect.NativeAnimation)
if (storyboard != null && effect?.Element != null && effect.NativeAnimation)
{
try
{
Expand Down