Skip to content

Commit

Permalink
fixed renderer for android
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiMisiukevich committed Apr 5, 2018
1 parent 38fb357 commit a324ac7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
19 changes: 14 additions & 5 deletions PanCardView.Droid/CardsViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ public override bool OnInterceptTouchEvent(MotionEvent ev)
{
return false;
}
var xDist = Abs(GetTotalX(ev));
var yDist = Abs(GetTotalY(ev));
return IsTouchHandled = xDist > yDist;

return SetIsTouchHandled(GetTotalX(ev), GetTotalY(ev));
}

HandleDownUpEvents(ev);
Expand All @@ -54,8 +53,15 @@ public override bool OnTouchEvent(MotionEvent e)
if (e.ActionMasked == MotionEventActions.Move)
{
var density = Context.Resources.DisplayMetrics.Density;
var distXDp = GetTotalX(e) / density;
var distYDp = GetTotalY(e) / density;

var xDelta = GetTotalX(e);
var yDelta = GetTotalY(e);

var distXDp = xDelta / density;
var distYDp = yDelta / density;

SetIsTouchHandled(xDelta, yDelta);

UpdatePan(GestureStatus.Running, distXDp, distYDp);
}

Expand All @@ -73,6 +79,9 @@ protected override void OnElementChanged(ElementChangedEventArgs<CardsView> e)
}
}

private bool SetIsTouchHandled(float xDelta, float yDelta)
=> IsTouchHandled = Abs(xDelta) > Abs(yDelta);

private void HandleDownUpEvents(MotionEvent ev)
{
HandleDownEvent(ev);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public CarouselSampleViewNoTemplate()

var carousel = new CarouselView
{
HeightRequest = 200,
Items = new[] {
new BoxView { Color = Color.Red },
new BoxView { Color = Color.Blue}
Expand Down

0 comments on commit a324ac7

Please sign in to comment.