Created
November 9, 2021 01:17
-
-
Save takahirom/9d7b03cb4a74ea2289c2fd18017e2e0f 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) | |
} | |
// deside own size | |
val height = placeables.sumOf { it.height }.takeIf { it != 0 } ?: constraints.minHeight | |
val width = placeables.maxOfOrNull { it.width } ?: 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