https://kotlinlang.org logo
Title
f

frankelot

06/13/2021, 3:08 PM
👋 qq: Is there a way to display a repeating background in compose? Something similar to “tileMode=repeat”
1
r

Rafs

06/13/2021, 4:08 PM
If it's an image, you can draw it on the composable's background in anyway you want using
Modifier.drawBehind
f

frankelot

06/13/2021, 4:17 PM
Thanks, didn’t know about
drawBehind
I’m still not sure how to set the
canvas
to repeat the image 🤔
Okay, your solution kinda worked for me in the end 🙂 (since I only wanted a dotted background)…
for (x in 0..this.size.width.roundToInt() step 80) {
                for (y in 0..this.size.height.roundToInt() step 80) {
                    drawCircle(
                        color = Color.Black,
                        center = Offset(x.toFloat(), y.toFloat()),
                        radius = 8f,
                        alpha = .1f
                    )
                }
            }
r

Rafs

06/13/2021, 5:02 PM
A quick example of a horizontal repeat
💯 1
f

frankelot

06/13/2021, 5:03 PM
nice, yes, this works, not sure how expensive it is (in terms of performance) but is good enough for me right now
n

Nader Jawad

06/15/2021, 6:47 AM
The tile mode APIs are available as part of the ImageShader API. You can create a brush from that and draw a rectangle with the desired pattern