Skip to content

Commit

Permalink
[Carousel] Ensure that extra small size is not larger than the large …
Browse files Browse the repository at this point in the history
…size

resolves #3640

PiperOrigin-RevId: 574514980
  • Loading branch information
imhappi authored and drchen committed Oct 19, 2023
1 parent ad2b5f8 commit 17baf71
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Expand Up @@ -19,6 +19,7 @@

import static com.google.android.material.carousel.CarouselStrategy.getChildMaskPercentage;
import static java.lang.Math.max;
import static java.lang.Math.min;

import android.content.Context;
import androidx.annotation.NonNull;
Expand Down Expand Up @@ -71,7 +72,8 @@ static KeylineState createLeftAlignedKeylineState(
float availableSpace,
@NonNull Arrangement arrangement) {

float extraSmallChildWidth = getExtraSmallSize(context) + childHorizontalMargins;
float extraSmallChildWidth =
min(getExtraSmallSize(context) + childHorizontalMargins, arrangement.largeSize);

float start = 0F;
float extraSmallHeadCenterX = start - (extraSmallChildWidth / 2F);
Expand Down Expand Up @@ -133,7 +135,8 @@ static KeylineState createCenterAlignedKeylineState(
float availableSpace,
@NonNull Arrangement arrangement) {

float extraSmallChildWidth = getExtraSmallSize(context) + childHorizontalMargins;
float extraSmallChildWidth =
min(getExtraSmallSize(context) + childHorizontalMargins, arrangement.largeSize);

float start = 0F;
float extraSmallHeadCenterX = start - (extraSmallChildWidth / 2F);
Expand Down
Expand Up @@ -156,6 +156,7 @@ private KeylineState createCenterAlignedKeylineState(
float mediumSize,
float xSmallSize,
float remainingSpace) {
xSmallSize = min(xSmallSize, largeSize);

float extraSmallMask = getChildMaskPercentage(xSmallSize, largeSize, childMargins);
float mediumMask = getChildMaskPercentage(mediumSize, largeSize, childMargins);
Expand Down Expand Up @@ -195,6 +196,7 @@ private KeylineState createLeftAlignedKeylineState(
float mediumSize,
int mediumCount,
float xSmallSize) {
xSmallSize = min(xSmallSize, largeSize);

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

0 comments on commit 17baf71

Please sign in to comment.