Click or drag to resize

SRIATParams, TItemViewsHolder Methods

The SRIATParams, TItemViewsHolder generic type exposes the following members.

Methods
  NameDescription
Protected methodAwake
Public methodChangeItemsCount
Self-explanatory. See ItemCountChangeMode in order to understand how change modes differ from each other.
Protected methodClearCachedRecyclableItems
Destroying any remaining game objects in the _RecyclableItems list and clearing it
Protected methodClearVisibleItems
Destroying any remaining game objects in the _VisibleItems list, clearing it and setting VisibleItemsCount to 0
Protected methodCollectItemsSizes
This is called during changing the items count. The base implementation reinitializes the items descriptor so that all items will have the same size, specified in DefaultItemSize If overriding the method and the item default size should remain the same as DefaultItemSize, don't forget to call the base implementation! Otherwise, call ReinitializeSizes(ItemCountChangeMode, Int32, Int32, NullableSingle) with the new default size as parameter. Use BeginChangingItemsSizes(Int32) before and EndChangingItemsSizes after setting sizes. The indices of items for which you set custom sizes must be one after another (4,5,6,7.. etc). Gaps are not allowed. Use "itemsDesc[itemIndexInView] = size" syntax for setting custom sizes. In this call, ItemIndex will be the same as itemIndexInView, even if looping is enabled.
Protected methodCreateViewsHolder

Called when there are no recyclable views for itemIndex. Provide a new viewsholder instance for itemIndex. This is the place where you must initialize the viewsholder

via Init(GameObject, Int32, Boolean, Boolean) shortcut or manually set its itemIndex, instantiate the prefab and call its CollectViews

Protected methodDispose
Public methodGetContentSize
Floating point rounding errors occur the bigger the content size, but generally it's accurrate enough. Returns MaxValue if the (virtual) content size is bigger than MaxValue
Public methodGetItemsCount
Public methodGetItemViewsHolder

Get the viewsHolder with a specific index in the "visible items" list.

Example: if you pass 0, the first visible ViewsHolder will be returned (if there's any)

Not to be mistaken to the other method 'GetItemViewsHolderIfVisible(int withItemIndex)', which uses the itemIndex, i.e. the index in the list of data models.

Returns null if the supplied parameter is >= VisibleItemsCount

Public methodGetItemViewsHolderIfVisible(Int32)
Gets the views holder representing the withItemIndex'th item in the list of data models, if it's visible.
Public methodGetItemViewsHolderIfVisible(RectTransform)
Same as GetItemViewsHolderIfVisible(int withItemIndex), but searches by the root RectTransform reference, rather than the item index
Public methodGetItemVirtualInsetFromParentStart

returns the VIRTUAL distance of the item's left (if scroll view is Horizontal) or top (if scroll view is Vertical) edge

from the parent's left (respectively, top) edge

Public methodGetNormalizedPosition
Floating point rounding errors occur the bigger the content size, but generally it's accurrate enough
Public methodGetViewsHolderOfClosestItemToViewportPoint(Single, Single, Single)
distance will be set to MaxValue if no ViewsHolder is found. The point's format is in range [0=startEdge .. 1=endEdge]
Protected methodGetViewsHolderOfClosestItemToViewportPoint(ICollectionTItemViewsHolder, FuncRectTransform, Single, RectTransform, Single, Single, Single, Single, Single)
Public methodGetVirtualAbstractNormalizedScrollPosition

Used internally. Returns values in [0f, 1f] interval, 1 meaning the scrollrect is at start, and 0 meaning end.

It uses a different approach when content size is smaller than viewport's size, so it can yield consistent results for ComputeVisibility(Double)

Public methodInit

Initialize the adapter. This is automatically called in Start(), but it may also be called manually, if for some reason you implement Start() and don't want to call base.Start()

Will call Canvas.ForceUpdateCanvases(), Params.InitIfNeeded(), will initialize the internal state and will change the items count to 0

IMPORTANT: Do not call it in Awake(), OnEnable(), OnDisable(). OnStart() is the best place to do it.

Public methodInsertItems
It preserves previously cached sizes
Protected methodIsRecyclable
Self-explanatory. The default implementation returns true each time
Protected methodOnBeforeRecycleOrDisableViewsHolder
Perfect place to clean the views in order to prepare them to be potentially recycled this frame or soon. newItemIndex will be -1 if the item will be disabled/destroyed instead of being recycled.
Public methodOnBeginDrag
Protected methodOnDestroy
Public methodOnEndDrag
Protected methodOnItemHeightChangedPreTwinPass
Only called for vertical ScrollRects. Called just before a "Twin" ComputeVisibility will execute. This can be used, for example, to disable a ContentSizeFitter on the item which was used to externally calculate the item's size in the current Twin ComputeVisibility pass
Protected methodOnItemWidthChangedPreTwinPass
Same as OnItemHeightChangedPreTwinPass(TItemViewsHolder), but for horizontal ScrollRects
Protected methodOnScrollViewSizeChanged
This is called automatically when the size of the scrollview itself (the game object which has the ScrollRect component attached) changes
Protected methodRebuildLayoutDueToScrollViewSizeChange

Called mainly when it's detected that the scroll view's size has changed. Marks everything for a layout rebuild and then calls Canvas.ForceUpdateCanvases().

IMPORTANT: Make sure to override MarkForRebuild in your views holder implementation if you have child layout groups and call LayoutRebuilder.MarkForRebuild() on them

Public methodRefresh
Same as ResetItemsCount(<currentCount>)
Public methodRemoveItems
It preserves previously cached sizes
Public methodRequestChangeItemSizeAndUpdateLayout(Int32, Single, Boolean, Boolean)

An item width/height can be changed with this method.

Should NOT be called during ComputeVisibilityForCurrentPosition(Boolean, Boolean, Boolean), UpdateViewsHolder(TItemViewsHolder), CreateViewsHolder(Int32) or from any critical view-recycling code. Suggestion: call it from MonBehaviour.Update()

Will change the size of the item's RectTransform to requestedSize and will shift the other items accordingly, if needed.

Public methodRequestChangeItemSizeAndUpdateLayout(TItemViewsHolder, Single, Boolean, Boolean)
See RequestChangeItemSizeAndUpdateLayout(Int32, Single, Boolean, Boolean) for additional info or if you want to resize an item which isn't visible
Public methodResetItems
It clears any previously cached sizes
Protected methodScheduleComputeVisibilityTwinPass

This can be called in order to schedule a "Twin" ComputeVisibility() call after exactly 1 frame.

A use case is to enable a ContentSizeFitter on your item, call this,

and then disable the ContentSizeFitter in OnItemHeightChangedPreTwinPass(TItemViewsHolder) (or OnItemWidthChangedPreTwinPass(TItemViewsHolder) if horizontal ScrollRect)

Public methodScrollTo

By default, it aligns the ScrollRect's content so that the item with itemIndex will be at the top.

But the two optional parameters can be used for more fine-tuning. One common use-case is to set them both at 0.5 so the item will be end up exactly in the middle of the viewport

Public methodSetNormalizedPosition
Floating point rounding errors occur the bigger the content size, but generally it's accurrate enough
Public methodSetVirtualAbstractNormalizedScrollPosition
Same thing as normalizedPosition, just that the position is 1 for start and 0 for end, regardless if using a horizontal or vertical ScrollRect
Protected methodShouldDestroyRecyclableItem
Self-explanatory. The default implementation returns true if isInExcess is true
Public methodSmoothScrollTo
Utility to smooth scroll. Identical to ScrollTo(Int32, Single, Single) in functionality, but the scroll is animated (scroll is done gradually, throughout multiple frames)
Protected methodStart
Protected methodUpdate
Protected methodUpdateViewsHolder

Here the data in your model should be bound to the views. Use newOrRecycled.ItemIndex (ItemIndex) to retrieve its associated model

Note that views holders are re-used (this is the main purpose of this adapter), so a views holder's views will contain data from its previously associated model and if,

for example, you're downloading an image to be set as an icon, it makes sense to first clear the previous one (and probably temporarily replace it with a generic "Loading" image)

Top
See Also