I'm drawing a shadow around my bottom bar using th...
# compose
s
I'm drawing a shadow around my bottom bar using the shadow modifier but it looks sharp. How can I draw a smoother shadow? I've tried playing around with the elevation but got nothing
1
I need something like this:
d
That shadow kind of defies Android's built-in light laws.
Interesting but nonsensical or natural.
I think it's purpose is to make the bar stand out against it's background but that would not be needed if the bar was a different color then it's background in the first place.
The shadows in the bar in the picture seem to defy the laws of physics.
c
@Se7eN code snippet please?
s
Copy code
BottomAppBar(
    modifier = Modifier.shadow(elevation = 1.dp),
    backgroundColor = Color.Transparent,
    cutoutShape = CircleShape,
    elevation = 0.dp,
    ...
) {
   Row { ... }
}
I'm not on PC right now but the code is some like this
@dewildte Good to know that. I'm creating a transparent bar and that's why I need a shadow
d
If the bar is transparent it would not leave a shadow.
1
s
So what else can I do?
c
So you really only want a shadow for the FAB? I think if your bottom app bar background is transparent, you might be better off having the FAB as a separate Composable where you can directly control the elevation on it.
s
No, I want the shadow for the whole bottom bar including the cutout, just like in the second image. For the cutout, I'm waiting for that
BottomAppBarCutoutShape
to be exposed because it's private right now.
Also, I have my FAB in the
Scaffold
c
Gotcha. Though as Eric mentioned, if the background color of the bar is transparent and you set elevation on it, you’ll just see the shadow modifier drawn, which is probably what you don’t want?
s
Yeah if I set an elevation, the whole bar is covered with the shadow.
d
Covered implies the shadow is on top. shadows are underneath, but the bar is transparent so you see the shadow.
s
Oh got it
c
Yeah it seems just with
elevation
that you can’t make the shadow as bold as your earlier screenshot without having access to or reimplementing
BottomAppBarCutoutShape
In general, it seems there is limited control over the shadow in terms of blur, spread, and color. I’m not sure if it’s being considered to enable more customization for the Modifier or in general, but maybe @Adam Powell or @romainguy have thoughts.
r
Blur and spread are not controllable, at least directly. You can, in recent versions of Android, control the surface of the light that projects those shadows
This has the side effect of modifying the “blur” of the shadow
Note that there’s no blur involved in our shadowing system, it is the result of properly computing the umbra and penumbra created by an area light project through an occluder
c
Sorta like this diagram?
r
Yep, except with quads instead of spheres
👍 1
Very first prototype (which was fully raytraced :))
🤩 4
m
@romainguy any idea how to add blur and spread to the shadow modifier ?
429 Views