PagerView

EntityVisualQuadLayerViewScrollViewceramic.PagerView (Class)

A scroll view that layouts its items as pages, where each page is exactly the size of the pager view bounds.

This implementation is designed to support a very large number of items without consuming too much CPU, so it's a preferred option over CollectionView if you just need a way to browse through children with all the same size as the pager bounds.

It also supports looping (when paging is enabled)

Key features:

  • Efficient view recycling for large datasets
  • Page-based scrolling with configurable spacing
  • Optional looping for infinite scrolling
  • Preloading of adjacent pages
  • Configurable visibility bounds
var pager = new PagerView();
pager.size(400, 300);
pager.loop = true;
pager.preloadAmplitude = 2; // Preload 2 pages before/after
pager.dataSource = myDataSource;

Instance Members

ui
dataSource: PagerViewDataSource

The data source that provides page views and manages their lifecycle. Setting this will trigger a reload of all pages.


ui
autoDestroyItems: Bool

Whether to automatically destroy page views when they are no longer needed. If false, views are kept alive but deactivated when recycled. Default: true


ui
maxReusableViewsCount: Int

Maximum number of reusable views to keep in the pool. Higher values reduce view creation overhead but consume more memory. Default: 1


ui
visibleOutset: Float

Extra padding beyond the visible bounds to keep pages active. Useful for preloading content just outside the viewport. Default: 0.0


ui
preloadAmplitude: Int

The number of pages to preload before and after, in advance.

  • 0: no preload at all (but usually not recommended as you'll see it)
  • 1: default value, with sibling pages automatically preloaded
  • higher values will preload more pages before and after, usually not needed

ui
hidePagesOutsideBounds: Bool

Whether to deactivate pages that are outside the visible bounds (plus outset). When true, invisible pages have their active property set to false. Default: true


ui
loop: Bool

Loop to the beginning when reaching the end. (ignored if paging is disabled)


ui
childrenDepth: ChildrenDepth

Control how children depth is sorted:

  • SAME: All pages have the same depth
  • INCREMENT: Later pages have higher depth
  • DECREMENT: Earlier pages have higher depth Default: SAME

Defines how page views are managed:

  • RECYCLE: Views are recycled when scrolled out of view
  • FREEZE: Views remain active but frozen when out of view
  • LAZY: Views are created on demand and kept Default: RECYCLE

ui
destroy(): Void

ui
reloadData(): Void

Reload all data from the data source. This will query the data source for the current page count and trigger a layout update.


ui
closestPageIndex(): Int

Get the index of the page closest to the current scroll position. This takes into account the page size, spacing, and looping behavior.

Returns Description
Int The index of the closest page (0-based)

ui
computeLoadedPages(): Void

Compute which pages should be loaded based on current scroll position. This method handles:

  • Loading pages within the preload amplitude
  • Recycling pages that are too far away
  • Managing the reusable view pool
  • Applying looping logic if enabled

ui
getTargetScrollXForPageIndex(pageIndex: Int, ?allowOverscroll: Bool = false): Float

Calculate the target horizontal scroll position for a specific page.

Name Type Default Description
pageIndex Int The index of the target page
allowOverscroll Bool false Whether to allow scrolling beyond boundaries
Returns Description
Float The X scroll position that would center the page

ui
getTargetScrollYForPageIndex(pageIndex: Int, ?allowOverscroll: Bool = false): Float

Calculate the target vertical scroll position for a specific page.

Name Type Default Description
pageIndex Int The index of the target page
allowOverscroll Bool false Whether to allow scrolling beyond boundaries
Returns Description
Float The Y scroll position that would center the page

ui
scrollToPageIndex(pageIndex: Int): Void

Immediately scroll to the specified page without animation.

Name Type Description
pageIndex Int The index of the page to scroll to

ui
smoothScrollToPageIndex(pageIndex: Int, ?duration: Float = 0.15, ?easing: Anonymous): Void

Smoothly scroll to the specified page with animation.

Name Type Default Description
pageIndex Int The index of the page to scroll to
duration Float 0.15 Animation duration in seconds (default: 0.15)
easing Anonymous (optional) Optional easing function for the animation

ui
new(): Void

Private Members

ui
reusableViews: Array<View>

Pool of views available for recycling


ui
prevLayoutWidth: Float

ui
prevLayoutHeight: Float

ui
pageViews: IntMap<View>

Map of currently loaded page views by index


ui
numPages: Int

Total number of pages from the data source


ui
layout(): Void

ui
handlePageView(pageIndex: Int, pageView: View): Void

Configure and position a page view at the given index. Handles positioning, depth sorting, visibility, and looping adjustments.

Name Type
pageIndex Int
pageView View

ui
checkScrollerPosition(): Void

Check and adjust the scroller position for looping behavior. When looping is enabled, this ensures the scroll position wraps around seamlessly at the boundaries.

Metadata

Name Parameters
:build tracker.macros.EventsMacro.build()
:autoBuild tracker.macros.EventsMacro.build()
:build ceramic.macros.EntityMacro.buildForCompletion()
:autoBuild ceramic.macros.EntityMacro.buildForCompletion()