Skip to content

Instantly share code, notes, and snippets.

@KatieBarnett
Created December 20, 2023 04:50
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 KatieBarnett/d5130861d1cf63f21fc6fc46e566e5b4 to your computer and use it in GitHub Desktop.
Save KatieBarnett/d5130861d1cf63f21fc6fc46e566e5b4 to your computer and use it in GitHub Desktop.
Dialog edge to edge
showDialog?.let {
Dialog(
onDismissRequest = { showDialog = null },
properties = DialogProperties(
usePlatformDefaultWidth = true,
decorFitsSystemWindows = false
)
) {
// Step 1: Find the windows
val activityWindow = window
val dialogWindow = (LocalView.current.parent as? DialogWindowProvider)?.window
val parentView = LocalView.current.parent as View
SideEffect {
if (activityWindow != null && dialogWindow != null) {
// Step 2: Get and apply the activity attributes to the dialog parent view
val attributes = WindowManager.LayoutParams()
attributes.copyFrom(activityWindow.attributes)
attributes.type = dialogWindow.attributes.type
dialogWindow.attributes = attributes
parentView.layoutParams = LayoutParams(
activityWindow.decorView.width,
activityWindow.decorView.height
)
}
}
FactDetail(items[it], Modifier.fillMaxSize())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment