Created
April 26, 2024 23:15
-
-
Save waquwex/ab2bb457a309332ecfea794d5ccfb697 to your computer and use it in GitHub Desktop.
Jetpack Compose Canvas and LayoutModifier
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
| @Composable | |
| fun MyCustomShape(color: Color) { | |
| Canvas(modifier = Modifier | |
| .size(100.dp) | |
| .background(Color.Black) | |
| ) { | |
| drawCircle(color = color, radius = 50.0f, center = center) | |
| } | |
| } | |
| @Composable | |
| fun MyCustomBox() { | |
| Box(modifier = Modifier.layout { | |
| measurable, constraints -> | |
| val placeable = measurable.measure(constraints.copy(minWidth = 0, minHeight = 0)) | |
| layout(placeable.width, placeable.height,) { | |
| placeable.place(x = 0.dp.roundToPx(), y = 50.dp.roundToPx(),) // Position it relative to parent(top left) | |
| } | |
| }){ | |
| Text(text = "LAYOUT MODIFIER", fontWeight = FontWeight.ExtraBold) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment