From ff97a6805c203724d8cd64d7ed7d6fc483c93f16 Mon Sep 17 00:00:00 2001 From: conradchen Date: Wed, 5 Jan 2022 15:13:12 -0500 Subject: [PATCH] [SnackBar] Enforce vertical layout when action text is too long The snack bar content layout is by default horizontal, and we only change it to vertical when the action view is too wide and ellipsizes the message text. Therefore if the layout orientation is already vertical, we should just keep the layout and no need to check if the message text is multi-line again. Resolves https://github.com/material-components/material-components-android/issues/1876 PiperOrigin-RevId: 419885582 --- .../android/material/snackbar/SnackbarContentLayout.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/java/com/google/android/material/snackbar/SnackbarContentLayout.java b/lib/java/com/google/android/material/snackbar/SnackbarContentLayout.java index fcbc4b08050..2312b841291 100644 --- a/lib/java/com/google/android/material/snackbar/SnackbarContentLayout.java +++ b/lib/java/com/google/android/material/snackbar/SnackbarContentLayout.java @@ -75,6 +75,12 @@ void updateActionTextColorAlphaIfNeeded(float actionTextColorAlpha) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); + if (getOrientation() == VERTICAL) { + // The layout is by default HORIZONTAL. We only change it to VERTICAL when the action view + // is too wide and ellipsizes the message text. When the condition is met, we should keep the + // layout as VERTICAL. + return; + } final int multiLineVPadding = getResources().getDimensionPixelSize(R.dimen.design_snackbar_padding_vertical_2lines);