Skip to content

Commit

Permalink
fix issue #128
Browse files Browse the repository at this point in the history
  • Loading branch information
qiankanglai committed Apr 23, 2022
1 parent 964bca7 commit 8645ad6
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Runtime/LoopHorizontalScrollRect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected override bool UpdateItems(ref Bounds viewBounds, ref Bounds contentBou
changed = true;
}

if (viewBounds.max.x > contentBounds.max.x - m_ContentRightPadding)
if (viewBounds.max.x > contentBounds.max.x - threshold - m_ContentRightPadding)
{
float size = NewItemAtEnd(), totalSize = size;
while (size > 0 && viewBounds.max.x > contentBounds.max.x - m_ContentRightPadding + totalSize)
Expand All @@ -151,7 +151,7 @@ protected override bool UpdateItems(ref Bounds viewBounds, ref Bounds contentBou
changed = true;
}

if (viewBounds.min.x < contentBounds.min.x + m_ContentLeftPadding)
if (viewBounds.min.x < contentBounds.min.x + threshold + m_ContentLeftPadding)
{
float size = NewItemAtStart(), totalSize = size;
while (size > 0 && viewBounds.min.x < contentBounds.min.x + m_ContentLeftPadding - totalSize)
Expand Down
4 changes: 2 additions & 2 deletions Runtime/LoopHorizontalScrollRectMulti.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected override bool UpdateItems(ref Bounds viewBounds, ref Bounds contentBou
changed = true;
}

if (viewBounds.max.x > contentBounds.max.x - m_ContentRightPadding)
if (viewBounds.max.x > contentBounds.max.x - threshold - m_ContentRightPadding)
{
float size = NewItemAtEnd(), totalSize = size;
while (size > 0 && viewBounds.max.x > contentBounds.max.x - m_ContentRightPadding + totalSize)
Expand All @@ -151,7 +151,7 @@ protected override bool UpdateItems(ref Bounds viewBounds, ref Bounds contentBou
changed = true;
}

if (viewBounds.min.x < contentBounds.min.x + m_ContentLeftPadding)
if (viewBounds.min.x < contentBounds.min.x + threshold + m_ContentLeftPadding)
{
float size = NewItemAtStart(), totalSize = size;
while (size > 0 && viewBounds.min.x < contentBounds.min.x + m_ContentLeftPadding - totalSize)
Expand Down
2 changes: 1 addition & 1 deletion Runtime/LoopScrollRectBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ IEnumerator ScrollToCellCoroutine(int index, float speed)
protected abstract void ProvideData(Transform transform, int index);

/// <summary>
/// Refresh item data
/// Refresh item data (if totalCount increases, please call `RefillCells` instead)
/// </summary>
public void RefreshCells()
{
Expand Down
4 changes: 2 additions & 2 deletions Runtime/LoopVerticalScrollRect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected override bool UpdateItems(ref Bounds viewBounds, ref Bounds contentBou
changed = true;
}

if (viewBounds.min.y < contentBounds.min.y + m_ContentBottomPadding)
if (viewBounds.min.y < contentBounds.min.y + threshold + m_ContentBottomPadding)
{
float size = NewItemAtEnd(), totalSize = size;
while (size > 0 && viewBounds.min.y < contentBounds.min.y + m_ContentBottomPadding - totalSize)
Expand All @@ -150,7 +150,7 @@ protected override bool UpdateItems(ref Bounds viewBounds, ref Bounds contentBou
changed = true;
}

if (viewBounds.max.y > contentBounds.max.y - m_ContentTopPadding)
if (viewBounds.max.y > contentBounds.max.y - threshold - m_ContentTopPadding)
{
float size = NewItemAtStart(), totalSize = size;
while (size > 0 && viewBounds.max.y > contentBounds.max.y - m_ContentTopPadding + totalSize)
Expand Down
4 changes: 2 additions & 2 deletions Runtime/LoopVerticalScrollRectMulti.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected override bool UpdateItems(ref Bounds viewBounds, ref Bounds contentBou
changed = true;
}

if (viewBounds.min.y < contentBounds.min.y + m_ContentBottomPadding)
if (viewBounds.min.y < contentBounds.min.y + threshold + m_ContentBottomPadding)
{
float size = NewItemAtEnd(), totalSize = size;
while (size > 0 && viewBounds.min.y < contentBounds.min.y + m_ContentBottomPadding - totalSize)
Expand All @@ -150,7 +150,7 @@ protected override bool UpdateItems(ref Bounds viewBounds, ref Bounds contentBou
changed = true;
}

if (viewBounds.max.y > contentBounds.max.y - m_ContentTopPadding)
if (viewBounds.max.y > contentBounds.max.y - threshold - m_ContentTopPadding)
{
float size = NewItemAtStart(), totalSize = size;
while (size > 0 && viewBounds.max.y > contentBounds.max.y - m_ContentTopPadding + totalSize)
Expand Down
5 changes: 3 additions & 2 deletions Samples~/Demo/Scripts/UI_ControlData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ private void OnButtonAddDataClick()
{
int RandomResult = Random.Range(0, 10);
m_ListBank.AddContent(RandomResult);
m_InitOnStart.m_LoopScrollRect.totalCount = m_InitOnStart.m_LoopListBank.GetListLength();
m_InitOnStart.m_LoopScrollRect.RefreshCells();
}

m_InitOnStart.m_LoopScrollRect.totalCount = m_InitOnStart.m_LoopListBank.GetListLength();
m_InitOnStart.m_LoopScrollRect.RefreshCells();
}

private void OnButtonSetDataClick()
Expand Down

0 comments on commit 8645ad6

Please sign in to comment.