Previously the BottomSheetBehavior was checking the measured size during onLayout and if it exceeded the max width or height configured it would "adjust" them by directly modifying the width and height on the layout params and then posting a setLayoutParams. This has many problems and is fundamentally the wrong way to do it. First off, a view should never modify the layout params that are configured on it for two reasons, one, they are properties of the parent view group, not the view itself, and two, they are almost always intended for users of the view group to configure, not the view group itself. Modifying the layout params directly is clobbering any previously configured parameter and permanently changing the layout (for example consider the case where the max width is set to 100dp and then later set to 200dp, the view would not be allowed to grow to 200dp because its layout params would already have been clobbered). Secondly the post is a very bad way to apply this max, not only does it trigger an entire layout pass a second time but it does so after having completed the first layout pass so it will cause the bottom sheet to render at the original size and then the capped size, it's both inefficient and will cause user visible jank.
The correct way to apply a maximum width/height is to do it during layout by incorporating it into the measure specs that are passed to the child. This doesn't clobber any state that the user of the view configured (i.e. when the parent measure specs change, e.g. due to screen rotation, the views correctly relayout) and it avoids doing multiple layout passes, the child can measure itself to the correct size the first time.
PiperOrigin-RevId: 387379138
Helpful for the case where the Top App Bar text/icons are still visible underneath a transparent status bar, when the Top App Bar is scrolled up.
PiperOrigin-RevId: 384985602
When BottomSheetBehavior is set to not draggable, it's still forwarding touch event to ViewDragHelper, which causes ViewDragHelper changes its state to dragging although it's not really dragging. This causes bugs like if we change draggable to true during "no-effect" dragging, ViewDragHelper won't report the dragging state change because it thinks the state is not changing.
Fixes this by avoiding forwarding touch events to ViewDragHelper when it's not draggable, so its state won't be changed.
Resolves https://github.com/material-components/material-components-android/issues/2258
PiperOrigin-RevId: 384942764
We disabled ChipTouchHelper on purpose to workaround a Talkback issue but we didn't stop forwarding touch/hover events to ChipTouchHelper, which cause some Talkback logic work incorrectly on certain API levels.
Adds a state variable to avoid using ChipTouchHelper when it's not registered as accessibility delegate to solve the issue.
Resolves https://github.com/material-components/material-components-android/issues/2155
PiperOrigin-RevId: 383911836
If startIconTint is a plain color, refreshStartIconDrawableState() won't update the tint to the new drawable. To solve the issue and make the logic be consistent, calls applyStartIconTint() when a new icon is set.
Resolves https://github.com/material-components/material-components-android/issues/2141
PiperOrigin-RevId: 383632467
MaterialButton is using TextViewCompat.setCompoundDrawablesRelative() under the hood to implement setIcon() operation. TextViewCompat won't call its compound drawables' setVisible() method, on which we rely to start progress indicator drawables automatically.
Calls setVisible() explicitly to start progressing.
Also adds a demo to catalog.
Resolves https://github.com/material-components/material-components-android/issues/2095
PiperOrigin-RevId: 383483364
Calling setValueInternal() will invoke OnChangeListeners if the values have been changed. We shouldn't unconditionally invoke listeners again, otherwise:
- If values haven't changed, OnChangeListeners will still be fired.
- If values have changed, OnChangeListeners will be fired twice.
Removes the unconditional invocation to solve the issue.
PiperOrigin-RevId: 382785198
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
Halo's showing position depends on the focused thumb index, which
would not be updated if there's no need to snap the thumb position.
This causes halo shows under the previously focused thumb if you
click on the exact position of the new thumb.
Always updates the focused thumb when doing snapping to solve the
issue.
Resolves https://www.google.com/url?q=https://github.com/material-components/material-components-android/issues/2150
PiperOrigin-RevId: 381533677
When the selected date is in the end month, the UTC timestamp of it
will be larger than the end month's, which cause us incorrectly
treat the selected date as invalid.
Fixes the logic by consistently use Month as the time unit to do
comparison.
Resolves https://github.com/material-components/material-components-android/issues/2101
PiperOrigin-RevId: 381280448