Skip to content

Commit 17baf71

Browse files
imhappidrchen
authored andcommittedOct 19, 2023
[Carousel] Ensure that extra small size is not larger than the large size
resolves #3640 PiperOrigin-RevId: 574514980
1 parent ad2b5f8 commit 17baf71

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed
 

‎lib/java/com/google/android/material/carousel/CarouselStrategyHelper.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import static com.google.android.material.carousel.CarouselStrategy.getChildMaskPercentage;
2121
import static java.lang.Math.max;
22+
import static java.lang.Math.min;
2223

2324
import android.content.Context;
2425
import androidx.annotation.NonNull;
@@ -71,7 +72,8 @@ static KeylineState createLeftAlignedKeylineState(
7172
float availableSpace,
7273
@NonNull Arrangement arrangement) {
7374

74-
float extraSmallChildWidth = getExtraSmallSize(context) + childHorizontalMargins;
75+
float extraSmallChildWidth =
76+
min(getExtraSmallSize(context) + childHorizontalMargins, arrangement.largeSize);
7577

7678
float start = 0F;
7779
float extraSmallHeadCenterX = start - (extraSmallChildWidth / 2F);
@@ -133,7 +135,8 @@ static KeylineState createCenterAlignedKeylineState(
133135
float availableSpace,
134136
@NonNull Arrangement arrangement) {
135137

136-
float extraSmallChildWidth = getExtraSmallSize(context) + childHorizontalMargins;
138+
float extraSmallChildWidth =
139+
min(getExtraSmallSize(context) + childHorizontalMargins, arrangement.largeSize);
137140

138141
float start = 0F;
139142
float extraSmallHeadCenterX = start - (extraSmallChildWidth / 2F);

‎lib/java/com/google/android/material/carousel/UncontainedCarouselStrategy.java

+2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ private KeylineState createCenterAlignedKeylineState(
156156
float mediumSize,
157157
float xSmallSize,
158158
float remainingSpace) {
159+
xSmallSize = min(xSmallSize, largeSize);
159160

160161
float extraSmallMask = getChildMaskPercentage(xSmallSize, largeSize, childMargins);
161162
float mediumMask = getChildMaskPercentage(mediumSize, largeSize, childMargins);
@@ -195,6 +196,7 @@ private KeylineState createLeftAlignedKeylineState(
195196
float mediumSize,
196197
int mediumCount,
197198
float xSmallSize) {
199+
xSmallSize = min(xSmallSize, largeSize);
198200

199201
// Make the left anchor size half the cut off item size to make the motion at the left closer
200202
// to the right where the cut off is.

0 commit comments

Comments
 (0)