Skip to content

Commit

Permalink
[MaterialSwitch] Fix drawable scaling for API < 23
Browse files Browse the repository at this point in the history
Resolves #3513

GIT_ORIGIN_REV_ID=d6b880efdab77b6c1171b3f53ee8d3fcf568f838
PiperOrigin-RevId: 563748930
  • Loading branch information
pubiqq authored and leticiarossi committed Sep 8, 2023
1 parent 3bb69f5 commit a10c508
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/java/com/google/android/material/drawable/DrawableUtils.java
Expand Up @@ -254,6 +254,8 @@ public static Drawable compositeTwoLayeredDrawable(
return bottomLayerDrawable;
}

boolean shouldScaleTopLayer =
topLayerDesiredWidth != INTRINSIC_SIZE && topLayerDesiredHeight != INTRINSIC_SIZE;
if (topLayerDesiredWidth == INTRINSIC_SIZE) {
topLayerDesiredWidth = getTopLayerIntrinsicWidth(bottomLayerDrawable, topLayerDrawable);
}
Expand Down Expand Up @@ -294,11 +296,11 @@ public static Drawable compositeTwoLayeredDrawable(
drawable.setLayerSize(1, topLayerNewWidth, topLayerNewHeight);
drawable.setLayerGravity(1, Gravity.CENTER);
} else {
Drawable scaledTopLayerDrawable =
new ScaledDrawableWrapper(topLayerDrawable, topLayerNewWidth, topLayerNewHeight)
.getDrawable();

drawable = new LayerDrawable(new Drawable[] {bottomLayerDrawable, scaledTopLayerDrawable});
if (shouldScaleTopLayer) {
topLayerDrawable =
new ScaledDrawableWrapper(topLayerDrawable, topLayerNewWidth, topLayerNewHeight);
}
drawable = new LayerDrawable(new Drawable[] {bottomLayerDrawable, topLayerDrawable});

final int horizontalInset =
max((bottomLayerDrawable.getIntrinsicWidth() - topLayerNewWidth) / 2, 0);
Expand Down

0 comments on commit a10c508

Please sign in to comment.