Skip to content

Instantly share code, notes, and snippets.

@waquwex
Created April 26, 2024 23:15
Show Gist options
  • Select an option

  • Save waquwex/ab2bb457a309332ecfea794d5ccfb697 to your computer and use it in GitHub Desktop.

Select an option

Save waquwex/ab2bb457a309332ecfea794d5ccfb697 to your computer and use it in GitHub Desktop.
Jetpack Compose Canvas and LayoutModifier
@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