Skip to content

Commit 5b4feca

Browse files
committed
fix error
1 parent b28f6a6 commit 5b4feca

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

Assets/Runtime/ScrollView/ScrollView.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,14 @@ protected virtual void InternalScrollTo(int index)
173173
{
174174
// vertical
175175
var value = 1 - (-r.yMax / (this.content.sizeDelta.y - this.refRect.height));
176+
value = Mathf.Clamp01(value);
176177
this.SetNormalizedPosition(value, 1);
177178
}
178179
else
179180
{
180181
// horizontal
181182
var value = r.xMin / (this.content.sizeDelta.x - this.refRect.width);
183+
value = Mathf.Clamp01(value);
182184
this.SetNormalizedPosition(value, 0);
183185
}
184186
}
@@ -337,13 +339,23 @@ private void InternalUpdateData()
337339
}
338340

339341
var newDataCount = 0;
340-
var keepOldItems = (this.willUpdateData & 2) == 0;
341342

342343
if (this.itemCountFunc != null)
343344
{
344345
newDataCount = this.itemCountFunc();
345346
}
346347

348+
this.CheckDataCountChange(this.dataCount, newDataCount);
349+
350+
this.ResetCriticalItems();
351+
352+
this.willUpdateData = 0;
353+
}
354+
355+
protected virtual void CheckDataCountChange(int oldDataCount, int newDataCount)
356+
{
357+
var keepOldItems = (this.willUpdateData & 2) == 0;
358+
347359
if (newDataCount != this.managedItems.Count)
348360
{
349361
if (this.managedItems.Count < newDataCount)
@@ -408,10 +420,6 @@ private void InternalUpdateData()
408420
}
409421

410422
this.dataCount = newDataCount;
411-
412-
this.ResetCriticalItems();
413-
414-
this.willUpdateData = 0;
415423
}
416424

417425
private void ResetCriticalItems()

Assets/Runtime/ScrollView/ScrollViewEx.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ protected override void InternalScrollTo(int index)
103103
base.InternalScrollTo(index - this.startOffset);
104104
}
105105

106+
protected override void CheckDataCountChange(int oldDataCount, int newDataCount)
107+
{
108+
base.CheckDataCountChange(oldDataCount, newDataCount);
109+
this.startOffset = Mathf.Clamp(this.startOffset, 0, Mathf.Max(this.realItemCountFunc() - this.pageSize, 0));
110+
}
111+
106112
private void OnValueChanged(Vector2 position)
107113
{
108114
int toShow;

0 commit comments

Comments
 (0)