It's probably a simple one. What's the best way to...
# compose
j
It's probably a simple one. What's the best way to achieve a squircle image using coil in compose. The image should have a placeholder with the initials of the user name.
m
Just add
Modifier.clip(CircleShape)
j
It's a squircle. Not exactly a circle.
b
You can clip to any shape, here’s a good article on defining a custom shape https://juliensalvi.medium.com/custom-shape-with-jetpack-compose-1cb48a991d42
👍🏼 1
👍 2
m
Oh, so you can use
RoundedCornerShape()
or use your own one
j
Thanks guys
What about the placeholder?
b
The contents of your composable should be a slot, and that slot should be conditionally updated depending on whether you have an image or not. If there isn’t an image, replace the contents with a
Text
m
For coil placeholders, take a look at custom content: https://google.github.io/accompanist/coil/#custom-content
j
Thanks for the help guys!
c
There's no built in way to create that shape, so you'll need to create the path yourself.
j
Good idea @cb!
Thanks @popalay. It works!