Skip to content

An infinite scroll rect implementation for Unity UI that recycles item views to improve performance with large data sets.

License

Notifications You must be signed in to change notification settings

Migzro/Recyclable-Scroll-Rect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

217 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Recyclable Scroll Rect for Unity UI

An ListView implementation for Unityโ€™s UI that recycles item views, designed to handle large data sets efficiently.

๐Ÿ“˜ Features

  • Seamless infinite (or large-scale) scrolling of UI lists.
  • Supports vertical, horizontal layouts with reverse arrangments.
  • Supports grid layouts with start axes and corners.
  • Supports pages layouts (like TikTok).
  • Reuses (recycles) item views instead of creating/destroying repeatedly.
  • Supports multiple gameObject prototypes.
  • Supports unknown item sizes with dynamic layout recalculation.
  • Supports extra visible items for smoother scrolling.
  • Supports reloading of data source.

๐ŸŽฌ Demo

Vertical RSR

Vertical RSR

Horizontal RSR

Horizontal RSR

Grid RSR

Grid RSR

Paged RSR

Paged RSR

Vertical Dynamic RSR with Data Source Reloading

Paged RSR

๐Ÿš€ Installation

1 - OpenUPM

Option 1 โ€” Install via OpenUPM CLI

If you have the OpenUPM CLI installed, run this command in your Unity project root:

openupm add com.migzro.recyclablescrollrect

Option 2 โ€” Install manually via Unity Package Manager

  • Open 'Edit / Project Settings / Package Manager'.
  • Add a new Scoped Registry with
    • Name: OpenUPM
    • URL: https://package.openupm.com
    • Scope(s): com.migzro.recyclablescrollrect
  • Go to 'Window / Package Manager / Packages / My Registries'.
  • Install the Recyclable Scroll Rect package.

You can also add it manually by editing your manifest.json file:

"scopedRegistries": [
    {
        "name": "OpenUPM",
        "url": "https://package.openupm.com",
        "scopes": [
          "com.migzro.recyclablescrollrect"
        ]
    }
]

2 - Unity Package

Download the latest Unity package from the Releases page.

๐Ÿงฉ Samples

Importing from Unity Package Manager

After installing via Package Manager, go to Window > Package Manager, select Recyclable Scroll Rect, and click Samples tab to import any demo.

Unity Package Manager

Importing from Unity Package

Open the sample scenes located in Assets/Recyclable Scroll Rect/Samples to see examples of vertical, horizontal, grid, and paged layouts.

โš™๏ธ Usage

  1. Add the required RSR component to a ScrollRect GameObject.
  2. Implement the IDataSource interface in a MonoBehaviour script to provide data and item views.
public class VerticalRSRDemo : MonoBehaviour, IRSRDataSource
    {
        [SerializeField] private int _itemsCount;
        [SerializeField] private RSR _scrollRect;
        [SerializeField] private GameObject[] _prototypeItems;
        
        private List<string> _dataSource;
        private int _itemCount;

        public int ItemsCount => _itemsCount;
        public bool IsItemSizeKnown => true;
        public GameObject[] PrototypeItems => _prototypeItems;

        private void Start()
        {
            _dataSource = new List<string>();
            for (var i = 0; i < _itemsCount; i++)
                _dataSource.Add(i.ToString());
            _scrollRect.Initialize(this);
        }
        
        public float GetItemSize(int itemIndex)
        {
            return 40.22f;
        }

        public void SetItemData(IItem item, int itemIndex)
        {
            (item as DemoItemPrototype)?.Initialize(_dataSource[itemIndex]);
        }

        public void ItemHidden(IItem item, int itemIndex)
        {
        }

        public GameObject GetItemPrototype(int itemIndex)
        {
            if (itemIndex % 2 == 0)
                return _prototypeItems[0];
            return _prototypeItems[1];
        }

        public void ItemCreated(int itemIndex, IItem item, GameObject itemGo)
        {

        }

        public bool IsItemStatic(int itemIndex)
        {
            return false;
        }

        public void ScrolledToItem(IItem item, int itemIndex)
        {
        }

        public bool IgnoreContentPadding(int itemIndex)
        {
            return false;
        }

        public void PullToRefresh()
        {
        }

        public void PushToClose()
        {
        }

        public void ReachedScrollStart()
        {
        }

        public void ReachedScrollEnd()
        {
        }

        public void LastItemIsVisible()
        {
        }
    }
}

๐Ÿ”ฎ Coming Soon

Hereโ€™s whatโ€™s planned for upcoming releases of Recyclable Scroll Rect:

  • Sections with headers and footers
  • Support for carousel mode

๐Ÿงช Why Use This?

For large lists or grids (hundreds/thousands of items), regular UI instantiation is heavy.
This component reuses item views to keep performance smooth and memory low.

๐Ÿงฉ Example Use Cases

  • Chat message lists
  • Inventories
  • Infinite scrolling feeds
  • Thumbnail grids

๐Ÿ“ Release Notes

See CHANGELOG.md for details.

๐Ÿ“„ License

MIT License โ€” see LICENSE.md.

๐Ÿ™‹ Support

Open an issue on GitHub for help or feature requests.

โ˜• Support Me

If this tool helped you, consider buying me a coffee:

Buy Me A Coffee

Thanks for using Recyclable Scroll Rect โ€” happy scrolling! ๐ŸŽ‰

About

An infinite scroll rect implementation for Unity UI that recycles item views to improve performance with large data sets.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages