Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Internal] Fix drawable compositing on API < 23 #4166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions lib/java/com/google/android/material/drawable/DrawableUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ public static Drawable compositeTwoLayeredDrawable(
* @param bottomLayerDrawable the drawable to be on the bottom layer
* @param topLayerDrawable the drawable to be on the top layer
* @param topLayerDesiredWidth top layer desired width in pixels, or {@link #INTRINSIC_SIZE} to
* use the intrinsic width.
* use the intrinsic width as the desired one.
* @param topLayerDesiredHeight top layer desired height in pixels, or {@link #INTRINSIC_SIZE} to
* use the intrinsic height.
* use the intrinsic height as the desired one.
*/
@Nullable
public static Drawable compositeTwoLayeredDrawable(
Expand All @@ -258,8 +258,6 @@ 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 @@ -300,10 +298,9 @@ public static Drawable compositeTwoLayeredDrawable(
drawable.setLayerSize(1, topLayerNewWidth, topLayerNewHeight);
drawable.setLayerGravity(1, Gravity.CENTER);
} else {
if (shouldScaleTopLayer) {
topLayerDrawable =
new ScaledDrawableWrapper(topLayerDrawable, topLayerNewWidth, topLayerNewHeight);
}
topLayerDrawable =
new ScaledDrawableWrapper(topLayerDrawable, topLayerNewWidth, topLayerNewHeight);

drawable = new LayerDrawable(new Drawable[] {bottomLayerDrawable, topLayerDrawable});

final int horizontalInset =
Expand Down