Skip to content

Commit

Permalink
Fix iOS swipe renderer (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josip Ćaleta committed Jun 6, 2019
1 parent 7ea22b4 commit c7aa16f
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/Calendar.Plugin/iOS/SwipeAwareContainerRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ protected override void OnElementChanged(ElementChangedEventArgs<ContentView> 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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit c7aa16f

Please sign in to comment.