Last active
November 10, 2021 00:28
-
-
Save takahirom/aee818f8a25c097b6b782514543c143c to your computer and use it in GitHub Desktop.
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 | |
inline fun MyVerticalBox( | |
name: String, | |
modifier: Modifier = Modifier, | |
content: @Composable () -> Unit = {} | |
) { | |
Layout( | |
content = { content() }, | |
modifier = modifier | |
) { measurables: List<Measurable>, | |
constraints: Constraints -> | |
// ① Measure children | |
val placeables = measurables.mapIndexed { index, measurable -> | |
measurable.measure(constraints) | |
} | |
// ② Decide own size | |
val height = maxOf(placeables.sumOf { it.height }, constraints.minHeight) | |
val width = maxOf(placeables.maxOfOrNull { it.width } ?: 0, constraints.minWidth) | |
val layout = layout(width, height) { | |
// ③ Place children | |
var y = 0 | |
placeables.forEach { placable: Placeable -> | |
placable.placeRelative(x = 0, y = y) | |
y += placable.height | |
} | |
} | |
layout | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment