material-components / material-components-android

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

[AppBarLayout] Scrolling animation is broken if the first swipe on header and the second was on the content #2320

Open maxim-pandra opened 3 years ago

maxim-pandra commented 3 years ago

Description: If in the view structure with AppBarLayout, CollapsingToolbarLayout and a RecyclerView you swipe to the top on the AppBarLayout and then immediately down on the recycler (or just press and hold the recycler), the animation is broken. (as you can see in the sample repo) This can be reproduced across almost every app on GooglePlay (for example, Youtube music, Spotify and every app that uses CollapsingToolbarLayout suffers from this bug). I found this issue because I needed a big collapsing toolbar (more than half of the screen) so, the first swipe often happens on the toolbar itself.

Video is available in my sample repo. Animation is not the best way to show how bad this is =) The best way is to try it on the phone in for example Spotify artist/album screen

Expected behavior: third animation in my sample repo iow animation should stop when finger is placed on recycler, or should immediatelly scroll down after a swipe on recycler

Source code: https://github.com/maxim-pandra/CollapsingToolbarBug

Android API version: Any api. For example android 11, 10 and probably any other

Material Library version: dependency block: implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.core:core-ktx:1.6.0' implementation 'androidx.appcompat:appcompat:1.3.1' implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'

Device: Any device or emulator. For exaple samsung galaxy note 20 / or android 11 emulator

maxim-pandra commented 3 years ago

Actually I found one possible walkaround to this problem.

It is a custom behavior that redirects all scroll events from the appbar to the recycler. But it is workaround, because scroll won't stop anymore on swipe on the appbar and reference to the recycler needed https://stackoverflow.com/a/57441618/5868421