Skip to content

Instantly share code, notes, and snippets.

@nimaiwalsh
Last active August 29, 2023 04:45
Show Gist options
  • Save nimaiwalsh/4187d909d69bf32a4a3d9f366f318827 to your computer and use it in GitHub Desktop.
Save nimaiwalsh/4187d909d69bf32a4a3d9f366f318827 to your computer and use it in GitHub Desktop.
Composable helper extensions
/**
* Modifies a layout to ignore irs parents horizontal padding. This is useful if you have an item in a column, such as
* a divider, that does not want to be constrained by the parents padding
*/
fun Modifier.ignoreHorizontalParentPadding(horizontal: Dp): Modifier {
return this.layout { measurable, constraints ->
val overriddenWidth = constraints.maxWidth + 2 * horizontal.roundToPx()
val placeable = measurable.measure(constraints.copy(maxWidth = overriddenWidth))
layout(placeable.width, placeable.height) {
placeable.place(0, 0)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment