Cash Hsiao
02/19/2021, 10:02 AMclass TestDialogFragment : DialogFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
) = ComposeView(requireContext()).apply {
setContent {
Surface {
TestDialogLayout()
}
}
}
}
It's all normal with the deploy Preview
@Preview
@Compose
fun PreviewTestDialog() {
TestDialogLayout()
}
But when I navigate from other fragment like:
TestDialogFragment().show(childFragmentManager, "Test")
or navigation way:
findNavController().navigate(MainFragmentDirections.actionToTestDialog())
Both calls gave me this crash log:
java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from DecorView@bec849f[MainActivity]
at androidx.compose.ui.platform.WindowRecomposerKt.createLifecycleAwareViewTreeRecomposer(WindowRecomposer.kt:231)
at androidx.compose.ui.platform.WindowRecomposerKt.access$createLifecycleAwareViewTreeRecomposer(WindowRecomposer.kt:1)
at androidx.compose.ui.platform.WindowRecomposerFactory$Companion$LifecycleAware$1.createRecomposer(WindowRecomposer.kt:115)
at androidx.compose.ui.platform.WindowRecomposerPolicy.createAndInstallWindowRecomposer$ui_release(WindowRecomposer.kt:168)
at androidx.compose.ui.platform.WindowRecomposerKt.getWindowRecomposer(WindowRecomposer.kt:216)
at androidx.compose.ui.platform.AbstractComposeView.ensureCompositionCreated(ComposeView.kt:184)
at androidx.compose.ui.platform.AbstractComposeView.onAttachedToWindow(ComposeView.kt:215)
at android.view.View.dispatchAttachedToWindow(View.java:19553)
I'm not sure what happened during the alpha10 to alpha12... anyone has idea?Vitor Prado
02/19/2021, 1:08 PMVitor Prado
02/19/2021, 1:09 PMVitor Prado
02/19/2021, 1:10 PMIan Lake
02/19/2021, 4:17 PMVitor Prado
02/19/2021, 4:19 PMIan Lake
02/19/2021, 5:03 PMViewTreeLifecycleOwner.set(dialog.decorView, lifecycleOwner)
Ian Lake
02/19/2021, 5:06 PMOnShowListener
Vitor Prado
02/19/2021, 7:16 PMdecorView
is my rootview?Vitor Prado
02/19/2021, 7:44 PMoverride fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
dialog?.window?.decorView?.let {
ViewTreeLifecycleOwner.set(it, viewLifecycleOwner)
}
}
Ian Lake
02/19/2021, 8:15 PMCash Hsiao
02/20/2021, 7:12 AMOnShowListener
is too late)Jeremy Woods
02/25/2021, 10:41 PM