diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.android.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.android.cs index 624182745..9e21ce3fd 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.android.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.android.cs @@ -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) { @@ -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) diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.ios.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.ios.cs index 0b7d16c59..deb45f1c7 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.ios.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.ios.cs @@ -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; } } diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.macos.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.macos.cs index 561bfd946..19d4b2656 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.macos.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.macos.cs @@ -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) @@ -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) @@ -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); } diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.tizen.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.tizen.cs index dd71cea77..167078a6c 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.tizen.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.tizen.cs @@ -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) diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.uwp.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.uwp.cs index 6d994f49f..0ce883725 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.uwp.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.uwp.cs @@ -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); } @@ -137,21 +137,21 @@ 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) @@ -159,34 +159,34 @@ void OnPointerCaptureLost(object? sender, PointerRoutedEventArgs e) 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; @@ -194,15 +194,15 @@ void OnPointerReleased(object? sender, PointerRoutedEventArgs e) 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); @@ -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 {