material-components / material-components/material-components-android
[MaterialContainerTransform] RecyclerView content is gone during transition when LinearLayoutManager.recycleChildrenOnDetach = true
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'm using `MaterialContainerTransform` in a fragment transition.
I see that `RecyclerView#onDetachedFromWindow()` gets called immediately as soon as the transition starts unlike `onDestroyView()` that waits for the transition to end. For performance improvement, I'm setting `LinearLayoutManager#recycleChildrenOnDetach` to `true`. This flag makes `LinearLayoutManager#onDetachedFromWindow()` clear the views in the RecyclerView causing the screen to turn blank when the transition starts. ([ref](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:recyclerview/recyclerview/src/main/java/androidx/recyclerview/widget/LinearLayoutManager.java;l=233?q=linearlayoutmanager))
The real issue is that `RecyclerView#onDetachedFromWindow()` doesn't wait for the transition to complete. In a regular fragment transition without `MaterialContainerTransform`, this method gets called only after the transition is completed.
**Source code:** https://github.com/mkano9/material-container-transform-recycleChildrenOnDetach/tree/master
See [FirstFragment](https://github.com/mkano9/material-container-transform-recycleChildrenOnDetach/blob/master/app/src/main/java/com/example/materialcontainertransformplayground/FirstFragment.kt#L59)
Video: https://user-images.githubusercontent.com/57272551/105796603-0c143d80-5f44-11eb-994b-a2dc8196cdd2.mp4
**Android API version:** 30
**Material Library version:** 1.3.0-rc01
**Device:** Pixel 3 XL
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 reproduction project and reading app/src/main/java/com/example/materialcontainertransformplayground/FirstFragment.kt around the reported transition. Trace the MaterialContainerTransform fragment transition alongside RecyclerView#onDetachedFromWindow() and LinearLayoutManager#recycleChildrenOnDetach; done means the RecyclerView content remains visible throughout the transition with that flag enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100