I tried `ViewGroup.setContent` extension inside a ...
# compose
j
I tried
ViewGroup.setContent
extension inside a
BottomSheetDialog
and it threw this exception
Copy code
java.lang.IllegalStateException: Composed into the View which doesn't propagate ViewTreeLifecycleOwner!
Is this a known issue?
i
Are you using
BottomSheetDialogFragment
and overriding
onCreateView()
to create your View? Fragment, and by extension any
DialogFragment
, will have its LifecycleOwner set
But for a regular
Dialog
, that view hierarchy is in its own window and is totally uncoupled from the Activity's.
j
I'm doing this with
BottomSheetDialog
Copy code
private val dialog = BottomSheetDialog(context)
val layout = LayoutInflater.from(context).inflate(R.layout.filter_bottom_sheet_dialog_view, null)
dialog.setContentView(layout)
layout.findViewById<CardView>(R.id.v_card).setContent(Recomposer.current()) {
    FiltersScreen(filterState = filterState)
}
i
Well, besides making that forcing you to manually clean up your Dialog when the Activity does away (otherwise you'll leak your window token - this I'd something fragments does for you), then yeah, you'll need to hook up the ViewTreeLifecycleOwner yourself
That's what it's
set
method is for. You'll also want to hook up the other ViewTree APIs
j
Thanks, will look into
set
methods.
BottomSheetDialogFragment
looks an obvious better choice then(funny didn't think of this earlier 😅)
l
You'll also want to hook up the other ViewTree APIs
What did you mean?
v
There's some inspiration here as well. Different issue but needed some of the same setup - https://www.jetpackcompose.app/snippets/AbstractComposeviewPreviewHelper