Yacov Rosenberg

04/12/2022, 7:40 PM
Hey Guys. I'm having a crash when trying to inflate a custom view with AbstractComposeView. My crash is java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from{4836644 V.E...... ......I. 0,0-0,0} What I'm trying to do is to inflate this custom view in a toast this way.
fun create (lifecycleOwner: LifecycleOwner, view: View) {

    val toast = Toast(context)

    val toastCustomView = ToastCustomView(

    toast.view = toastCustomView

Any help?

Adam Powell

04/12/2022, 8:00 PM
1. Toasts are awful UI, don't use them/use something like snackbars instead. 2. Use
and similar to configure view tree dependencies when hosting compose outside of a
window. 3. Toasts are awful UI, don't use them. 🙂
👀 2

Yacov Rosenberg

04/12/2022, 8:15 PM
Thank you @Adam Powell
fun create(
    lifecycleOwner: LifecycleOwner,
    viewModelStoreOwner: ViewModelStoreOwner,
    savedStateRegistryOwner: SavedStateRegistryOwner
) {

    val toastCustomView = ToastCustomView(context)
    Toast(context).apply {
        ViewTreeLifecycleOwner.set(toastCustomView, lifecycleOwner)
        ViewTreeViewModelStoreOwner.set(toastCustomView, viewModelStoreOwner)
        ViewTreeSavedStateRegistryOwner.set(toastCustomView, savedStateRegistryOwner)
        view = toastCustomView
That way worked for me, I think I might stay with toast api because is a lot simples.
🤦‍♂️ 1
@Adam Powell Why is toast a so bad api? Have used many times and always worked fine...

Adam Powell

04/12/2022, 8:34 PM
its lifecycle is poorly defined, it obscures the UI of the windows beneath it and which parts of that UI is obscured is poorly defined/unpredicatable, it's a purely time-based notification that is bad for accessibility, the queue of them can become arbitrarily long leading to minutes of queued toasts displaying, which combines poorly with the previously described drawbacks, on old enough platform versions they display over apps other than your own which can lead to usability problems for other apps on the user's device
👀 1
there's plenty more, and most of it all traces back to the aforementioned poorly defined lifecycle
👀 1