89 Commits

Author SHA1 Message Date
rightnao
3d3edce956 [Snackbar] Update motion specs
PiperOrigin-RevId: 470790457
2022-08-30 11:21:45 -04:00
Material Design Team
44cc9b745c Add @CanIgnoreReturnValue to some APIs that return this.
PiperOrigin-RevId: 468721442
2022-08-22 15:22:27 -04:00
leticiars
581f7343c6 [Snackbar] Made snackbar javadoc more clear of how its dismissing works.
PiperOrigin-RevId: 468494275
2022-08-19 10:56:35 -04:00
conradchen
fd5ee4a989 [Snackbar] Avoid update layout if bottom margins for anchor view does not change
Whenever the anchor view is being relaid out, we will try to update the bottom margin of the snack bar, which may cause the anchor view be relaid out again, thus an infinite loop. Avoids updating margins if the bottom margin for anchor view doesn't change to fix the issue.

Resolves https://github.com/material-components/material-components-android/issues/2744

PiperOrigin-RevId: 454885847
2022-06-14 10:19:33 -07:00
dsn5ft
e981f2f96c [Snackbar] Add defensive null check for messageView.getLayout() in SnackbarContentLayout onMeasure
PiperOrigin-RevId: 452776106
2022-06-03 11:59:14 -07:00
conradchen
46fa8cc45b [SnackBar] Fix margins are added multiple times when show() is called
When a snack bar is hidden and its show() method is called, it will be added to the target parent, and at this moment the parent view will set the layout params to the snack bar, with the same existing margins if any. Therefore if the margins are already updated with extra margins, the original margins will be incorrectly updated. This CL introduces a flag to tells this situation from other "real" scenarios in which clients want to update their custom margins.

Resolves https://github.com/material-components/material-components-android/issues/2666

PiperOrigin-RevId: 445159923
2022-04-28 12:37:45 -04:00
dsn5ft
a71781355e [Snackbar] Add shape theming support and update M3 style to use new shapeAppearanceCornerExtraSmall
PiperOrigin-RevId: 444883546
2022-04-27 12:37:04 -04:00
dsn5ft
b62b9a50b0 [Gradle] Update library source and target compatibility to Java 8 and add lambda + method reference usage
PiperOrigin-RevId: 443370295
2022-04-21 16:29:39 -04:00
conradchen
d5856fd036 [Snackbar] Fix the issue that setting margins programmatically does not work
We always use the original margins saved when the snackbar is created to update snackbar's actual margins. Therefore the newly set margins will always be overridden. Fixes this by updating original margins when layout params are set.

Resolves https://github.com/material-components/material-components-android/issues/1076

PiperOrigin-RevId: 427795853
2022-02-11 15:43:45 +00:00
conradchen
4c7be52775 [Snackbar] Support setting max lines programmatically
Resolves https://github.com/material-components/material-components-android/issues/2018

PiperOrigin-RevId: 427305265
2022-02-09 15:59:34 +00:00
conradchen
3cf23e4bf1 [Snackbar] Solve lint error caused by @IntDef
It seems like lint won't take both @IntDef and @IntRange into consideration at the same time. Just uses @IntRange to cover all possible values.

Resolves https://github.com/material-components/material-components-android/issues/1767

PiperOrigin-RevId: 424918785
2022-01-28 11:56:33 -08:00
conradchen
ff97a6805c [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
2022-01-05 23:26:51 -05:00
Material Design Team
cfc00aa5a3 Update android core class definitions across material
PiperOrigin-RevId: 414839941
2021-12-08 14:56:25 +00:00
conradchen
35d9da8f67 [SnackBar] Fix NPE on Android 8 & 9
It seems like on Android 8 & 9 framework's View implementation has a bug that under certain scenarios if we set a view's visibility when view.getParent() is null, it can cause NPE crash.

Fixes this by switching the order of addView and setVisibility() call.

Resolves https://github.com/material-components/material-components-android/issues/917

PiperOrigin-RevId: 413978332
2021-12-06 19:46:57 +00:00
conradchen
6a3ea94ae0 [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
2021-12-06 19:43:13 +00:00
Material Design Team
a487c89185 Internal change
PiperOrigin-RevId: 412135443
2021-11-29 17:35:39 +00:00
conradchen
8729d8ab57 [SnackBar] Fix maxWidth and maxInlineActionWidth are not applied
We load maxWidth and maxInlineActionWidth style attributes in SnackbarContentLayout, but the snackbar styles are only applied to SnackbarLayout. We need to pass the values to SnackbarContentLayout, as we did for actionTextColorAlpha.

Resolves https://github.com/material-components/material-components-android/issues/781

PiperOrigin-RevId: 404320339
2021-10-20 19:18:47 +00:00
pekingme
9de9319b1e [Resources] Added styles in res-public.
PiperOrigin-RevId: 403451624
2021-10-18 15:31:13 -04:00
conradchen
764cd05b9d [M3][Snackbar] Update snackbar dev doc with M3 themes/styles
Also adds missed text appearance attribute.

PiperOrigin-RevId: 395951691
2021-09-15 12:45:45 -07:00
conradchen
41219f05ac [M3][Snackbar] Create snack bar styles
PiperOrigin-RevId: 394314511
2021-09-02 13:01:09 -04:00
conradchen
58ceeab63c [SnackBar] Handle anchor view properly so no memory leak will happen
The anchor view can be detached even when the snack bar (or any
transient bottom bar) is showing. If this situation happens the
global layout listener it registers with the anchor view will
become not removable due to a bug/intended behavior of Android View's
implementation.

We need to remove the listener when the anchor view is detached to
fix the issue.

This CL also refactors the whole implementation of anchor view and consolidates
the anchoring/unanchoring logic to improve readability and robustness of it.

Resolves https://github.com/material-components/material-components-android/issues/2042

PiperOrigin-RevId: 382603130
2021-07-02 08:15:03 -04:00
conradchen
b0558dc006 [Snackbar] Fix memory leak caused by not resetting anchor views
PiperOrigin-RevId: 379830572
2021-06-17 14:51:36 -04:00
Valentin Slawicek
d15d435093 Automated g4 rollback of changelist 350755495
PiperOrigin-RevId: 351144304
2021-01-11 21:10:54 -05:00
Valentin Slawicek
a3b8be845a [Snackbar] Fix last remaining NPE from #917
Resolves https://github.com/material-components/material-components-android/pull/1938

GIT_ORIGIN_REV_ID=2b71fd49e19c577ef2caf17ca5a92c3f069b1fe0
PiperOrigin-RevId: 350755495
2021-01-08 10:28:18 -05:00
Valentin Slawicek
ebd3223147 [Snackbar] Fixes remaining NPEs from #917
Resolves https://github.com/material-components/material-components-android/pull/1887

GIT_ORIGIN_REV_ID=331d064eb02cb4ff1a2b84f274b8d2c98848e9d4
PiperOrigin-RevId: 345283901
2020-12-03 14:45:59 -05:00
Mattia Pagini
2b95793ea6 [BaseTransientBottomBar] Check for nullable AccessibilityService
Resolves https://github.com/material-components/material-components-android/issues/1885
Resolves https://github.com/material-components/material-components-android/pull/1888

GIT_ORIGIN_REV_ID=35572a920b4bdd66e416d428c55416df7c498db6
PiperOrigin-RevId: 343873267
2020-11-23 14:41:28 -05:00
Material Design Team
9659a536b9 [Snackbar] Add support for passing a Context to Snackbar.make()
Currently Snackbar.make() will use the context of the parent view (typically CoordinatorLayout or decor content view) to inflate the Snackbar view. This is not desirable for cases where there may be a ContextThemeWrapper below that parent view, e.g. for a Fragment that uses material theme.

The behavior of existing methods without Context argument remain unchanged.

PiperOrigin-RevId: 340286851
2020-11-03 11:12:55 -05:00
dniz
89a1bf883f [Snackbar] Added ability to have Snackbar position respond to anchor view layout changes
Disabled by default to avoid changes in behavior and breakages in tests

PiperOrigin-RevId: 333299318
2020-09-23 12:10:02 -07:00
Gabriele Mariotti
391d1f8ac5 [Snackbar] Changed dimens according to spec
Resolves https://github.com/material-components/material-components-android/pull/1711
Resolves https://github.com/material-components/material-components-android/issues/1721

GIT_ORIGIN_REV_ID=c039075b65833724b59ecdfde1ba70ed8ae5b8eb
Co-authored-by: pekingme <pekingme@gmail.com>
PiperOrigin-RevId: 333292492
2020-09-23 12:08:37 -07:00
marianomartin
049ad022a6 Delete components build.gradle files
PiperOrigin-RevId: 320944144
2020-07-15 09:38:31 -07:00
marianomartin
555356b03f Internal cleanup
PiperOrigin-RevId: 318134343
2020-06-26 14:06:52 -04:00
isabellekim
c30abe9d7a Update javadocs for Snackbar.
PiperOrigin-RevId: 300406441
2020-03-13 10:46:58 -04:00
marianomartin
934c407d7d Add a setter for maxInlineActionWidth
PiperOrigin-RevId: 295033109
2020-02-14 11:30:12 -05:00
connieshi
bd7de3d412 Add null check in #animateViewIn to guard against the post runnable executing after the view has been destroyed.
Resolves https://github.com/material-components/material-components-android/issues/917

PiperOrigin-RevId: 290300667
2020-01-17 13:57:49 -05:00
dniz
86b2ec3243 Update Snackbar gesture inset calculation to factor in translationY
Fixes issue of compounding margins for legacy Snackbar which uses a slide animation that affects it's position on the screen

Resolves https://github.com/material-components/material-components-android/issues/741

PiperOrigin-RevId: 285246645
2019-12-12 16:10:26 -05:00
dniz
1882fa96b5 Remove ThemeOverlay.AppCompat.Dark from Snackbar mtrl layouts
The theme overlay should no longer be needed now that we explicitly set colors on the Snackbar's message text and action button

Resolves https://github.com/material-components/material-components-android/issues/706

PiperOrigin-RevId: 281067788
2019-11-19 10:21:00 -08:00
marianomartin
115313c0c0 Expose a class for themeoverlay in style
This moves functionality from ThemeEnforcement into a stand alone class.

Resolves https://github.com/material-components/material-components-android/issues/665

PiperOrigin-RevId: 275481343
2019-10-21 10:24:19 -04:00
dniz
0c8c6f6249 Update Snackbar to respect left/right system window insets
PiperOrigin-RevId: 272667571
2019-10-03 11:45:22 -04:00
dniz
4974f31a8b Update Snackbar#setGestureInsetBottomIgnored to return Snackbar
PiperOrigin-RevId: 272522128
2019-10-03 11:43:28 -04:00
dniz
b99709200e Add support for Snackbar message text styling via snackbarTextViewStyle attr
PiperOrigin-RevId: 272198481
2019-10-01 12:35:27 -04:00
isabellekim
2f740c73e3 Update Snackbar's application of backgroundTint so that it applies a tint on a colored background to keep the shadow.
PiperOrigin-RevId: 270970055
2019-09-26 17:53:38 -04:00
isabellekim
95af724ca4 Updates snackbar to support app:backgroundTint and app:backgroundTintMode.
Also adds ability to setBackgroundTintMode programmatically.

PiperOrigin-RevId: 270337384
2019-09-24 12:20:17 -04:00
dniz
03b5cffbb7 Update naming of Snackbar gesture inset ignore flag
PiperOrigin-RevId: 268914646
2019-09-18 14:06:07 -04:00
dniz
72cfef981b Rename prefix mtrl_ to material_ in public resources
PiperOrigin-RevId: 265729121
2019-08-29 12:16:13 -04:00
cketcham
4211a8a794 Add @NonNull and @Nullable annotations
PiperOrigin-RevId: 265057036
2019-08-29 10:25:19 -04:00
dniz
c1098453fc Update Snackbars to respect bottom system gesture inset on Android Q
Ensures that the Snackbar swipe to dismiss gesture doesn't conflict with the Quick Switch gesture

PiperOrigin-RevId: 264836552
2019-08-26 11:34:02 -04:00
dniz
bfcaf43715 Hide BaseTransientBottomBar IntDef annotations
PiperOrigin-RevId: 260144023
2019-07-29 16:38:30 -04:00
dniz
949e64475e Update Snackbar#setAnchorView(int) javadoc to explain how anchor view is found
PiperOrigin-RevId: 259991025
2019-07-29 16:31:45 -04:00
dniz
52ebd29fa6 Add setBackgroundTintList to Snackbar
PiperOrigin-RevId: 259812607
2019-07-25 13:11:25 -04:00
dniz
cc73c2a630 Update TODOs
PiperOrigin-RevId: 259535844
2019-07-23 11:21:39 -04:00