material-components / material-components/material-components-android
[CollapsingToolbarLayout] CollapsingToolbarLayout scroll issue with ViewPager
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
**Description:**
CollapsingToolbarLayout stops reacting to scroll when ViewPager2 with FragmentStateAdapter changes page (occurs with either ViewPager or ViewPager2). Happens if ViewPager's Fragment content has either NestedScrollView or RecyclerView inside.
Steps to reproduce:
1. Run the app.
2. Toolbar collapses correctly while dragging AppBar or ViewPager content up and down.
3. Swipe ViewPager right to get to the next page (do **not** scroll the ViewPager content!).
4. Dragging AppBar to collapse/expand Toolbar is not working anymore.
5. Scrolling by dragging ViewPager2 fragment enables Toolbar collapse/enlargement by dragging AppBar again.

In the case of ViewPager the error **does not** occur when swiped out page is still within the ViewPager2.offscreenPageLimit (eg. when offscreenPageLimit = 1, swiping from page 0 -> 1 does not break the scroll, but from 1 -> 2 does). Essentialy, for view pager it happens when fragment that had been scrolled gets out of ViewPager.offscreenPageLimit range.
**Expected behavior:**
Toolbar should respond to scrolls and collapse/enlarge in the same way before and after a ViewPager page change.
**Source code:**
GitHub repo to reproduce the issue. Created by adding ViewPager to AndroidStudio's new "ScrollingActivity" project:
https://github.com/WojciechLatala/CoordinatorViewPager
Source code for the layout:
```
```
**Android API version:** min: 22, target/compile: 29
**Material Library version:** 1.2.1, error still occurs on 1.3.0-alpha03
**Device:** Sony Xperia Android 9.0 (and many others).
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 running the linked CoordinatorViewPager reproduction with the provided CoordinatorLayout containing CollapsingToolbarLayout, AppBarLayout, and ViewPager2. Reproduce the failure after changing pages without scrolling the fragment, then compare the toolbar behavior before and after the change. Done means AppBar dragging and fragment scrolling collapse and expand the toolbar consistently across page changes.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100