Dmitry
Dmitry

Reputation: 109

Jetpack Compose add custom themed colors to library

I develop library with composables. Composables have different foregone colors set for light and dark theme. For example backgroundColor, buttonColor, progressLineColor. I don't want library users to pass any information about theme or colors to composables of library.

What I want is

@Composable
fun SomeLibraryComposable(someText: String) {
    // This color should be different for light/dark modes of consumer app
    val backgroundColor = getThemedBackroundColor()
    ....
}

I see that it is possible to add custom themed palette, using staticCompositionLocalOf, like here. But:

  1. I can't wrap composables in my theme inside library, because I don't know if it's dark or light mode in app. isSystemInDarkMode is appliable only if app uses system dark mode
  2. I should not make library users add staticCompositionLocalOf with my palette to their theme
  3. I should not make library users pass darkMode: Boolean to composables of library to create corresponding theme

Upvotes: 1

Views: 23

Answers (0)

Related Questions