Skip to content

Commit

Permalink
https://github.com/AndreiMisiukevich/CardView/issues/382
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiMisiukevich committed Apr 26, 2021
1 parent 0f89557 commit ac346c3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 42 deletions.
6 changes: 1 addition & 5 deletions PanCardView.Droid/CardsViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ public override bool OnTouchEvent(MotionEvent e)
var yDelta = GetTotalY(e);
CheckTouchHandled(xDelta, yDelta);

if ((Abs(yDelta) <= Abs(xDelta) && Element.IsHorizontalOrientation) ||
(Abs(yDelta) >= Abs(xDelta) && !Element.IsHorizontalOrientation))
{
UpdatePan(GestureStatus.Running, xDelta, yDelta);
}
UpdatePan(GestureStatus.Running, xDelta, yDelta);
}

HandleDownUpEvents(e);
Expand Down
52 changes: 18 additions & 34 deletions PanCardView.iOS/CardsViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public override void AddGestureRecognizer(UIGestureRecognizer gestureRecognizer)

if (gestureRecognizer is UIPanGestureRecognizer panGestureRecognizer)
{
gestureRecognizer.ShouldBeRequiredToFailBy = ShouldBeRequiredToFailBy;
gestureRecognizer.ShouldRecognizeSimultaneously = ShouldRecognizeSimultaneously;
gestureRecognizer.ShouldBegin = ShouldBegin;
}
Expand Down Expand Up @@ -126,41 +125,26 @@ private bool ShouldBegin(UIGestureRecognizer recognizer)
{
if (recognizer is UIPanGestureRecognizer pangesture)
{
var velocity = pangesture.VelocityInView(this);
var absVelocityX = Abs(velocity.X);
var absVelocityY = Abs(velocity.Y);
var isHorizontal = Element.IsHorizontalOrientation;
return (absVelocityY < absVelocityX && isHorizontal) ||
(absVelocityY > absVelocityX && !isHorizontal);
}

return true;
}

private bool ShouldBeRequiredToFailBy(UIGestureRecognizer gestureRecognizer, UIGestureRecognizer otherGestureRecognizer)
=> IsPanGestureHandled() && otherGestureRecognizer.View != this;

private bool ShouldRecognizeSimultaneously(UIGestureRecognizer gestureRecognizer, UIGestureRecognizer otherGestureRecognizer)
{
if (!(gestureRecognizer is UIPanGestureRecognizer panGesture))
{
return true;
}

var parent = Element?.Parent;
while (parent != null)
{
if (parent is FlyoutPage && (Element?.IsHorizontalOrientation ?? false))
{
var velocity = panGesture.VelocityInView(this);
return Abs(velocity.Y) > Abs(velocity.X);
var superview = pangesture.View.Superview;
while (superview != null)
{
if (superview is UIScrollView)
{
var velocity = pangesture.VelocityInView(this);
var absVelocityX = Abs(velocity.X);
var absVelocityY = Abs(velocity.Y);
var isHorizontal = Element.IsHorizontalOrientation;
return (absVelocityY < absVelocityX && isHorizontal) ||
(absVelocityY > absVelocityX && !isHorizontal);
}
superview = superview.Superview;
}
parent = parent.Parent;
}
return !IsPanGestureHandled();
}

private bool IsPanGestureHandled()
=> Abs(Element?.CurrentDiff ?? 0) >= Element?.MoveThresholdDistance;
return true;
}

private bool ShouldRecognizeSimultaneously(UIGestureRecognizer gestureRecognizer, UIGestureRecognizer otherGestureRecognizer)
=> Element == null || !(otherGestureRecognizer is UIPanGestureRecognizer);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using Xamarin.Forms;
using Xamarin.Forms;
using PanCardViewSample.ViewModels;
using PanCardView;
using System.Collections.Generic;
using PanCardView.Extensions;
using CardCarouselView = PanCardView.CarouselView;

Expand Down

0 comments on commit ac346c3

Please sign in to comment.