Skip to content

Instantly share code, notes, and snippets.

@KatieBarnett
Created December 21, 2023 22:54
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/aedd257683475902148daf7340cd66f8 to your computer and use it in GitHub Desktop.
Save KatieBarnett/aedd257683475902148daf7340cd66f8 to your computer and use it in GitHub Desktop.
Edge to Edge reusable code
@Composable
fun getActivityWindow(): Window? = LocalView.current.context.getActivityWindow()
private tailrec fun Context.getActivityWindow(): Window? =
when (this) {
is Activity -> window
is ContextWrapper -> baseContext.getActivityWindow()
else -> null
}
@Composable
fun SetDialogDestinationToEdgeToEdge() {
val activityWindow = getActivityWindow()
val dialogWindow = (LocalView.current.parent as? DialogWindowProvider)?.window
val parentView = LocalView.current.parent as View
SideEffect {
if (activityWindow != null && dialogWindow != null) {
val attributes = WindowManager.LayoutParams()
attributes.copyFrom(activityWindow.attributes)
attributes.type = dialogWindow.attributes.type
dialogWindow.attributes = attributes
parentView.layoutParams = FrameLayout.LayoutParams(
activityWindow.decorView.width,
activityWindow.decorView.height
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment