Skip to content

Instantly share code, notes, and snippets.

@itsSiddharthGupta
Created November 17, 2024 10:51
Show Gist options
  • Save itsSiddharthGupta/865e54d95260138019df1e9346942a9a to your computer and use it in GitHub Desktop.
Save itsSiddharthGupta/865e54d95260138019df1e9346942a9a to your computer and use it in GitHub Desktop.
Circle Modifier Node
// Modifier factory
fun Modifier.circle(color: Color) = this then CircleElement(color)
// ModifierNodeElement
private data class CircleElement(val color: Color) : ModifierNodeElement<CircleNode>() {
override fun create() = CircleNode(color)
override fun update(node: CircleNode) {
node.color = color
}
}
// Modifier.Node
private class CircleNode(var color: Color) : DrawModifierNode, Modifier.Node() {
override fun ContentDrawScope.draw() {
drawCircle(color)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment