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.1
Browse files Browse the repository at this point in the history
  • Loading branch information
michael811125 committed Nov 1, 2023
1 parent 5fc4506 commit ff7192f
Show file tree
Hide file tree
Showing 19 changed files with 446 additions and 305 deletions.
5 changes: 5 additions & 0 deletions Assets/InfiniteScrollView/Scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## CHANGELOG

## [1.3.1] - 2023-11-01
- Fixed determines.
- Modified Samples.
- Optimzied Recycle and SetupCell procedure.

## [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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public override void RefreshCellVisibility()
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();
cellList[index]?.transform.SetAsLastSibling();
else
cellList[index].transform.SetAsFirstSibling();
cellList[index]?.transform.SetAsFirstSibling();
}
}
contentWidth += dataList[i].cellSize.x + spacing.x;
Expand Down
10 changes: 8 additions & 2 deletions Assets/InfiniteScrollView/Scripts/Runtime/InfiniteCellData.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using UnityEngine;
using System;
using UnityEngine;

namespace HowTungTung
{
public class InfiniteCellData
public class InfiniteCellData : IDisposable
{
public int index { get; internal set; }
public Vector2 cellSize;
Expand All @@ -23,5 +24,10 @@ public InfiniteCellData(Vector2 cellSize, object data)
this.cellSize = cellSize;
this.data = data;
}

public void Dispose()
{
this.data = null;
}
}
}
24 changes: 15 additions & 9 deletions Assets/InfiniteScrollView/Scripts/Runtime/InfiniteScrollView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public virtual async UniTask Remove(int index, bool autoRefresh = true)
index < 0)
return;

dataList[index].Dispose();
dataList.RemoveAt(index);
this.RefreshCellDataIndex(index);
RecycleCell(index);
Expand Down Expand Up @@ -351,13 +352,14 @@ private async UniTask ProcessSnapping(Vector2 target, float duration)

protected void SetupCell(InfiniteCell cell, int index, Vector2 pos)
{
if (cell == null) return;

cell.gameObject.SetActive(true);
cell.CellData = dataList[index];
cell.RectTransform.anchoredPosition = pos;
cellList[index] = cell;
cell.onSelected += OnCellSelected;
if (cell != null)
{
cellList[index] = cell;
cell.CellData = dataList[index];
cell.RectTransform.anchoredPosition = pos;
cell.onSelected += OnCellSelected;
cell.gameObject.SetActive(true);
}
}

protected void RecycleCell(int index)
Expand All @@ -366,10 +368,10 @@ protected void RecycleCell(int index)
{
var cell = cellList[index];
cellList[index] = null;
_cellPool.Enqueue(cell);
cell.onSelected -= OnCellSelected;
cell.gameObject.SetActive(false);
cell.OnRecycle();
cell.onSelected -= OnCellSelected;
_cellPool.Enqueue(cell);
}
}

Expand All @@ -388,6 +390,10 @@ public virtual async UniTask Clear()
await InitializePool();
scrollRect.velocity = Vector2.zero;
scrollRect.content.anchoredPosition = Vector2.zero;
for (int i = 0; i < dataList.Count; i++)
{
dataList[i].Dispose();
}
dataList.Clear();
for (int i = 0; i < cellList.Count; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public override void RefreshCellVisibility()
if (cell != null) dirCoeff = cell.RectTransform.pivot.y > 0 ? -1f : 1f;
SetupCell(cell, index, new Vector2((dataList[index].cellSize.x + spacing.x) * j + (padding.left - padding.right), contentHeight * dirCoeff));
if (visibleRange.y >= viewportRange.x)
cellList[index].transform.SetAsLastSibling();
cellList[index]?.transform.SetAsLastSibling();
else
cellList[index].transform.SetAsFirstSibling();
cellList[index]?.transform.SetAsFirstSibling();
}
}
contentHeight += dataList[i].cellSize.y + spacing.y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ RectTransform:
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 30, y: 30}
m_SizeDelta: {x: 288.41, y: 0}
m_SizeDelta: {x: 290, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!114 &2096381313
MonoBehaviour:
Expand Down Expand Up @@ -426,12 +426,11 @@ MonoBehaviour:
m_Text: 'Vertical Normal Conditions:
1. Viewport content pivot (x,
y) = (0, 1) and align [Stretch-Top].
1. Viewport content pivot (x, y) = (0,
1) and align [Stretch-Top].
2. Cell pivot (x, y) = (0, 1)
and align [Left-Top].'
2. Cell pivot (x, y) = (0, 1) and align [Left-Top].'
--- !u!222 &2096381315
CanvasRenderer:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -575,7 +574,7 @@ PrefabInstance:
- target: {fileID: 1855459386986698912, guid: a17a812836c754f11a7ba8e246512cd8,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
value: 0.00067811005
objectReference: {fileID: 0}
- target: {fileID: 1855459387362808913, guid: a17a812836c754f11a7ba8e246512cd8,
type: 3}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ RectTransform:
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 30, y: 30}
m_SizeDelta: {x: 288.41, y: 0}
m_SizeDelta: {x: 290, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!114 &2100359777
MonoBehaviour:
Expand Down Expand Up @@ -586,12 +586,12 @@ MonoBehaviour:
m_Text: 'Vertical Reverse Conditions:
1. Viewport content pivot (x,
y) = (0, 0) and align [Stretch-Bottom].
1. Viewport content pivot (x, y) =
(0, 0) and align [Stretch-Bottom].
2. Cell pivot (x, y) = (0,
0) and align [Left-Bottom].'
2. Cell pivot (x, y) = (0, 0) and align
[Left-Bottom].'
--- !u!222 &2100359779
CanvasRenderer:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ RectTransform:
m_AnchorMin: {x: 1, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -30, y: -30}
m_SizeDelta: {x: 288.41003, y: 0}
m_SizeDelta: {x: 290, y: 0}
m_Pivot: {x: 1, y: 1}
--- !u!114 &272292816
MonoBehaviour:
Expand Down Expand Up @@ -213,12 +213,12 @@ MonoBehaviour:
m_Text: 'Horizontal Normal Conditions:
1. Viewport content pivot (x,
y) = (0, 1) and align [Stretch-Left].
1. Viewport content pivot (x, y) =
(0, 1) and align [Stretch-Left].
2. Cell pivot (x, y) = (0, 1)
and align [Left-Top].'
2. Cell pivot (x, y) = (0, 1) and align
[Left-Top].'
--- !u!222 &272292818
CanvasRenderer:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ PrefabInstance:
- target: {fileID: 7911875008147736594, guid: 421612e6beac0d541a07ea5d97bb7677,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
value: 0.00079345703
objectReference: {fileID: 0}
- target: {fileID: 7911875008147736594, guid: 421612e6beac0d541a07ea5d97bb7677,
type: 3}
Expand Down Expand Up @@ -518,7 +518,7 @@ RectTransform:
m_AnchorMin: {x: 1, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -30, y: -30}
m_SizeDelta: {x: 288.41003, y: 0}
m_SizeDelta: {x: 290, y: 0}
m_Pivot: {x: 1, y: 1}
--- !u!114 &2039907101
MonoBehaviour:
Expand Down Expand Up @@ -570,12 +570,12 @@ MonoBehaviour:
m_Text: 'Horizontal Reverse Conditions:
1. Viewport content pivot (x,
y) = (1, 1) and align [Stretch-Right].
1. Viewport content pivot (x, y)
= (1, 1) and align [Stretch-Right].
2. Cell pivot (x, y) = (1,
1) and align [Right-Top].'
2. Cell pivot (x, y) = (1, 1) and
align [Right-Top].'
--- !u!222 &2039907103
CanvasRenderer:
m_ObjectHideFlags: 0
Expand Down
Loading

0 comments on commit ff7192f

Please sign in to comment.