Skip to content

Instantly share code, notes, and snippets.

@k0siara
Created March 29, 2023 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k0siara/175cc860312414c8e5ad9855f01cf396 to your computer and use it in GitHub Desktop.
Save k0siara/175cc860312414c8e5ad9855f01cf396 to your computer and use it in GitHub Desktop.
internal class DialogFragmentComposeView(
context: Context,
private val dialogProvider: () -> Dialog,
) : AbstractComposeView(context, null, 0),
DialogWindowProvider {
// The fix is here
override val window get() = dialogProvider().window!!
private val content = mutableStateOf<(@Composable () -> Unit)?>(null)
override var shouldCreateCompositionOnAttachedToWindow: Boolean = false
private set
@Composable
override fun Content() {
content.value?.invoke()
}
override fun getAccessibilityClassName(): CharSequence = ComposeView::class.java.name
/**
* Set the Jetpack Compose UI content for this view.
* Initial composition will occur when the view becomes attached to a window or when
* [createComposition] is called, whichever comes first.
*/
fun setContent(content: @Composable () -> Unit) {
shouldCreateCompositionOnAttachedToWindow = true
this.content.value = content
if (isAttachedToWindow) createComposition()
}
}
internal var DialogFragmentComposeView.consumeWindowInsets: Boolean
get() = getTag(androidx.compose.ui.R.id.consume_window_insets_tag) as? Boolean ?: true
set(value) {
setTag(androidx.compose.ui.R.id.consume_window_insets_tag, value)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment