zsperske
12/02/2022, 9:43 PMAbstractComposeView inside of a BottomSheetDialog (from the material design library). Wondering if anyone else has run into this before & found a solution. Error starts with:
java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from android.widget.FrameLayoutzsperske
12/02/2022, 9:43 PMjava.lang.IllegalStateException: ViewTreeLifecycleOwner not found from android.widget.FrameLayout{7ec5e5f V.E...... ......I. 0,0-0,0 #7f08006f app:id/container}
at androidx.compose.ui.platform.WindowRecomposer_androidKt.createLifecycleAwareWindowRecomposer(WindowRecomposer.android.kt:349)
at androidx.compose.ui.platform.WindowRecomposer_androidKt.createLifecycleAwareWindowRecomposer$default(WindowRecomposer.android.kt:324)
at androidx.compose.ui.platform.WindowRecomposerFactory$Companion$LifecycleAware$1.createRecomposer(WindowRecomposer.android.kt:168)
at androidx.compose.ui.platform.WindowRecomposerPolicy.createAndInstallWindowRecomposer$ui_release(WindowRecomposer.android.kt:224)
at androidx.compose.ui.platform.WindowRecomposer_androidKt.getWindowRecomposer(WindowRecomposer.android.kt:299)
at androidx.compose.ui.platform.AbstractComposeView.resolveParentCompositionContext(ComposeView.android.kt:240)
at androidx.compose.ui.platform.AbstractComposeView.ensureCompositionCreated(ComposeView.android.kt:247)
at androidx.compose.ui.platform.AbstractComposeView.onAttachedToWindow(ComposeView.android.kt:279)
at android.view.View.dispatchAttachedToWindow(View.java:20479)Ian Lake
12/02/2022, 10:41 PMBottomSheetDialog (when really you'd run into less problems if you use BottomSheetDialogFragment): https://kotlinlang.slack.com/archives/CJLTWPH7S/p1597245390048100Ian Lake
12/02/2022, 10:41 PMBottomSheetDialog, you see the same thing in every non-managed Dialog that doesn't know anything about Composezsperske
12/02/2022, 10:57 PMIan Lake
12/02/2022, 10:58 PMSavedStateRegistryOwner (and optionally a ViewModelStoreOwner if you want to use ViewModels within the dialog)Ian Lake
12/02/2022, 10:59 PMzsperske
12/02/2022, 11:00 PMzsperske
12/02/2022, 11:01 PMIan Lake
12/02/2022, 11:10 PMAppCompatDialog (the superclass of BottomSheetDialog ) will extend ComponentDialog, which will give you the LifecycleOwner part for freeIan Lake
12/03/2022, 12:59 AMComponentDialog can also implement SavedStateRegistryOwnerzsperske
12/03/2022, 1:06 AMzsperske
12/03/2022, 9:40 PMComponentDialog never gets its setContentView methods called (which is what initializes the LifecycleOwner). The subclass AppCompatDialog doesn’t call super.setContentView and instead calls a delegate method which doesn’t end up leading to the ComponentDialogIan Lake
12/03/2022, 10:15 PMIan Lake
12/03/2022, 10:17 PMsetViewLifecycleOwner with this (i.e., with the ComponentDialog instance that implements LifecycleOwner). That's a lot easier than building a valid owner yourselfzsperske
12/03/2022, 10:27 PMSavedStateRegistryOwner APIs in the newest savedstate artifact (1.2) vs the one appcompat activity uses (1.1.0-beta01)zsperske
12/04/2022, 7:03 PM