Eric Martori
04/27/2022, 11:27 AMComposeView
in the XML works for most cases, but now we have to show a pop window and an alert on user interaction.
We have tried creating the PopupWindow
and AlertDialog
programmatically and setting the content view as a ComposeView
with the desired content but we get errors like: java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from android.widget.PopupWindow$PopupDecorView
So we are thinking that maybe there is a way to launch the alert and popup directly from compose, but don't know how to launch it from inside a custom view without replacing the already working content.myanmarking
04/27/2022, 1:22 PMEric Martori
04/27/2022, 1:23 PMmyanmarking
04/27/2022, 1:25 PMEric Martori
04/27/2022, 1:30 PMcontentView
of the PopupWindow to a ComposeView
but this fails due to the lifecycle error of my original message.
I was wondering if maybe there is a way to add a dummy ComposeView to the ConstraintLayout and launch the tooltip from theremyanmarking
04/27/2022, 1:32 PMsetViewCompositionStrategy
in your compose dialog view?Eric Martori
04/27/2022, 1:33 PMmyanmarking
04/27/2022, 1:36 PMEric Martori
04/27/2022, 1:37 PMmyanmarking
04/27/2022, 1:37 PMEric Martori
04/27/2022, 1:40 PMmyanmarking
04/27/2022, 1:44 PMEric Martori
04/27/2022, 1:46 PMViewTreeLifecycleOwner.set()
and setting it manually, but the view that crashes es private and I am no sure how to do itmyanmarking
04/27/2022, 1:53 PMEric Martori
04/27/2022, 2:00 PMAndy Himberger
05/05/2022, 6:53 AM// use the right lifecycle owner, activity shown here
fun Dialog.enableComposeViewSupport(activity: AppCompatActivity) {
val decorView = getWindow()?.getDecorView()
if (decorView != null) {
ViewTreeLifecycleOwner.set(decorView, activity)
ViewTreeViewModelStoreOwner.set(decorView, activity)
ViewTreeSavedStateRegistryOwner.set(decorView, activity)
}
}
another option is to create your alertdialog via a dialogfragment, in that case you won't need this workaround.Eric Martori
05/10/2022, 10:42 AM