From c7aa16fb2912ab0861a8d34414b483d93f87e003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josip=20=C4=86aleta?= Date: Thu, 6 Jun 2019 10:54:35 +0200 Subject: [PATCH] Fix iOS swipe renderer (#10) --- .../iOS/SwipeAwareContainerRenderer.cs | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Calendar.Plugin/iOS/SwipeAwareContainerRenderer.cs b/src/Calendar.Plugin/iOS/SwipeAwareContainerRenderer.cs index ee3fef1..158d4a9 100644 --- a/src/Calendar.Plugin/iOS/SwipeAwareContainerRenderer.cs +++ b/src/Calendar.Plugin/iOS/SwipeAwareContainerRenderer.cs @@ -47,10 +47,7 @@ protected override void OnElementChanged(ElementChangedEventArgs e) { base.OnElementChanged(e); - if (NativeView == null) - return; - - if (e.NewElement != null) + if (e.NewElement is SwipeAwareContainer element && !element.SwipeDetectionDisabled) AddGestureRecognizers(); if (e.OldElement != null) @@ -61,16 +58,19 @@ private void AddGestureRecognizers() { try { - if (!NativeView.GestureRecognizers.Contains(_rightGestureRecognizer)) + if (NativeView == null) + return; + + if (!NativeView.GestureRecognizers?.Contains(_rightGestureRecognizer) ?? true) NativeView.AddGestureRecognizer(_rightGestureRecognizer); - if (!NativeView.GestureRecognizers.Contains(_leftGestureRecognizer)) + if (!NativeView.GestureRecognizers?.Contains(_leftGestureRecognizer) ?? true) NativeView.AddGestureRecognizer(_leftGestureRecognizer); - if (!NativeView.GestureRecognizers.Contains(_upGestureRecognizer)) + if (!NativeView.GestureRecognizers?.Contains(_upGestureRecognizer) ?? true) NativeView.AddGestureRecognizer(_upGestureRecognizer); - if (!NativeView.GestureRecognizers.Contains(_downGestureRecognizer)) + if (!NativeView.GestureRecognizers?.Contains(_downGestureRecognizer) ?? true) NativeView.AddGestureRecognizer(_downGestureRecognizer); } catch (Exception) @@ -81,16 +81,19 @@ private void RemoveGestureRecognizers() { try { - if (NativeView.GestureRecognizers.Contains(_rightGestureRecognizer)) + if (NativeView == null) + return; + + if (NativeView.GestureRecognizers?.Contains(_rightGestureRecognizer) ?? false) NativeView.RemoveGestureRecognizer(_rightGestureRecognizer); - if (NativeView.GestureRecognizers.Contains(_leftGestureRecognizer)) + if (NativeView.GestureRecognizers?.Contains(_leftGestureRecognizer) ?? false) NativeView.RemoveGestureRecognizer(_leftGestureRecognizer); - if (NativeView.GestureRecognizers.Contains(_upGestureRecognizer)) + if (NativeView.GestureRecognizers?.Contains(_upGestureRecognizer) ?? false) NativeView.RemoveGestureRecognizer(_upGestureRecognizer); - if (NativeView.GestureRecognizers.Contains(_downGestureRecognizer)) + if (NativeView.GestureRecognizers?.Contains(_downGestureRecognizer) ?? false) NativeView.RemoveGestureRecognizer(_downGestureRecognizer); } catch (Exception)