[Shape] Fix corner animation interruption during state changes while maintaining performance#4995
Conversation
Fix regression introduced in ea9d250 where corner morph animations in MaterialButtonGroup were interrupted. The issue was that onBoundsChange() always skipped animations by passing `skipAnimation=true` to updateShape(). This affected state-only changes (like button press) where bounds don't actually change. Restored the boundsIsEmpty logic from 1.14.0-alpha06: - Skip animation only on first non-empty bounds (initial layout) - Allow animations for subsequent state changes (smooth UX) Fixes material-components#4990
|
Hi @dsn5ft, I'm checking in on this PR. I've already verified the fix through local testing and confirmed it restores the corner animation behavior as expected. Since there hasn't been any feedback from @pekingme regarding a 'better way' for a while, I suggest moving forward with this approach to address the regression in the current alpha version. Could you please review this or let me know if we should wait further? |
|
The solution being a flag in MaterialShapeDrawable that helps differentiate corner animations triggered by state change vs bound change. |
…maintaining performance. After ea9d250, corner morph animations in MaterialButtonGroup were interrupted during state changes because onBoundsChange() always skipped animations. This caused abrupt visual transitions when buttons were pressed or focused. Simply reverting would reintroduce unnecessary animations during layout changes (screen rotation, window resize), hurting performance. Solution: Use time-based approach to distinguish change types: - Track timestamp when state changes occur (onStateChange) - Allow animation for 500ms after state change - Skip animation for pure layout changes (outside time window) This maintains both smooth state transition UX and layout change performance. Fixes material-components#4990
|
Updated the implementation based on feedback! Instead of simply reverting to I've also updated the PR description to reflect this new approach. Please take a look at the updated implementation. Thanks! |
|
thanks for updating the PR! but hmm checking elapsed time against a hardcoded value like 500 ms feels a little hacky. I believe we were thinking of introducing a more specific / deterministic based solution. @pekingme thoughts? |
Summary
Fix corner morph animation interruption in MaterialButtonGroup while maintaining the performance optimization from ea9d250.
Problem
After ea9d250, corner animations are interrupted during state changes because
onBoundsChange()always skips animations.Solution
Instead of simply reverting ea9d250, this PR uses a time-based approach:
This achieves both smooth state transition animations AND fast layout performance, as suggested by reviewers.
Implementation
stateChangeTimestampto track state change timingonBoundsChange()to check time windowTest
Fixes #4990