Skip to content

Commit 6a3ea94

Browse files
drchenjosefigueroa168
authored andcommitted
[Snackbar] Fix maxWidth is not applied on Snackbar
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
1 parent b2f05d5 commit 6a3ea94

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

lib/java/com/google/android/material/snackbar/BaseTransientBottomBar.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ protected BaseTransientBottomBar(
376376
((SnackbarContentLayout) content)
377377
.updateActionTextColorAlphaIfNeeded(view.getActionTextColorAlpha());
378378
((SnackbarContentLayout) content).setMaxInlineActionWidth(view.getMaxInlineActionWidth());
379-
((SnackbarContentLayout) content).setMaxWidth(view.getMaxWidth());
380379
}
381380
view.addView(content);
382381

@@ -1222,6 +1221,15 @@ public void setOnClickListener(@Nullable OnClickListener onClickListener) {
12221221
super.setOnClickListener(onClickListener);
12231222
}
12241223

1224+
@Override
1225+
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
1226+
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
1227+
if (maxWidth > 0 && getMeasuredWidth() > maxWidth) {
1228+
widthMeasureSpec = MeasureSpec.makeMeasureSpec(maxWidth, MeasureSpec.EXACTLY);
1229+
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
1230+
}
1231+
}
1232+
12251233
@Override
12261234
protected void onLayout(boolean changed, int l, int t, int r, int b) {
12271235
super.onLayout(changed, l, t, r, b);

lib/java/com/google/android/material/snackbar/SnackbarContentLayout.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public class SnackbarContentLayout extends LinearLayout implements ContentViewCa
3737
private TextView messageView;
3838
private Button actionView;
3939

40-
private int maxWidth;
4140
private int maxInlineActionWidth;
4241

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

80-
if (maxWidth > 0 && getMeasuredWidth() > maxWidth) {
81-
widthMeasureSpec = MeasureSpec.makeMeasureSpec(maxWidth, MeasureSpec.EXACTLY);
82-
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
83-
}
84-
8579
final int multiLineVPadding =
8680
getResources().getDimensionPixelSize(R.dimen.design_snackbar_padding_vertical_2lines);
8781
final int singleLineVPadding =
@@ -162,8 +156,4 @@ public void animateContentOut(int delay, int duration) {
162156
public void setMaxInlineActionWidth(int width) {
163157
maxInlineActionWidth = width;
164158
}
165-
166-
void setMaxWidth(int width) {
167-
maxWidth = width;
168-
}
169159
}

0 commit comments

Comments
 (0)