Albert Chang
03/04/2021, 9:57 AMgraphicsLayer()
doesn't seem to work. (Details in thread)Canvas(Modifier.fillMaxWidth().height(200.dp).graphicsLayer()) {
drawRect(
Color.Blue,
topLeft = Offset(size.width / 3, 0f),
size = Size(size.width / 3, size.height)
)
drawRect(
Color.Red,
topLeft = Offset(0f, size.height / 3),
size = Size(size.width, size.height / 3),
blendMode = BlendMode.Xor
)
}
This results in the first, while what I want is the second.Nader Jawad
03/04/2021, 8:07 PM// Configure alpha to almost 1 but not quite 1 to force graphics layer into
// offscreen composition to ensure XOR blends against transparent pixels
// otherwise the contents are drawn directly
Canvas(Modifier.fillMaxWidth().height(200.dp).graphicsLayer(alpha = 0.99f)) {
drawRect(
Color.Blue,
topLeft = Offset(size.width / 3, 0f),
size = Size(size.width / 3, size.height)
)
drawRect(
Color.Red,
topLeft = Offset(0f, size.height / 3),
size = Size(size.width, size.height / 3),
blendMode = BlendMode.Xor
)
}
useCompositingLayer = true
instead of using alpha to force this behavior