Skip to content

Commit 6039806

Browse files
committed
[Carousel] Update mask size when MaskableFrameLayout size is changed
1 parent 2336c23 commit 6039806

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public MaskableFrameLayout(
6565
@Override
6666
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
6767
super.onSizeChanged(w, h, oldw, oldh);
68-
onMaskChanged();
68+
updateMaskRect();
6969
}
7070

7171
@Override
@@ -120,13 +120,17 @@ public void setMaskXPercentage(float percentage) {
120120
percentage = MathUtils.clamp(percentage, 0F, 1F);
121121
if (maskXPercentage != percentage) {
122122
this.maskXPercentage = percentage;
123-
// Translate the percentage into an actual pixel value of how much of this view should be
124-
// masked away.
125-
float maskWidth = AnimationUtils.lerp(0f, getWidth() / 2F, 0f, 1f, maskXPercentage);
126-
setMaskRectF(new RectF(maskWidth, 0F, (getWidth() - maskWidth), getHeight()));
123+
updateMaskRect();
127124
}
128125
}
129126

127+
private void updateMaskRect() {
128+
// Translate the percentage into an actual pixel value of how much of this view should be
129+
// masked away.
130+
float maskWidth = AnimationUtils.lerp(0f, getWidth() / 2F, 0f, 1f, maskXPercentage);
131+
setMaskRectF(new RectF(maskWidth, 0F, (getWidth() - maskWidth), getHeight()));
132+
}
133+
130134
/**
131135
* Sets the {@link RectF} that this {@link View} will be masked by.
132136
*

0 commit comments

Comments
 (0)