material-components / material-components-android

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

[MaterialSwitch] Checked change animations don't work within RecyclerView or ViewPager2 #2224

Closed mateuszkwiecinski closed 3 years ago

mateuszkwiecinski commented 3 years ago

Description: MaterialSwitch's animations are not fired after RecyclerView re-attaches the view

Expected behavior: I expect animations to work consistently, the same way as they were before switching the tab/scrolling the list.

Source code: https://github.com/mateuszkwiecinski/recyclerview_doesnt_work

Android API version: All? Tested on 28 and 30

Material Library version: 1.3.0, 1.4.0-beta01

Device: Android Emulator

To help us triage faster, please check to make sure you are using the latest version of the library.

We also happily accept pull requests.

doesnt_work

drchen commented 3 years ago

Can you elaborate? From the screen recording it looks working fine.

mateuszkwiecinski commented 3 years ago

I wouldn't agree it works fine on the attached gif. Clearly animations aren't firing at all after switching the viewpager's tab back. They don't work in a RecyclerView at all. One can find more details here https://issuetracker.google.com/issues/189446951, where the issue seems to be confirmed 🤷‍♂️

drchen commented 3 years ago

So from https://issuetracker.google.com/issues/189446951, apparently it's not a Material library issue, and someone on the Jetpack/Framework side should handle it soon.

Close this for now. Please track https://issuetracker.google.com/issues/189446951 for updates.

mateuszkwiecinski commented 3 years ago

Ok, thanks 👍
I kinda hoped Material Library will somehow work around the issue as it affect everyone, everywhere on every api version. It's Material Library who relies on broken functionality and you could easily rewrite internal to avoid relying on View#isLaidOut flag 🤷

drchen commented 3 years ago

The issue is we actually can't....SwitchMaterial is just a stylish wrapper of SwitchCompat, which is part of Jetpack implementation (ViewCompat is part of Jetpack as well), not Material Library...

And, if it's a framework/recyclerview issue, there is probably no way for us to workaround it. (We cannot just run animation no matter the view is laid out or not.)

mateuszkwiecinski commented 3 years ago

oh, ok, thanks for explanation 👍
In that case I'd at least encourage you to escalate this issue internally. It's been 2 weeks since last message in the linked issue. It would be nice if nobody else had to spend time investigating the same inavlid behavior 😉