Skip to content


[Carousel] Fix contained mask logic to only update masks when it is s…
Browse files Browse the repository at this point in the history
…till in view, and remove restrictions on mask size with childWidth/2F. The only restriction is that the right of the mask must be greater than the left of the mask.

PiperOrigin-RevId: 537080963
  • Loading branch information
imhappi authored and afohrman committed Jun 5, 2023
1 parent fb56ab4 commit 7d6a977
Showing 1 changed file with 6 additions and 6 deletions.
Expand Up @@ -21,7 +21,6 @@
import static;
import static java.lang.Math.abs;
import static java.lang.Math.max;
import static java.lang.Math.min;

Expand Down Expand Up @@ -773,16 +772,17 @@ private void updateChildMaskForLocation(

// If the carousel is a CONTAINED carousel, ensure the mask collapses against the side of the
// container instead of bleeding and being clipped by the RecyclerView's bounds.
// Only do this if there is only one side of the mask that is out of bounds; if
// both sides are out of bounds on the same side, then the whole mask is out of view.
if (carouselStrategy.isContained()) {
float offsetCx = calculateChildOffsetCenterForLocation(child, childCenterLocation, range);
float maskedLeft = offsetCx - (maskRect.width() / 2F);
float maskedRight = offsetCx + (maskRect.width() / 2F);

if (maskedLeft < getParentLeft()) {
maskRect.left = min(maskRect.left + (getParentLeft() - maskedLeft), childWidth / 2F);
if (maskedLeft < getParentLeft() && maskedRight >= getParentLeft()) {
maskRect.left = maskRect.left + (getParentLeft() - maskedLeft);
if (maskedRight > getParentRight()) {
maskRect.right = max(maskRect.right - (maskedRight - getParentRight()), childWidth / 2F);
if (maskedRight > getParentRight() && maskedLeft <= getParentRight()) {
maskRect.right = max(maskRect.right - (maskedRight - getParentRight()), maskRect.left);
((Maskable) child).setMaskRectF(maskRect);
Expand Down

0 comments on commit 7d6a977

Please sign in to comment.