@@ -431,19 +431,26 @@ public void onLayoutCompleted(State state) {
431
431
private void addViewsStart (Recycler recycler , int startPosition ) {
432
432
float start = calculateChildStartForFill (startPosition );
433
433
for (int i = startPosition ; i >= 0 ; i --) {
434
- ChildCalculations calculations = makeChildCalculations (recycler , start , i );
435
- if (isLocOffsetOutOfFillBoundsStart (calculations .offsetCenter , calculations .range )) {
434
+ float center = addEnd (start , currentKeylineState .getItemSize () / 2F );
435
+ KeylineRange range =
436
+ getSurroundingKeylineRange (currentKeylineState .getKeylines (), center , false );
437
+
438
+ float offsetCenter = calculateChildOffsetCenterForLocation (center , range );
439
+ if (isLocOffsetOutOfFillBoundsStart (offsetCenter , range )) {
436
440
break ;
437
441
}
438
442
start = addStart (start , currentKeylineState .getItemSize ());
439
443
440
444
// If this child's start is beyond the end of the container, don't add the child but continue
441
445
// to loop so we can eventually get to children that are within bounds.
442
- if (isLocOffsetOutOfFillBoundsEnd (calculations . offsetCenter , calculations . range )) {
446
+ if (isLocOffsetOutOfFillBoundsEnd (offsetCenter , range )) {
443
447
continue ;
444
448
}
449
+ View child = recycler .getViewForPosition (i );
450
+ measureChildWithMargins (child , 0 , 0 );
445
451
// Add this child to the first index of the RecyclerView.
446
- addAndLayoutView (calculations .child , /* index= */ 0 , calculations );
452
+ addAndLayoutView (
453
+ child , /* index= */ 0 , new ChildCalculations (child , center , offsetCenter , range ));
447
454
}
448
455
}
449
456
@@ -476,19 +483,26 @@ private void addViewAtPosition(@NonNull Recycler recycler, int startPosition, in
476
483
private void addViewsEnd (Recycler recycler , State state , int startPosition ) {
477
484
float start = calculateChildStartForFill (startPosition );
478
485
for (int i = startPosition ; i < state .getItemCount (); i ++) {
479
- ChildCalculations calculations = makeChildCalculations (recycler , start , i );
480
- if (isLocOffsetOutOfFillBoundsEnd (calculations .offsetCenter , calculations .range )) {
486
+ float center = addEnd (start , currentKeylineState .getItemSize () / 2F );
487
+ KeylineRange range =
488
+ getSurroundingKeylineRange (currentKeylineState .getKeylines (), center , false );
489
+
490
+ float offsetCenter = calculateChildOffsetCenterForLocation (center , range );
491
+ if (isLocOffsetOutOfFillBoundsEnd (offsetCenter , range )) {
481
492
break ;
482
493
}
483
494
start = addEnd (start , currentKeylineState .getItemSize ());
484
495
485
496
// If this child's end is beyond the start of the container, don't add the child but continue
486
497
// to loop so we can eventually get to children that are within bounds.
487
- if (isLocOffsetOutOfFillBoundsStart (calculations . offsetCenter , calculations . range )) {
498
+ if (isLocOffsetOutOfFillBoundsStart (offsetCenter , range )) {
488
499
continue ;
489
500
}
501
+ View child = recycler .getViewForPosition (i );
502
+ measureChildWithMargins (child , 0 , 0 );
490
503
// Add this child to the last index of the RecyclerView
491
- addAndLayoutView (calculations .child , /* index= */ -1 , calculations );
504
+ addAndLayoutView (
505
+ child , /* index= */ -1 , new ChildCalculations (child , center , offsetCenter , range ));
492
506
}
493
507
}
494
508
@@ -562,7 +576,7 @@ private ChildCalculations makeChildCalculations(Recycler recycler, float start,
562
576
KeylineRange range =
563
577
getSurroundingKeylineRange (currentKeylineState .getKeylines (), center , false );
564
578
565
- float offsetCenter = calculateChildOffsetCenterForLocation (child , center , range );
579
+ float offsetCenter = calculateChildOffsetCenterForLocation (center , range );
566
580
return new ChildCalculations (child , center , offsetCenter , range );
567
581
}
568
582
@@ -889,13 +903,12 @@ private float calculateChildStartForFill(int startPosition) {
889
903
/**
890
904
* Remaps and returns the child's offset center from the end-to-end layout model.
891
905
*
892
- * @param child the child to calculate the offset for
893
906
* @param childCenterLocation the center of the child in the end-to-end layout model
894
907
* @param range the keyline range that the child is currently between
895
908
* @return the location along the scroll axis where the child should be located
896
909
*/
897
910
private float calculateChildOffsetCenterForLocation (
898
- View child , float childCenterLocation , KeylineRange range ) {
911
+ float childCenterLocation , KeylineRange range ) {
899
912
float offsetCenter =
900
913
lerp (
901
914
range .leftOrTop .locOffset ,
@@ -915,11 +928,9 @@ private float calculateChildOffsetCenterForLocation(
915
928
// Calculate how far past the nearest keyline (either the first or last keyline) this item
916
929
// has scrolled in the end-to-end layout. Then use that value calculate what would be a
917
930
// Keyline#locOffset.
918
- LayoutParams lp = (LayoutParams ) child .getLayoutParams ();
919
- float marginMask = orientationHelper .getMaskMargins (lp ) / currentKeylineState .getItemSize ();
920
931
float outOfBoundOffset =
921
932
(childCenterLocation - range .rightOrBottom .loc )
922
- * (1F - range .rightOrBottom .mask + marginMask );
933
+ * (1F - range .rightOrBottom .mask );
923
934
offsetCenter += outOfBoundOffset ;
924
935
}
925
936
@@ -977,7 +988,7 @@ private void updateChildMaskForLocation(
977
988
978
989
RectF maskRect = orientationHelper .getMaskRect (childHeight , childWidth , maskHeight , maskWidth );
979
990
980
- float offsetCenter = calculateChildOffsetCenterForLocation (child , childCenterLocation , range );
991
+ float offsetCenter = calculateChildOffsetCenterForLocation (childCenterLocation , range );
981
992
float maskedTop = offsetCenter - (maskRect .height () / 2F );
982
993
float maskedBottom = offsetCenter + (maskRect .height () / 2F );
983
994
float maskedLeft = offsetCenter - (maskRect .width () / 2F );
@@ -1508,7 +1519,7 @@ private float offsetChild(View child, float startOffset, float halfItemSize, Rec
1508
1519
float center = addEnd (startOffset , halfItemSize );
1509
1520
KeylineRange range =
1510
1521
getSurroundingKeylineRange (currentKeylineState .getKeylines (), center , false );
1511
- float offsetCenter = calculateChildOffsetCenterForLocation (child , center , range );
1522
+ float offsetCenter = calculateChildOffsetCenterForLocation (center , range );
1512
1523
1513
1524
// Offset the child so its center is at offsetCenter
1514
1525
super .getDecoratedBoundsWithMargins (child , boundsRect );
0 commit comments