Resolving Crashes When Using ComposeView Inside RecyclerView
1 min
Background
Recently, during a development task, I used ComposeView’s setContent function inside a ViewHolder. Everything seemed to be working fine until another team’s feature was introduced. When a BottomSheet or another Activity was opened, the app crashed.
Crash log
java.lang.IllegalStateException: ViewTreeLifecycleOwner not foundHow I Fixed It
Initially, I suspected the ViewCompositionStrategy was the issue. I changed it from the default to DisposeOnDetachedFromWindowOrReleasedFromPool, but that didn’t solve the problem.
The solution was to simply update androidx.recyclerview:recyclerview to version 1.3.1 or higher.
Reference
issuetracker.google.com
Issue Tracker - Google
Crash when dynamically adding ComposeView to RecyclerView item
Comments
Loading comments...