Skip to content

Instantly share code, notes, and snippets.

@KatieBarnett
Last active May 10, 2024 11:16
Show Gist options
  • Select an option

  • Save KatieBarnett/aedd257683475902148daf7340cd66f8 to your computer and use it in GitHub Desktop.

Select an option

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
)
}
}
}
dialog(
"detail/{index}",
dialogProperties = DialogProperties(
usePlatformDefaultWidth = true,
decorFitsSystemWindows = false
)
) { backStackEntry ->
SetDialogDestinationToEdgeToEdge()
backStackEntry.arguments?.getInt("index")?.let {
FactDetail(items[it], Modifier.fillMaxSize())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment