material-components / material-components/material-components-android
[AppBarLayout] "scroll" layout flag problematic on Android 17 QPR1 and QPR2 (autoscrolls when it should not)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
Observed on v1.14.0 on a Google Pixel Pro running QPR2 Beta 4. Also happens in the emulator running Android 17 API 37.1 and 37.2
See [this issue](https://issuetracker.google.com/issues/534911685#comment7) report on the Android beta tracker (post 7) for more details and a video showing the issue in my app.
The problem is that a `MaterialToolBar` child of an `AppBarLayout` with `app:layout_scrollFlags="scroll"` (possibly combined with other flags but only `scroll` is important), always auto-scrolls when a `BottomNavigationView ` (see video) that uses fragments within a `ViewPager2` for its tabs, switches tabs (`ViewPager#setCurrentItem`).
It results in unwanted scrolling of the `MaterialToolBar` when switching tabs This issue does not happen on regular Android 17 and below. It started to happen in an early Android 17 QPR beta version a few months ago.
It is hugely annoying and the only work-around I found for now is to disable "scroll" on the `MaterialToolBar` if the app is running on Android 17 QPR:
```
if(Misc.isAndroid17_1_OrLater()) {
((AppBarLayout.LayoutParams) _toolbar.getLayoutParams()).setScrollFlags(0);
}
```
Normally, the `MaterialToolBar` scrolls up (hides) when use scrolls the content, but this workaround disable it.
Mind you, the YouTube app is also affected (the issue report linked above was initially for the YT app).
Would be awesome if it could be looked into.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with a MaterialToolBar child of AppBarLayout using app:layout_scrollFlags="scroll", BottomNavigationView, fragments in ViewPager2, and setCurrentItem on Android 17 QPR1/QPR2 or API 37.1/37.2. Compare tab switching with regular Android 17 and below, and verify that switching tabs no longer auto-scrolls the toolbar while normal content scrolling still hides it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100