Hey Guys. I'm having a crash when trying to inflate a custom view with AbstractComposeView. My cras...
y
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 com.hiatus.android.ui.toast.ToastCustomView{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.
Copy code
fun create (lifecycleOwner: LifecycleOwner, view: View) {

    val toast = Toast(context)

    val toastCustomView = ToastCustomView(
        context
    )

    toast.view = toastCustomView
    toast.show()
}

Any help?
a
1. Toasts are awful UI, don't use them/use something like snackbars instead. 2. Use
ViewTreeLifecycleOwner.set
and similar to configure view tree dependencies when hosting compose outside of a
ComponentActivity
or
DialogFragment
window. 3. Toasts are awful UI, don't use them. 🙂
👀 2
y
Thank you @Adam Powell
Copy code
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
        show()
    }
}
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...
a
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