RecyclerBinder can leak OnPreDrawListener if unmount is called after view has been detached
- Dominant language
- Kotlin
- Stars
- 7.8k
- Forks
- 768
- PR merge metrics
- No merged PRs in 30d
Description
- [ ] I have searched [existing issues](https://github.com/facebook/litho/issues) and this is not a duplicate
## Version
0.39.0
## Issues and Steps to Reproduce
RecyclerBinder mount and unmount assume that the same ViewTreeObserver is associated with the RecyclerView when that may not be the case.
There is one ViewTreeObserver that is active while the view is attached to the window, and another "floating" ViewTreeObserver that is active when the view is detached from the window.
See implementation of [View#getViewTreeObserver](https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/view/View.java?q=View.java%20%22public%20ViewTreeObserver%20getViewTreeObserver%22) for reference.
Using RecyclerBinder from a Fragment:
1) Call RecyclerBinder#mount from Fragment's onCreateView lifecycle callback
2) Call RecyclerBinder#unmount from Fragment's onDestroyView lifecycle callback
## Expected Behavior
When RecyclerBinder#unmount is called, expected that when unmount calls unregisterDrawListener that the OnPreDrawListener is removed from the ViewTreeObserver.
## Actual Behavior
When RecyclerBinder#unmount is called, the OnPreDrawListener is not removed when unregisterDrawListener is called because the ViewTreeObserver returned is the one representing the "floating" detached view state.
This leaks the OnPreDrawListener.
Contributor guide
Assessment
This issue has not been assessed yet.