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

iOS scroll animate bug fix #27

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
20 changes: 12 additions & 8 deletions src/iOS/Renderers/CarouselLayoutRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected override void OnElementChanged(VisualElementChangedEventArgs e)
if (e.OldElement != null) return;

_native = (UIScrollView)NativeView;
_native.Scrolled += NativeScrolled;
_native.DecelerationEnded += NativeScrolled;
e.NewElement.PropertyChanged += ElementPropertyChanged;
}

Expand All @@ -40,26 +40,30 @@ void NativeScrolled (object sender, EventArgs e)

void ElementPropertyChanged(object sender, PropertyChangedEventArgs e) {
if (e.PropertyName == CarouselLayout.SelectedIndexProperty.PropertyName && !Dragging) {
ScrollToSelection (false);
ScrollToSelection (true);
}
}

void ScrollToSelection (bool animate)
{
if (Element == null) return;

_native.SetContentOffset (new CoreGraphics.CGPoint
(_native.Bounds.Width *
Math.Max(0, ((CarouselLayout)Element).SelectedIndex),
_native.ContentOffset.Y),
animate);
InvokeOnMainThread(() =>
{
_native.SetContentOffset (new CoreGraphics.CGPoint
(_native.Bounds.Width *
Math.Max(0, ((CarouselLayout)Element).SelectedIndex),
_native.ContentOffset.Y),
animate);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 58: Needs ); after the }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue here, seems your solution almost solves it. In my case the image tries to scroll but fails, so I see like an hard movement of the image to the left and then it gets back to the right. Weird. I also tried to switch _native.Bounds.Width to Application.Current.MainPage.Width (my slider is full-screen). Any idea?

}

/*
public override void Draw(CoreGraphics.CGRect rect)
{
base.Draw (rect);
ScrollToSelection (false);
}
*/
}
}