Stylianos Gakis
03/06/2023, 11:48 AMAppTheme {
Surface(color = MaterialTheme.colors.background) {
// stuff
}
}
to get the right theme + composition locals in place for the rest of the screen. The one thing that looks a tiny but suspicious is that I have to call surface and change the color to be background instead. Then use normal Surface with the default MaterialTheme.colors.surface for cards and other surfaces, so that there’s this difference between background and surface colors.
Does this look odd, is there some better composable I should be using for this situation?Nick Rout
03/06/2023, 11:59 AMScaffold
or BottomSheetScaffold
the default backgroundColor
is MaterialTheme.colors.background
.
Alternatively I guess you could do something like this:
@Composable
fun Background(
modifier: Modifier = Modifier,
content: @Composable () -> Unit
) {
Surface(
modifier = modifier,
color = MaterialTheme.colors.background,
content = content
)
}
Stylianos Gakis
03/06/2023, 12:03 PMNick Rout
03/06/2023, 12:03 PMZoltan Demant
03/06/2023, 2:17 PMsetDecorFitsSystemWindows(false)
, it basically does all the heavy lifting for you; I find it really really nice and havent needed to even think about statusbar/navigationbar paddings. YMMV 🙂Albert Chang
03/06/2023, 3:46 PMAlbert Chang
03/06/2023, 3:49 PMScaffold
whenever possible because it uses subcompose layout under the hood and is less performant.Stylianos Gakis
03/06/2023, 3:56 PMThe M3 scaffold also helps a great deal if youre usingTrue that! Although in most cases I am only adding a TopAppBar, so the rest of the insets is easy to figure out. With that said, with the scaffold case, you get those insets passed in as PaddingValues in the content lambda, that means that if you apply them to the entire content composable, your content won’t actually render behind the navigation bar for example right? More often than not, I do want to render behind, so I don’t want that, and instead have in my column asetDecorFitsSystemWindows(false)
Spacer(Modifier.windowInsetsPadding(WindowInsets.safeDrawing.only(WindowInsetsSides.Bottom)))
at the end, meaning that if I scroll up the content does draw under the system bars.
If I have a LazyColumn or some composable which accepts a contentPadding
you can pass it in there, but if you got a normal Column for example it wouldn’t work, so still, doing it myself has proven to be easier tbh.Stylianos Gakis
03/06/2023, 3:57 PMUsually you just do this once in the root composable. Why do you need to add it to every screen?I am in this app which is activity-based for all screens 🥲, so each of the activities (I referred to them as screens) is like starting from scratch, I can’t rely on the top level root composable, hence why I in particular need to do this often.
Albert Chang
03/07/2023, 2:58 AM@Composable fun MainScreen()
), I would say it's better to put it in your activities instead. If you are already putting it in the activities, I don't think it's odd at all.Zoltan Demant
03/07/2023, 6:24 AMZoltan Demant
03/07/2023, 6:26 AM