Skip to content

Commit

Permalink
fix issue #178: GridLayout may increase totalCount at any time, so …
Browse files Browse the repository at this point in the history
…fill last row when possible
  • Loading branch information
qiankanglai committed Sep 7, 2024
1 parent 08ac1cf commit ed00b08
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Runtime/LoopHorizontalScrollRect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ protected override bool UpdateItems(ref Bounds viewBounds, ref Bounds contentBou
if (totalSize > 0)
changed = true;
}
else if ((itemTypeEnd % contentConstraintCount != 0) && (itemTypeEnd < totalCount || totalCount < 0))
{
NewItemAtEnd();
}

if (viewBounds.min.x < contentBounds.min.x + m_ContentLeftPadding)
{
Expand Down
4 changes: 4 additions & 0 deletions Runtime/LoopHorizontalScrollRectMulti.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ protected override bool UpdateItems(ref Bounds viewBounds, ref Bounds contentBou
if (totalSize > 0)
changed = true;
}
else if ((itemTypeEnd % contentConstraintCount != 0) && (itemTypeEnd < totalCount || totalCount < 0))
{
NewItemAtEnd();
}

if (viewBounds.min.x < contentBounds.min.x + m_ContentLeftPadding)
{
Expand Down
2 changes: 1 addition & 1 deletion Runtime/LoopScrollRectBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ public void RefreshCells()
// recycle items if we can
for (int i = 0; i < m_Content.childCount; i++)
{
if (itemTypeEnd < totalCount)
if (itemTypeEnd < totalCount || totalCount < 0)
{
ProvideData(m_Content.GetChild(i), itemTypeEnd);
itemTypeEnd++;
Expand Down
5 changes: 5 additions & 0 deletions Runtime/LoopVerticalScrollRect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ protected override bool UpdateItems(ref Bounds viewBounds, ref Bounds contentBou
if (totalSize > 0)
changed = true;
}
// issue #178: grid layout could increase totalCount at any time
else if ((itemTypeEnd % contentConstraintCount != 0) && (itemTypeEnd < totalCount || totalCount < 0))
{
NewItemAtEnd();
}

if (viewBounds.max.y > contentBounds.max.y - m_ContentTopPadding)
{
Expand Down
4 changes: 4 additions & 0 deletions Runtime/LoopVerticalScrollRectMulti.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ protected override bool UpdateItems(ref Bounds viewBounds, ref Bounds contentBou
if (totalSize > 0)
changed = true;
}
else if ((itemTypeEnd % contentConstraintCount != 0) && (itemTypeEnd < totalCount || totalCount < 0))
{
NewItemAtEnd();
}

if (viewBounds.max.y > contentBounds.max.y - m_ContentTopPadding)
{
Expand Down

0 comments on commit ed00b08

Please sign in to comment.