Skip to content

Commit 7d6a977

Browse files
imhappiafohrman
authored andcommitted
[Carousel] Fix contained mask logic to only update masks when it is still 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
1 parent fb56ab4 commit 7d6a977

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

lib/java/com/google/android/material/carousel/CarouselLayoutManager.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static com.google.android.material.animation.AnimationUtils.lerp;
2222
import static java.lang.Math.abs;
2323
import static java.lang.Math.max;
24-
import static java.lang.Math.min;
2524

2625
import android.graphics.Canvas;
2726
import android.graphics.Color;
@@ -773,16 +772,17 @@ private void updateChildMaskForLocation(
773772

774773
// If the carousel is a CONTAINED carousel, ensure the mask collapses against the side of the
775774
// container instead of bleeding and being clipped by the RecyclerView's bounds.
775+
// Only do this if there is only one side of the mask that is out of bounds; if
776+
// both sides are out of bounds on the same side, then the whole mask is out of view.
776777
if (carouselStrategy.isContained()) {
777778
float offsetCx = calculateChildOffsetCenterForLocation(child, childCenterLocation, range);
778779
float maskedLeft = offsetCx - (maskRect.width() / 2F);
779780
float maskedRight = offsetCx + (maskRect.width() / 2F);
780-
781-
if (maskedLeft < getParentLeft()) {
782-
maskRect.left = min(maskRect.left + (getParentLeft() - maskedLeft), childWidth / 2F);
781+
if (maskedLeft < getParentLeft() && maskedRight >= getParentLeft()) {
782+
maskRect.left = maskRect.left + (getParentLeft() - maskedLeft);
783783
}
784-
if (maskedRight > getParentRight()) {
785-
maskRect.right = max(maskRect.right - (maskedRight - getParentRight()), childWidth / 2F);
784+
if (maskedRight > getParentRight() && maskedLeft <= getParentRight()) {
785+
maskRect.right = max(maskRect.right - (maskedRight - getParentRight()), maskRect.left);
786786
}
787787
}
788788
((Maskable) child).setMaskRectF(maskRect);

0 commit comments

Comments
 (0)