Skip to content

Instantly share code, notes, and snippets.

@nadewad
Created October 12, 2020 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nadewad/14f04c788aea43bd6d31d94cd8100ab5 to your computer and use it in GitHub Desktop.
Save nadewad/14f04c788aea43bd6d31d94cd8100ab5 to your computer and use it in GitHub Desktop.
Jetpack compose BlendMode.Xor demo
@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
)
}
}
@Swami-Laxmikant
Copy link

How did you know that the opacity should be .99?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment