/// <summary> /// Removes the item data. /// </summary> /// <param name="index">Index.</param> public void RemoveAtItemData(int index) { if (index < 0) { throw new ArgumentOutOfRangeException(nameof(index), "Index is out of range."); } if (index > _itemSizeList.Count) { throw new ArgumentException("Deleted range is out of range."); } var itemIndex = CurrentItemIndex; var itemSizeList = _itemSizeList.ToArray(); InnerInfiniteScrollItemRepository.RemoveAt(index); _itemSizeList.RemoveAt(index); if (itemIndex == index) { MovePositionAt(Math.Min(_itemSizeList.Count - 1, index)); } else if (itemIndex > index) { var removeSize = itemSizeList[index] + itemInterval; MovePosition(CurrentPosition - removeSize); } UpdateContents(); _isUpdateCanvasRequest = true; }
/// <summary> /// Removes the range item data. /// </summary> /// <param name="index">Index.</param> /// <param name="count">Count.</param> public void RemoveRangeItemData(int index, int count) { if (index < 0) { throw new ArgumentOutOfRangeException(nameof(index), "Index is out of range."); } if (count < 0) { throw new ArgumentOutOfRangeException(nameof(count), "Count is out of range."); } if ((count + index) > _itemSizeList.Count) { throw new ArgumentException("Deleted range is out of range."); } var itemIndex = CurrentItemIndex; var itemSizeList = _itemSizeList.ToArray(); InnerInfiniteScrollItemRepository.RemoveRange(index, count); _itemSizeList.RemoveRange(index, count); if (itemIndex >= index && itemIndex <= index + count - 1) { MovePositionAt(Math.Min(_itemSizeList.Count - 1, index)); } else if (itemIndex > index) { var itemSizeRange = new float[count]; Array.Copy(itemSizeList, index, itemSizeRange, 0, count); var removeSize = itemSizeRange.Sum() + itemInterval * (count); MovePosition(CurrentPosition - removeSize); } UpdateContents(); _isUpdateCanvasRequest = true; }
/// <summary> /// Adds the item data. /// </summary> /// <param name="data">Data.</param> public void AddItemData(object data) { InnerInfiniteScrollItemRepository.Add(data); _itemSizeList.Add(defaultItemSize); UpdateContents(); _isUpdateCanvasRequest = true; }
/// <summary> /// Clears the item data. /// </summary> public void ClearItemData() { InnerInfiniteScrollItemRepository.Clear(); _itemSizeList.Clear(); MovePositionAt(0); UpdateContents(); _isUpdateCanvasRequest = true; }
/// <summary> /// Adds the range item data. /// </summary> /// <param name="data">Data.</param> public void AddRangeItemData(IEnumerable <object> data) { var item = data.ToArray(); InnerInfiniteScrollItemRepository.AddRange(item); _itemSizeList.AddRange(Enumerable.Repeat(defaultItemSize, item.Length)); UpdateContents(); _isUpdateCanvasRequest = true; }
/// <summary> /// Sets the item data. /// </summary> /// <param name="data">Data.</param> public void SetItemData(IEnumerable <object> data) { InnerInfiniteScrollItemRepository.Clear(); InnerInfiniteScrollItemRepository.AddRange(data ?? new object[0]); _itemSizeList = Enumerable.Repeat(defaultItemSize, InnerInfiniteScrollItemRepository.Count).ToList(); MovePositionAt(0); UpdateContents(); _isUpdateCanvasRequest = true; }
private void UpdateBinder() { var data = InnerInfiniteScrollItemRepository.ToArray(); var itemSizeList = _itemSizeList.ToArray(); var fullSize = itemSizeList.Sum() + Mathf.Max(itemSizeList.Length - 1, 0f) * itemInterval; for (var i = 0; i < InfiniteScrollBinders.Length; i++) { var index = i; var infiniteScrollBinder = InfiniteScrollBinders[index]; if (_currentBinderIndex > index) { index = instantiatedItemCount + index; } var itemIndex = CurrentItemIndex + index - _currentBinderIndex; float pos; if (data.Length <= itemIndex || itemIndex < 0) { infiniteScrollBinder.Hide(); if (itemIndex < 0) { pos = -((itemInterval + defaultItemSize) * (0 - itemIndex)); } else { pos = fullSize + (itemIndex - data.Length) * defaultItemSize + (itemIndex - data.Length + 1) * itemInterval; } } else { infiniteScrollBinder.UpdateItemData(data[itemIndex], itemIndex); var itemSizeRange = new float[itemIndex]; Array.Copy(itemSizeList, 0, itemSizeRange, 0, itemIndex); pos = itemSizeRange.Sum() + itemInterval * itemIndex; } if (!isReverse) { pos = pos * -1; } switch (direction) { case Direction.Vertical: infiniteScrollBinder.UpdateItemPosition(new Vector2(0, pos)); break; case Direction.Horizontal: infiniteScrollBinder.UpdateItemPosition(new Vector2(pos * -1, 0)); break; default: throw new ArgumentOutOfRangeException(); } } }
/// <summary> /// Inserts the item data. /// </summary> /// <param name="index">Index.</param> /// <param name="data">Data.</param> public void InsertItemData(int index, object data) { InnerInfiniteScrollItemRepository.Insert(index, data); _itemSizeList.Insert(index, defaultItemSize); if (CurrentItemIndex >= index) { MovePosition(CurrentPosition + defaultItemSize + itemInterval); } UpdateContents(); _isUpdateCanvasRequest = true; }
/// <summary> /// Inserts the range item data. /// </summary> /// <param name="index">Index.</param> /// <param name="data">Data.</param> public void InsertRangeItemData(int index, IEnumerable <object> data) { var item = data.ToArray(); InnerInfiniteScrollItemRepository.InsertRange(index, item); _itemSizeList.InsertRange(index, Enumerable.Repeat(defaultItemSize, item.Length)); if (CurrentItemIndex >= index) { var addSize = (defaultItemSize + itemInterval) * item.Length; MovePosition(CurrentPosition + addSize); } UpdateContents(); _isUpdateCanvasRequest = true; }