Created
March 29, 2023 14:22
-
-
Save k0siara/175cc860312414c8e5ad9855f01cf396 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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