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

Florian

08/07/2021, 6:02 PM
I'm not really getting the point of this default surface in a new Compose Activity. What's it's purpose? And why does it set the background color?
s

Se7eN

08/07/2021, 6:09 PM
Well I guess this is just an example
You don't have to include it if your root composable is a
Scaffold
or some other composable that includes
Surface
f

Florian

08/07/2021, 6:12 PM
Oh interesting, I didn't know Scaffold includes Surface
s

Se7eN

08/07/2021, 6:15 PM
Yep many other material components include Surface
f

Florian

08/07/2021, 6:44 PM
thank you
yea I've tried to read that but it didn't say much to me
I also didn't notice a difference removing it, probably because all my screens use Scaffold
s

Se7eN

08/07/2021, 6:50 PM
Yeah if you remove it in the Greetings example and run the app in dark mode, you can see your
Text
won't pick up the white color automatically so it will show black text on a black background
f

Florian

08/07/2021, 7:20 PM
ah this makes sense, thank you very much!
👍 1
c

Colton Idle

08/09/2021, 12:49 AM
@Florian I also asked something similar to this a while back. And one thing I learned (from Nick Butcher I think) is that a surface also clips it's children which compose doesn't clip children by default, so you could run into some issues in that.
f

Florian

08/09/2021, 9:12 AM
@Colton Idle what do you mean by "clip"?
c

Colton Idle

08/09/2021, 2:09 PM
In xml land the equivallent is
android:clipChildren
which is set to true by default. In compose, clipping is set to false by default.
f

Florian

08/09/2021, 3:28 PM
interesting, thank you
3 Views