This message was deleted.
# compose
s
This message was deleted.
s
I'd suggest you take a look at how material3 library does this. There is one theme which contains all colors. Each composable takes in a custom class which contains the colors that will be used specifically for that one composable. And it defaults to some colors that come from the theme. But they are still overridable if the caller wishes to do so
Is CategoryTheme a version of AppTheme, or are they two completely separate themes that have nothing to do with each other?
And is it entire screens that sometimes need to be entirely in CategoryTheme? And not just individual components? If yes, your small component shouldn't even have to know anything about CategoryTheme. It can grab things from the local AppTheme, and you need to make sure that your specifically styled screens are wrapped with the correct composition local. So your theme probably looks smth like
Copy code
object AppTheme {
  /**
   * Retrieves the current [ColorScheme] at the call site's position in the hierarchy.
   */
  val colorScheme: ColorScheme
    @Composable
    @ReadOnlyComposable
    get() = LocalColorScheme.current
}
For that screen, you need to have called
Copy code
CategoryTheme {
  ThatScreen()
}
Where
CategoryTheme
should do
Copy code
CompositionLocalProvider(LocalColorScheme provides categoryColorScheme) {
  content()
}
where
categoryColorScheme
should be the
ColorScheme
for that other theme of yours
Then inside that composable do
Copy code
fun WhateverComposable() {
  Something()
  CategoryTheme {
    SomethingWithCategoryTheme
  }
  SomethingElse()
}
Even though I must admit it looks fishy to have mixed themes used like that not only within one screen, but within even one component.
What is
CategoryTheme
exactly in your case? Is it the entire theme object that contains typography, colorschemes, shapes etc?
Sounds to me like you want to wrap those specific products and categories completely with smth like
CetegoryTheme {}
and inside the object itself you can still use AppTheme.colorScheme.primary, and it will then grab the right one that was provided by your composition local override. That's how I interpret this tbh. I think jetcaster https://github.com/android/compose-samples/tree/main/Jetcaster does something similar with having the same theme but with overridden colors in some contexts