Hey, assuming I want to show a compose dialog/bott...
# compose-android
m
Hey, assuming I want to show a compose dialog/bottomsheet but have no control over the activity this might be called from, is this "safe" or would you stick to calling them only from other composables? (Code snipped in thread)
Copy code
fun showSheet(context: Activity) {
    context.addContentView(ComposeView(context).apply {
        setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnDetachedFromWindow)
        setContent {
            var showSheet by remember { mutableStateOf(true) }
            if (showSheet) {
                ModalBottomSheet(onDismissRequest = {
                    showSheet = false
                    visibility = View.GONE
                    context.findViewById<ViewGroup>(android.R.id.content)
                        ?.removeView(this)
                }) { Text(text = "Hello", modifier = Modifier.padding(16.dp)) }
            }
        }
    }, ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT))
}
a
We call composable overlay bottom sheets within an activity too, and have no major issues adding it to the content view and removing it when dismissed