-
-
Save KatieBarnett/aedd257683475902148daf7340cd66f8 to your computer and use it in GitHub Desktop.
Edge to Edge reusable code
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
@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