@@ -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 ( )
0 commit comments