material-components / material-components/material-components-android
[CollapsingToolbarLayout] Scroll state not preserved when recreating view and `exitUntilCollapsed` scroll flag is set
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
**Description:**
I spotted multiple mentions of the same issue, i.e. here: https://github.com/material-components/material-components-android/issues/1019#issuecomment-773056165, so I assume this is not _new_, but since I couldn't find a proper bug report I'm creating a new one.
The issue is: `CollapsingToolbarLayout` with `app:layout_scrollFlags="scroll|exitUntilCollapsed"` doesn't preserve its scroll state when the view is destroyed and then recreated (i.e. when navigating back between fragments)
**Expected behavior:** Screenshots and/or description of expected behavior
The `CollapsingToolbarLayout` scroll state is exactly the same as it was before leaving the screen.
_Expected_
https://github.com/material-components/material-components-android/assets/36954793/fe1c52fa-f8a2-4d54-9571-3d63c0ebdf4d
_Actual_
https://github.com/material-components/material-components-android/assets/36954793/74967735-1bf9-454c-a7a9-45123921b85a
(the "should be hidden" label should not be visible. It is because `CollapsingToolbar` restores in an "expanded" state)
**Source code:**
My current repro is:
```xml
```
but the crucial part is the `exitUntilCollapsed`.
❗ **Interesting** thing is setting `minHeight` to `tipText` TextView seems to restore proper behavior. This is very confusing 😅
**Minimal sample app repro:**
Full project: https://github.com/mateuszkwiecinski/collapsing_toolbar_doesnt_work
1. `./gradlew installDebug`
2. Launch app
3. Scroll up, so the "Should be hidden" label disappears
4. Tap the "Navigate forward and back to recreate view" which commits another fragment and immediately pops it back
5. 🐛 should be visible now
**Android API version:**
28, 31, 33
**Material Library version:**
`1.11.0-alpha01`, `1.9.0`
**Device:**
Android emulator
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 with the linked minimal sample app and reproduce the issue using `./gradlew installDebug`, then inspect `CollapsingToolbarLayout` and `AppBarLayout` state restoration around fragment recreation. Done means the collapsed scroll state remains unchanged after navigating forward and back with `scroll|exitUntilCollapsed`, including on the reported API levels.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100