Created
October 12, 2020 19:49
-
-
Save nadewad/14f04c788aea43bd6d31d94cd8100ab5 to your computer and use it in GitHub Desktop.
Jetpack compose BlendMode.Xor demo
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 | |
fun foo() { | |
Canvas(Modifier | |
.fillMaxSize() | |
.wrapContentSize(Alignment.Center) | |
.preferredSize(120.dp, 120.dp) | |
// Provide a slight opacity to for compositing into an | |
// offscreen buffer to ensure blend modes are applied to empty pixel information | |
// By default any alpha != 1.0f will use a compositing layer by default | |
.drawLayer(alpha = 0.99f) | |
) { | |
val radius = size.minDimension / 4 | |
drawCircle( | |
Color.Red, | |
center = Offset(center.x - radius / 2, center.y), | |
radius = radius, | |
blendMode = BlendMode.Xor | |
) | |
drawCircle( | |
Color.Red, | |
center = Offset(center.x + radius / 2, center.y), | |
radius = radius, | |
blendMode = BlendMode.Xor | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How did you know that the opacity should be .99?