Skip to content

Commit

Permalink
[Snackbar] Fix maxWidth is not applied on Snackbar
Browse files Browse the repository at this point in the history
During a previous refactoring, the maxWidth enforcement logic was incorrectly moved to the inner layout of snackbar. Moves the logic back to the outer layout so it can be properly applied.

PiperOrigin-RevId: 413938993
  • Loading branch information
drchen authored and josefigueroa168 committed Dec 6, 2021
1 parent b2f05d5 commit 6a3ea94
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Expand Up @@ -376,7 +376,6 @@ protected BaseTransientBottomBar(
((SnackbarContentLayout) content)
.updateActionTextColorAlphaIfNeeded(view.getActionTextColorAlpha());
((SnackbarContentLayout) content).setMaxInlineActionWidth(view.getMaxInlineActionWidth());
((SnackbarContentLayout) content).setMaxWidth(view.getMaxWidth());
}
view.addView(content);

Expand Down Expand Up @@ -1222,6 +1221,15 @@ public void setOnClickListener(@Nullable OnClickListener onClickListener) {
super.setOnClickListener(onClickListener);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (maxWidth > 0 && getMeasuredWidth() > maxWidth) {
widthMeasureSpec = MeasureSpec.makeMeasureSpec(maxWidth, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
Expand Down
Expand Up @@ -37,7 +37,6 @@ public class SnackbarContentLayout extends LinearLayout implements ContentViewCa
private TextView messageView;
private Button actionView;

private int maxWidth;
private int maxInlineActionWidth;

public SnackbarContentLayout(@NonNull Context context) {
Expand Down Expand Up @@ -77,11 +76,6 @@ void updateActionTextColorAlphaIfNeeded(float actionTextColorAlpha) {
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

if (maxWidth > 0 && getMeasuredWidth() > maxWidth) {
widthMeasureSpec = MeasureSpec.makeMeasureSpec(maxWidth, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

final int multiLineVPadding =
getResources().getDimensionPixelSize(R.dimen.design_snackbar_padding_vertical_2lines);
final int singleLineVPadding =
Expand Down Expand Up @@ -162,8 +156,4 @@ public void animateContentOut(int delay, int duration) {
public void setMaxInlineActionWidth(int width) {
maxInlineActionWidth = width;
}

void setMaxWidth(int width) {
maxWidth = width;
}
}

0 comments on commit 6a3ea94

Please sign in to comment.