ContentSizeFitterExample Class |
The prefabhas a disabled ContentSizeFitter added, which will be enabled in UpdateViewsHolder(MyItemViewsHolder)
if the size was not already calculated (in a previous call), then ScheduleComputeVisibilityTwinPass(Boolean) should be called.
After that, as soon as UpdateViewsHolder(MyItemViewsHolder) was called for all visible items, you'll receive a callback to OnItemHeightChangedPreTwinPass(TItemViewsHolder)
(or OnItemWidthChangedPreTwinPass(TItemViewsHolder) for horizontal ScrollRects) for each of them,
where you can disable the content size fitter.
A "Twin" ComputeVisibility(Double) pass is executed after the current one has finished (meaning UpdateViewsHolder(MyItemViewsHolder) was called for all visible items).
Namespace: Com.ForbiddenByte.OSA.Demos.ContentSizeFitter
public class ContentSizeFitterExample : OSA<MyParams, MyItemViewsHolder>
The ContentSizeFitterExample type exposes the following members.
Name | Description | |
---|---|---|
ContentSizeFitterExample |
Name | Description | |
---|---|---|
CreateRandomModel | ||
CreateViewsHolder | 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 | |
OnItemHeightChangedPreTwinPass |
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 (Overrides OSATParams, TItemViewsHolderOnItemHeightChangedPreTwinPass(TItemViewsHolder).) | |
OnItemIndexChangedDueInsertOrRemove | Because the index is shown in the title, this may lead to a content size change, so mark the ViewsHolder to have its size recalculated For more info, see OnItemIndexChangedDueInsertOrRemove(TItemViewsHolder, Int32, Boolean, Int32) | |
RebuildLayoutDueToScrollViewSizeChange | 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 | |
Start | (Overrides OSATParams, TItemViewsHolderStart.) | |
UpdateViewsHolder | 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) Note that this is not called for items that will remain visible after an Insert or Remove operation is done |