Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue on android where carousel would snap to a page prematurly #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/Droid/Renderers/CarouselLayoutRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ void HScrollViewTouch (object sender, TouchEventArgs e)

switch (e.Event.Action) {
case MotionEventActions.Move:
/* MotionEventActions.Down will not fire if a child element is intercepting the event.
Down has to occur before move so we will ensure that happens. */
OnMotionEventActionsDown();
_deltaXResetTimer.Stop ();
_deltaX = _scrollView.ScrollX - _prevScrollX;
_prevScrollX = _scrollView.ScrollX;
Expand All @@ -65,18 +68,30 @@ void HScrollViewTouch (object sender, TouchEventArgs e)
_deltaXResetTimer.Start ();
break;
case MotionEventActions.Down:
_motionDown = true;
_scrollStopTimer.Stop ();
// Note: This case block will never occur if a child element is consuming the down event.
OnMotionEventActionsDown();
break;
case MotionEventActions.Up:
_motionDown = false;
SnapScroll ();
_scrollStopTimer.Start ();
break;
}
}

void UpdateSelectedIndex () {
}

/// <summary>
/// If motionDown is set to false set it to true and stop the scroll timer.
/// </summary>
void OnMotionEventActionsDown()
{
if (!_motionDown)
{
_motionDown = true;
_scrollStopTimer.Stop();
}
}

void UpdateSelectedIndex () {
var center = _scrollView.ScrollX + (_scrollView.Width / 2);
var carouselLayout = (CarouselLayout)this.Element;
carouselLayout.SelectedIndex = (center / _scrollView.Width);
Expand Down