Piotr Prus
03/17/2023, 2:57 PMPiotr Prus
03/17/2023, 2:57 PMPiotr Prus
03/17/2023, 3:08 PMephemient
03/17/2023, 3:41 PMephemient
03/17/2023, 3:42 PMModifier
.drawWithCache {
val brush = Brush.horizontalGradient(
0f to Color.Transparent,
0.35f to Color.Black,
0.65f to Color.Black,
1f to Color.Transparent,
)
onDrawWithContent {
drawContent()
drawRect(brush = brush, blendMode = BlendMode.DstIn)
}
}
Piotr Prus
03/17/2023, 3:52 PMephemient
03/17/2023, 3:52 PMPiotr Prus
03/17/2023, 3:54 PMAlbert Chang
03/17/2023, 4:06 PM.graphicsLayer(compositingStrategy = CompositingStrategy.Offscreen)
(or .graphicsLayer(alpha = 0.99f)
if you are using stable version) before .drawWithCache
.ephemient
03/17/2023, 4:13 PMephemient
03/17/2023, 4:41 PMval shader = remember {
RuntimeShader(
"""
uniform shader image;
uniform float width;
half4 main(vec2 coords) {
float alpha = saturate((0.5 - abs(coords.x / width - 0.5)) / 0.35);
half4 color = image.eval(coords);
return half4(color.rgb, color.a * alpha);
}
""".trimIndent()
)
}
var width by remember { mutableStateOf(0) }
Modifier
.onSizeChanged { width = it.width }
.graphicsLayer {
shader.setFloatUniform("width", width.toFloat())
renderEffect = RenderEffect.createRuntimeShaderEffect(shader, "image").asComposeRenderEffect()
}
but RuntimeShader is Android 13+ and it really doesn't seem worthwhile to choose to go down that pathPiotr Prus
03/17/2023, 9:10 PM.graphicsLayer(compositingStrategy = CompositingStrategy.Offscreen)
and it works!! 🎉