Is there a way to host a fragment inside of a comp...
# compose
l
Is there a way to host a fragment inside of a composable? I know we can host composables inside of a fragment but what about the opposite?
i
You should only use
AndroidViewBinding
to inflate a layout with a
FragmentContainerView
- that's the only setup that will automatically add and importantly remove the Fragment when you remove that
AndroidViewBinding
from your Composable hierarchy
👍 4
v
Hello @Ian Lake! Are there any additional steps required, aside from following this guidance, when removing the Fragment from the Composable hierarchy? I’m encountering a memory leak issue with a Fragment after its removal, and I want to confirm if there are any known bugs or actions required on our part that you are aware of. Thanks! 🙏
i
AndroidViewBinding
automatically removes the Fragment from the FragmentManager when the
AndroidView
reaches its
onRelease
so nothing in the framework should be holding onto that Fragment beyond the disposal of the `AndroidViewBinding`: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]a/androidx/compose/ui/viewinterop/AndroidViewBinding.kt;l=198
💪 1
v
Knowing this, I will continue investigating. Thanks for the info!