I have put MainScreen inside S1FoundationTheme, bu...
# compose
m
I have put MainScreen inside S1FoundationTheme, but the layout editor shows MaterialTheme in the same level as MainScreen. What does this mean? Certainly, MaterialTheme is not a child of S1FoundationTheme, rather maybe the reverse.
a
You are calling
MaterialTheme
in
S1FoundationTheme
right? In that case
MaterialTheme
is the child of
S1FoundationTheme
.
m
I use some MaterialTheme attributes for text yeah, but still I cannot understand how it is the child of S1FoundationTheme.
c
What does your
S1FoundationTheme
code look like? I’m guessing it’s wrapping
MaterialTheme
which is why it shows up like this in the Layout Inspector hierarchy
m
The S1FoundationTheme code is the default theme generated by Android Studio. I use it like this:
Copy code
setContent {
    S1FoundationTheme {
        MainScreen()
    }
}
c
I see. If you go to the implementation of S1FoundationTheme you’ll see it’s using MaterialTheme
should be in
ui/theme/Theme.kt
since it’s generated from Android Studio
m
Yes, it's interesting. MaterialTheme is used inside my app theme.
Copy code
@Composable
fun S1FoundationTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) {
    val colors = if (darkTheme) {
        DarkColorPalette
    } else {
        LightColorPalette
    }

    MaterialTheme(
        colors = colors,
        typography = Typography,
        shapes = Shapes,
        content = content
    )
}
c
Yes, that is one recommended approach on customizing your theme in your app. What makes it interesting to you?
m
The layout inspector part makes it interesting. So, basically the inspector displays any components (composables) used inside another. I had not used it before. It's really a fascinating tool.
c
Yes! It’s a great way to learn about how the layering in Compose is working both for the code you are writing, and those from libraries/framework
❤️ 1
Works for Views (XML) as well if you haven’t tried it for those projects
m
Great, even for the libraries of the framework?
c
Yep, if you uncheck “Filter System-Defined Layers” you will see a lot more nodes in the tree
It’s filtered by default since it can make the tree more noisy and less focused on your code. But still informative!
❤️ 1
m
Yes, it's very informative.