Vishal-Singh-Panwar / InfiniteScrolling

Add infinite scrolling to collection view.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Port to C# - help

balinabbb opened this issue · comments

Hi,

awesome work you did there. I am trying to port this functionality to Xamarin iOS via C#.
Almost everything works out fine, except when I scroll and it reaches the points where content offset should be updated it stops the scrolling animation and stops.

I had similar problems with my own implementation, that's why I found yours in the first place.
Do you have any idea why is this happening? My calculations and numbers are exactly like yours. Am I missing some property or config which discards animations when contentOffset is updated?

public override void Scrolled(UIScrollView scrollView)
{
    var boundarySize = Parent._numberOfBoundaryElements * (Parent.CellSize + Parent.Padding);
    var contentOffsetValue = Parent.ContentOffset.Y;
    if (contentOffsetValue >= Parent.ContentSizeValue - boundarySize)
    {
        var offset = boundarySize - Parent.Padding;
        var updatedOffsetPoint = new CGPoint(0, offset);
        scrollView.ContentOffset = updatedOffsetPoint;
    }
    else if (contentOffsetValue <= 0)
    {
        var boundaryLessSize = Parent.DataSet.Count * (Parent.CellSize + Parent.Padding);
        var updatedOffsetPoint = new CGPoint(0, boundaryLessSize);
        scrollView.ContentOffset = updatedOffsetPoint;
    }
}

infinitescroll-bug

On this gif the black shoes is the first item where the contentOffset is updated.

Hi,

The exact porting would be like:

public override void Scrolled(UIScrollView scrollView)
{
    var boundarySize = Parent._numberOfBoundaryElements * Parent.CellSize + (Parent._numberOfBoundaryElements  * Parent.Padding);
    var contentOffsetValue = Parent.ContentOffset.Y;
    if (contentOffsetValue >= Parent.ContentSizeValue - boundarySize). //assuming Parent.ContentSizeValue is retuning height of contentSize
    {
        var offset = boundarySize - Parent.Padding;
        var updatedOffsetPoint = new CGPoint(0, offset);
        scrollView.ContentOffset = updatedOffsetPoint;
    }
    else if (contentOffsetValue <= 0)
    {
        var boundaryLessSize = Parent.DataSet.Count * Parent.CellSize + (Parent.DataSet.Count * Parent.Padding);
        var updatedOffsetPoint = new CGPoint(0, boundaryLessSize);
        scrollView.ContentOffset = updatedOffsetPoint;
    }
}

Can you check with this code?

Hi,

Thank you for your time and answer. I tried it, but the problem persists.

EDIT:
I also tried to get help on xamarin forums, with no success at the moment.
https://forums.xamarin.com/discussion/122672/infinite-circular-scrolling/p1?new=1