https://kotlinlang.org logo
#compose
Title
# compose
t

Travis Griggs

10/23/2023, 8:36 PM
I've got this little DurationDial that I'm implementing with some Canvas.DrawScopes. I want the dark cyan circle thumb to pop off, by having a shadow under it. Is there any way to simulate shadows easily in a DrawScope? (I can draw series of successive alpha dark circles below it if I want to get really old fashion primitive), I could also move the thumb into its own composable like a Surface with a CircleShape and a shadow, but then all the drawing code that has already done various center/radius/angle math gets repeated. The second screenshot (purple thumb) is the iOS version with the shadow effect I want to recreate.
r

romainguy

10/23/2023, 8:49 PM
In this case you can easily fake it by drawing a second circle with a radial (circular) gradient
t

Travis Griggs

10/23/2023, 8:53 PM
True. What about when I want to do a line or a rectangle? I wish this were a withShadow(values) { } sub draw scope, kind of like withTransform
r

romainguy

10/23/2023, 8:54 PM
You can use a native Canvas on Android and set a shadow layer on the paint
that will work on Android P and above
a

ascii

10/23/2023, 8:54 PM
Copy code
Paint().apply { color = Color.Black }.asFrameworkPaint().setShadowLayer()
And then draw whatever you want with this paint
r

romainguy

10/23/2023, 8:54 PM
Yep, that
t

Travis Griggs

10/23/2023, 8:58 PM
i'll give that a try, thanks. i need to use the native draw methods inside the native scope in that case (rather than drawCircle, etc), correct?
r

romainguy

10/23/2023, 8:58 PM
Yeah but they are basically the same
like drawCircle() for circles 😄
t

Travis Griggs

10/23/2023, 11:02 PM
This worked like a charm, thanks!
e

efemoney

10/24/2023, 9:16 AM
Damn, why does the ios font (make the entire thing) look better 🧌 (🙈)
t

Travis Griggs

10/24/2023, 3:14 PM
maybe in part, because I have the font size on the android one cranked up bigger. that said, for me, it has something to do with weight. SF seems to have a marginally thicker nominal stroke weight that gives the font more solidity. i have experimented with weight on roboto to try and get it to match, because at a glance they are similiar. but the SF normal weight seems to be somewhere between that of Roboto's normal and medium
👍🏾 1
r

romainguy

10/24/2023, 3:15 PM
You can rely on variable fonts to fine tune your weight btw
1