Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Commit

Permalink
updated to v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
michael811125 committed Oct 31, 2023
1 parent 31c80ba commit 86fe6c7
Show file tree
Hide file tree
Showing 79 changed files with 8,717 additions and 412 deletions.
24 changes: 24 additions & 0 deletions Assets/InfiniteScrollView/Scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
## CHANGELOG

## [1.3.0] - 2023-10-31
- Modified All infiniteScrollViews can auto calculate direction by content and cell pivot.
- Modified Samples (Normal direction and Reverse direction).
- Added ScrollToLeft and ScrollToRight (Horizontal).
```C#
public void ScrollToLeft()
public void ScrollToRight()
```
- Added InfiniteScrollView IsAtLeft and IsAtRight.
```C#
public bool IsAtLeft()
public bool IsAtRight()
```
- Rename InfiniteScrollView IsScrollToTop method name to IsAtTop.
```C#
public bool IsAtTop()
```
- Rename InfiniteScrollView IsScrollToBottom method name to IsAtBottom.
```C#
public bool IsAtBottom()
```
- Removed ScrollToTarget method from InfiniteScrollView.
- Optimized code.

## [1.2.1] - 2023-10-24
- Modified InfiniteCell method name (OnUpdate change to OnRefresh more clear).
```C#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,25 @@ public class HorizontalGridInfiniteScrollView : InfiniteScrollView
{
public Vector2 spacing;
public int rowCount = 1;
public bool isAtLeft = true;
public bool isAtRight = true;

public override void RefreshCellVisibility()
{
if (rowCount <= 0)
{
rowCount = 1;
}

// Viewport
float viewportInterval = scrollRect.viewport.rect.width;
float minViewport = -scrollRect.content.anchoredPosition.x;

// Check content direction pivot
if (this._contentDirCoeff == 0) this._contentDirCoeff = scrollRect.content.pivot.x > 0 ? 1f : -1f;

// Set content direction
float minViewport = scrollRect.content.anchoredPosition.x * this._contentDirCoeff;
Vector2 viewportRange = new Vector2(minViewport - extendVisibleRange, minViewport + viewportInterval + extendVisibleRange);

// Hide
float contentWidth = padding.left;
for (int i = 0; i < dataList.Count; i += rowCount)
{
Expand All @@ -35,6 +42,8 @@ public override void RefreshCellVisibility()
}
contentWidth += dataList[i].cellSize.x + spacing.x;
}

// Show
contentWidth = padding.left;
for (int i = 0; i < dataList.Count; i += rowCount)
{
Expand All @@ -46,7 +55,16 @@ public override void RefreshCellVisibility()
var visibleRange = new Vector2(contentWidth, contentWidth + dataList[index].cellSize.x);
if (visibleRange.y >= viewportRange.x && visibleRange.x <= viewportRange.y)
{
SetupCell(index, new Vector2(contentWidth, (dataList[index].cellSize.y + spacing.y) * -j + -(padding.top - padding.bottom)));
InfiniteCell cell = null;
if (cellList[index] == null)
{
if (_cellPool.Count > 0) cell = _cellPool.Dequeue();
else Debug.Log("<color=#ff4242>The cell display error occurred, not enough cells in the cell pool!!!</color>");
}
// Check cell direciton pivot
float dirCoeff = 1f;
if (cell != null) dirCoeff = cell.RectTransform.pivot.x > 0 ? -1f : 1f;
SetupCell(cell, index, new Vector2(contentWidth * dirCoeff, (dataList[index].cellSize.y + spacing.y) * -j + -(padding.top - padding.bottom)));
if (visibleRange.y >= viewportRange.x)
cellList[index].transform.SetAsLastSibling();
else
Expand All @@ -55,15 +73,19 @@ public override void RefreshCellVisibility()
}
contentWidth += dataList[i].cellSize.x + spacing.x;
}

// Check scroll position
if (scrollRect.content.sizeDelta.x > viewportInterval)
{
isAtLeft = viewportRange.x + extendVisibleRange + dataList[0].cellSize.x <= dataList[0].cellSize.x;
isAtRight = scrollRect.content.sizeDelta.x - viewportRange.y + extendVisibleRange + dataList[dataList.Count - 1].cellSize.x <= dataList[dataList.Count - 1].cellSize.x;
this._isAtLeft = viewportRange.x + extendVisibleRange + dataList[0].cellSize.x <= dataList[0].cellSize.x;
this._isAtRight = scrollRect.content.sizeDelta.x - viewportRange.y + extendVisibleRange + dataList[dataList.Count - 1].cellSize.x <= dataList[dataList.Count - 1].cellSize.x;
}
else
{
isAtLeft = true;
isAtRight = true;
this._isAtTop = false;
this._isAtBottom = false;
this._isAtLeft = true;
this._isAtRight = true;
}
}

Expand Down Expand Up @@ -126,7 +148,8 @@ public override void Snap(int index, float duration)

if (scrollRect.content.anchoredPosition.x != width)
{
DoSnapping(new Vector2(-width, 0), duration);
// Check content direction pivot
DoSnapping(new Vector2(width * this._contentDirCoeff, 0), duration);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
using Cysharp.Threading.Tasks;
using System;
using UnityEngine;

namespace HowTungTung
{
public class HorizontalInfiniteScrollView : InfiniteScrollView
{
public float spacing;
public bool isAtLeft = true;
public bool isAtRight = true;

public override async UniTask InitializePool(object args = null)
{
await base.InitializePool(args);
isAtLeft = true;
isAtRight = true;
}

public override void RefreshCellVisibility()
{
if (dataList.Count == 0)
return;

// Viewport
float viewportInterval = scrollRect.viewport.rect.width;
float minViewport = -scrollRect.content.anchoredPosition.x;

// Check content direction pivot
if (this._contentDirCoeff == 0) this._contentDirCoeff = scrollRect.content.pivot.x > 0 ? 1f : -1f;

// Set content direction
float minViewport = scrollRect.content.anchoredPosition.x * this._contentDirCoeff;
Vector2 viewportRange = new Vector2(minViewport - extendVisibleRange, minViewport + viewportInterval + extendVisibleRange);

// Hide
float contentWidth = padding.left;
for (int i = 0; i < dataList.Count; i++)
{
Expand All @@ -34,29 +33,44 @@ public override void RefreshCellVisibility()
}
contentWidth += dataList[i].cellSize.x + spacing;
}

// Show
contentWidth = padding.left;
for (int i = 0; i < dataList.Count; i++)
{
var visibleRange = new Vector2(contentWidth, contentWidth + dataList[i].cellSize.x);
if (visibleRange.y >= viewportRange.x && visibleRange.x <= viewportRange.y)
{
SetupCell(i, new Vector2(contentWidth, -(padding.top - padding.bottom)));
InfiniteCell cell = null;
if (cellList[i] == null)
{
if (_cellPool.Count > 0) cell = _cellPool.Dequeue();
else Debug.Log("<color=#ff4242>The cell display error occurred, not enough cells in the cell pool!!!</color>");
}
// Check cell direciton pivot
float dirCoeff = 1f;
if (cell != null) dirCoeff = cell.RectTransform.pivot.x > 0 ? -1f : 1f;
SetupCell(cell, i, new Vector2(contentWidth * dirCoeff, -(padding.top - padding.bottom)));
if (visibleRange.y >= viewportRange.x)
cellList[i].transform.SetAsLastSibling();
cellList[i]?.transform.SetAsLastSibling();
else
cellList[i].transform.SetAsFirstSibling();
cellList[i]?.transform.SetAsFirstSibling();
}
contentWidth += dataList[i].cellSize.x + spacing;
}

// Check scroll position
if (scrollRect.content.sizeDelta.x > viewportInterval)
{
isAtLeft = viewportRange.x + extendVisibleRange + dataList[0].cellSize.x <= dataList[0].cellSize.x;
isAtRight = scrollRect.content.sizeDelta.x - viewportRange.y + extendVisibleRange + dataList[dataList.Count - 1].cellSize.x <= dataList[dataList.Count - 1].cellSize.x;
this._isAtLeft = viewportRange.x + extendVisibleRange + dataList[0].cellSize.x <= dataList[0].cellSize.x;
this._isAtRight = scrollRect.content.sizeDelta.x - viewportRange.y + extendVisibleRange + dataList[dataList.Count - 1].cellSize.x <= dataList[dataList.Count - 1].cellSize.x;
}
else
{
isAtLeft = true;
isAtRight = true;
this._isAtTop = false;
this._isAtBottom = false;
this._isAtLeft = true;
this._isAtRight = true;
}
}

Expand Down Expand Up @@ -120,7 +134,8 @@ public override void Snap(int index, float duration)

if (scrollRect.content.anchoredPosition.x != width)
{
DoSnapping(new Vector2(-width, 0), duration);
// Check content direction pivot
DoSnapping(new Vector2(width * this._contentDirCoeff, 0), duration);
}
}

Expand Down
Loading

0 comments on commit 86fe6c7

Please sign in to comment.