AnimatedInsertRemoveExample Class |
Simple list demonstrating adding and removing items with an animation. Items "pop up" when are inserted and shrink before being removed.
It's assumed that adding/inserting items is not done throgh the InsertItems(Int32, Int32, Boolean, Boolean) or RemoveItems(Int32, Int32, Boolean, Boolean), but only through AnimatedInsert(Int32, MyModel) and AnimatedRemove(Int32), respectively
Namespace: Com.ForbiddenByte.OSA.Demos.AnimatedInsertRemove
public class AnimatedInsertRemoveExample : OSA<MyParams, MyVH>
The AnimatedInsertRemoveExample type exposes the following members.
| Name | Description | |
|---|---|---|
| AnimatedInsertRemoveExample |
| Name | Description | |
|---|---|---|
| AnimatedInsert | Inserting now, then animating | |
| AnimatedRemove | Animating removal, then remove | |
| ChangeItemsCount | Self-explanatory. See ItemCountChangeMode in order to understand how change modes differ from each other. Every count change operation (Refresh(Boolean, Boolean), InsertItems(Int32, Int32, Boolean, Boolean) etc.) ultimately calls this method, so it's a good place for example to fire a custom "ItemsChanged" event, if you need to | |
| CollectItemsSizes |
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, NullableDouble) 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.
(Overrides OSATParams, TItemViewsHolderCollectItemsSizes(ItemCountChangeMode, Int32, Int32, ItemsDescriptor).) | |
| 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, RectTransform, Int32, Boolean, Boolean) shortcut or manually set its itemIndex, instantiate the prefab and call its CollectViews | |
| OnItemIndexChangedDueInsertOrRemove | Called when an insert or remove event happens. You'll only need this if some of your views depend on the item's index itself as opposed to depending only on the model's data For example, if your item is from a leaderboard and each player's place is given by the order of the models (i.e. you don't have an int in the model named 'place'), you may want to display the item's title as '#233 PlayerName'. This works well if you're only using ResetItems(Int32, Boolean, Boolean), but if you'll call InsertItems(Int32, Int32, Boolean, Boolean) or RemoveItems(Int32, Int32, Boolean, Boolean), the indices of some views holders are shifted, while they'll maintain their data. In this case, you'll override this method and only update the title from its model This is an important optimization, because you shouldn't update items that are already updated, especially when fetching them from the web | |
| Start | (Overrides OSATParams, TItemViewsHolderStart.) | |
| Update | (Overrides OSATParams, TItemViewsHolderUpdate.) | |
| 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 |