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

Scrollbar and scroll to element #4

Open
aprius opened this issue Nov 5, 2020 · 8 comments
Open

Scrollbar and scroll to element #4

aprius opened this issue Nov 5, 2020 · 8 comments

Comments

@aprius
Copy link

aprius commented Nov 5, 2020

Haro!
Thanks for creating it, it amazing!

But, Can you add support recyclable scroll work correct with scrollbar?
and add method support scroll to element by index.

@MdIqubal
Copy link
Owner

Hey!
Glad that you like the asset.
Scrollbar and scroll to element are in the roadmap. However, I cannot give you a timeline on these as of now since I am a little busy with other projects. I Will start working on these as soon as possible.

@btxsqdr
Copy link

btxsqdr commented Dec 2, 2020

Hey!
Glad that you like the asset.
Scrollbar and scroll to element are in the roadmap. However, I cannot give you a timeline on these as of now since I am a little busy with other projects. I Will start working on these as soon as possible.

Also from our side: Please implement it, as soon as it suits you. Scrollbar is largely useful on PC, of course, where your solution becomes handy if you want to use it for 1,000 items in a grid or list.

@temresen
Copy link

Hey! Thanks for this great asset! It is amazing and really easy to use

Just wondering if there is any update on "scroll to element by index." functionality?

Thanks!

@dhaminitinAltran
Copy link

Just an addition of a scrollbar would make it perfect.

@joaoborks
Copy link

joaoborks commented Jul 27, 2021

Hey everyone! In my case, I had the necessity to scroll to the end of the list. This is how I did it in VerticalRecyclingSystem:

        public void ScrollToEnd()
        {
            var totalItems = DataSource.GetItemCount();
            var totalCells = _cellPool.Count;
            if (_cellHeight * totalItems <= _recyclableViewBounds.size.y)
                return;
            
            int cellIndex = bottomMostCellIndex;
            int itemIndex = totalItems - 1;
            for (int i = 0; i < totalCells; i++)
            {
                DataSource.SetCell(_cachedCells[cellIndex], itemIndex);
                itemIndex--;
                if (cellIndex == 0)
                    cellIndex = totalCells - 1;
                else
                    cellIndex--;
            }
            
            currentItemCount = totalItems;
            
            Content.anchoredPosition = Vector2.up * _recyclableViewBounds.size.y;
        }

This is how I called it in the RecyclableScrollRect:

        public void ScrollDown()
        {
            onValueChanged.RemoveListener(OnValueChangedListener);
            ((VerticalRecyclingSystem)_recyclingSystem).ScrollToEnd();
            verticalNormalizedPosition = 0;
            StopMovement();
            onValueChanged.AddListener(OnValueChangedListener);
        }

It's far from ideal and requires more testing, but it was good enough for my needs. I'd love to actually implement this in a PR caring for the other views and grids, but I can't promise to do that, unfortunately.

@choidaewon
Copy link

choidaewon commented Jan 19, 2022

this:

    public override IEnumerator InitCoroutine(System.Action onInitialized)
    {
        SetTopAnchor(Content);
        Content.anchoredPosition = Vector3.zero;
        yield return null;
        SetRecyclingBounds();

        //Cell Poool
        CreateCellPool();
        currentItemCount = _cellPool.Count;
        topMostCellIndex = 0;
        bottomMostCellIndex = _cellPool.Count - 1;

        //Set content height according to no of rows
        //int noOfRows = (int)Mathf.Ceil((float)_cellPool.Count / (float)_coloumns);
        float contentYSize = 0;
        for (int i = 0; i < currentItemCount; i++)
        {
            contentYSize += _cellPool[i].sizeDelta.y;
            contentYSize += 10; // this is cell spacing
        }
        //float contentYSize = noOfRows * _cellHeight;
        Content.sizeDelta = new Vector2(Content.sizeDelta.x, contentYSize);
        SetTopAnchor(Content);

        if (onInitialized != null) onInitialized();

        Content.anchoredPosition = new Vector2(0, Content.sizeDelta.y - positionOffset);
    }

I don't know if this is a satisfactory answer, but if you apply the height of ScrollRect to positionOffset, it will scroll to the bottom after ReloadData().
I hope this is a hint.

@JPCard
Copy link

JPCard commented Dec 29, 2022

Hi @MdIqubal, I want to thank you for the work you put in this code. I found it very useful.
Regarding scrolling to rows or columns by index I added this code to RecyclableScrollRect.cs, hope you like it.

    /// <summary>
    /// Scrolls to desired row
    /// Pre: Must be initialized before calling this
    /// @author JPCard
    /// </summary>
    /// <param name="rowIndex">number of row to snap to (in range [0; rowCount - 1])</param>
    public void ScrollToRow(float rowIndex)
    {
        StopMovement();
        content.anchoredPosition = new Vector2(content.anchoredPosition.x, rowIndex * PrototypeCell.rect.height);
        OnValueChangedListener(Vector2.zero); // Vector2 parameter is not used
    }

    /// <summary>
    /// Scrolls to desired column
    /// Pre: Must be initialized before calling this
    /// @author JPCard
    /// </summary>
    /// <param name="columnIndex">number of column to snap to (in range [0; columnCount - 1])</param>
    public void ScrollToColumn(float columnIndex)
    {
        StopMovement();
        content.anchoredPosition = new Vector2(columnIndex * PrototypeCell.rect.width, content.anchoredPosition.y);
        OnValueChangedListener(Vector2.zero); // Vector2 parameter is not used
    }

    /// <summary>
    /// Scrolls to desired row and column
    /// Pre: Must be initialized before calling this
    /// @author JPCard
    /// </summary>
    /// <param name="rowIndex">number of row to snap to (in range [0; rowCount - 1])</param>
    /// <param name="columnIndex">number of column to snap to (in range [0; columnCount - 1])</param>
    public void ScrollToRowAndColumn(float rowIndex, float columnIndex)
    {
        StopMovement();
        var cellRect = PrototypeCell.rect;
        content.anchoredPosition = new Vector2(columnIndex * cellRect.width, rowIndex * cellRect.height);
        OnValueChangedListener(Vector2.zero); // Vector2 parameter is not used
    }

`

@Anton111111
Copy link

Hi @MdIqubal, I want to thank you for the work you put in this code. I found it very useful. Regarding scrolling to rows or columns by index I added this code to RecyclableScrollRect.cs, hope you like it.

I think it wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants