material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.35k stars 3.06k forks source link

[TabLayout] No tab ripple when TabLayout is inside AppBarLayout #3233

Closed pubiqq closed 1 year ago

pubiqq commented 1 year ago

https://user-images.githubusercontent.com/82187521/218569322-6ec5c063-2ca0-40ea-834e-9a346375c5df.mp4

Material Library version: 1.8.0

OxygenCobalt commented 1 year ago

Can reproduce this issue, however instead of no ripple, I have a weird "spot" ripple that doesn't expand. Issue was seemingly introduced in 1.8.0-alpha02. May be able to bisect it when I get the time.

imhappi commented 1 year ago

It looks like this is happening once we introduced selected tab text appearances. The tab textview started needing to be invalidated whenever a tab is selected due to setting the text appearance. Invalidating the textview causes onLayout to be called in an upward chain, and I think that that there's a weird view invalidation timing thing going on since AppBarLayout's onLayout call seems to be what's causing the ripple to not appear. The RippleDrawable start and exit animations all appear to be getting called. Still needs more investigation

Edit: I found the issue; it is an unfortunate interaction between the AppBarLayout and drawables; the AppBarLayout calls jumpDrawablesToCurrentState in order to update its background drawable elevation, which updates the drawables of all of its children (TabLayout in this case) to their current states...and RippleDrawable's jumpToCurrentState method ends the ripple animation. A fix will probably involve changing AppBarLayout to only jump its own background drawable to the current state, but will need to investigate potential repercussions first