Skip to content

Instantly share code, notes, and snippets.

@rotorgames
Created October 9, 2019 18:21
Show Gist options
  • Select an option

  • Save rotorgames/89b124dd85a5bd22c4ca7883183e17e1 to your computer and use it in GitHub Desktop.

Select an option

Save rotorgames/89b124dd85a5bd22c4ca7883183e17e1 to your computer and use it in GitHub Desktop.
Carousel Gestures
public override bool OnTouchEvent(MotionEvent e)
{
switch(e.Action)
{
case MotionEventActions.Down:
case MotionEventActions.PointerDown:
case MotionEventActions.Pointer2Down:
if(Element?.Content != null && IsHorizontalScrollStarted())
Parent?.RequestDisallowInterceptTouchEvent(true);
break;
case MotionEventActions.Cancel:
case MotionEventActions.Up:
Parent?.RequestDisallowInterceptTouchEvent(false);
break;
}
return base.OnTouchEvent(e);
}
bool IsHorizontalScrollStarted()
{
return //Return true is scroll is started;
}
public override void AddGestureRecognizer(UIGestureRecognizer gestureRecognizer)
{
base.AddGestureRecognizer(gestureRecognizer);
if (gestureRecognizer is UIPanGestureRecognizer)
gestureRecognizer.ShouldBeRequiredToFailBy = ShouldBeRequiredToFailBy;
gestureRecognizer.ShouldRecognizeSimultaneously = ShouldRecognizeSimultaneously;
}
bool ShouldBeRequiredToFailBy(UIGestureRecognizer gestureRecognizer, UIGestureRecognizer otherGestureRecognizer)
{
if (IsHorizontalScrollStarted() && gestureRecognizer is UIPanGestureRecognizer && otherGestureRecognizer.View != this)
return true;
return false;
}
bool ShouldRecognizeSimultaneously(UIGestureRecognizer gestureRecognizer, UIGestureRecognizer otherGestureRecognizer)
{
return !IsHorizontalScrollStarted();
}
bool IsHorizontalScrollStarted()
{
return // Return true is scroll is started;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment