Created
October 14, 2025 09:11
-
-
Save Sottti/b4373d2941f33d20f4a82e0c15c5a02b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public fun Modifier.centerInParent(): Modifier = | |
this then layout { measurable, constraints -> | |
val maxWidthAllowedByParent = constraints.maxWidth | |
val maxHeightAllowedByTheParent = constraints.maxHeight | |
val placeable = measurable.measure(constraints) | |
val start = maxWidthAllowedByParent / 2 - placeable.width / 2 | |
val top = maxHeightAllowedByTheParent / 2 - placeable.height / 2 | |
layout(width = placeable.width, height = placeable.height) { | |
placeable.placeRelative(x = start, y = top) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment