Created
March 16, 2021 19:03
-
-
Save pauloaapereira/df1a72aba4632adf376e6932544bd5cb to your computer and use it in GitHub Desktop.
Jetpack Compose — Drawer Pushing Content - 1
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 MyBasicColumn( | |
modifier: Modifier = Modifier, | |
content: @Composable() () -> Unit | |
) { | |
Layout( | |
modifier = modifier, | |
content = content | |
) { measurables, constraints -> | |
// List of measured children | |
val placeables = measurables.map { measurable -> | |
// Measure each children | |
measurable.measure(constraints.copy(minHeight = 0)) | |
} | |
// Set the size of the layout as big as it can | |
layout(constraints.maxWidth, constraints.maxHeight) { | |
// Track the y co-ord we have placed children up to | |
var yPosition = 0 | |
// Place children in the parent layout | |
placeables.forEach { placeable -> | |
// Position item on the screen | |
placeable.place(x = 0, y = yPosition) | |
// Record the y co-ord placed up to | |
yPosition += placeable.height | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment