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)