Lukasz Kalnik
04/26/2024, 9:00 AMopen class LibraryThemeHolder {
@Composable
open fun LibraryTheme(content: @Composable () -> Unit) {
MaterialTheme(
colorScheme = libraryColorScheme(),
typography = libraryTypography(),
content = content
)
}
open fun libraryColorScheme() {
//...
}
open fun libraryTypography() {
// ...
}
}
It has the disadvantage of having to access the theme through an object. Are there better solutions?Stylianos Gakis
04/26/2024, 9:09 AMFooColors
object, which defaults to whatever theme you got in the library https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]=ButtonDefaults&ss=androidx%2Fplatform%2Fframeworks%2Fsupport and https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]=ButtonDefaults&ss=androidx%2Fplatform%2Fframeworks%2Fsupport
But then allow your callers to call ButtonDefaults.textButtonColors(TheirTheme.colorScheme.primary)
and so onLukasz Kalnik
04/26/2024, 9:16 AMLukasz Kalnik
04/26/2024, 9:17 AMStylianos Gakis
04/26/2024, 9:30 AMMaterialTheme
anyway, you can try and default to fetching the client’s material theme from the composition local, and if it’s not there (if the client does not wrap their composables with MaterialTheme) then use some sane defaults from the library?
Is this kinda what you want to do?Stylianos Gakis
04/26/2024, 9:31 AMLukasz Kalnik
04/26/2024, 9:35 AMMaterialTheme
in the library.
Library screens are under my complete control (the client doesn't modify/access the composables there, I just wrap them in an activity which the client starts).
I want to give the client the possibility to overwrite some parameters of my theme (colors/text styles) and the rest should be defaults from the library.Lukasz Kalnik
04/26/2024, 9:36 AMStylianos Gakis
04/26/2024, 9:38 AMStylianos Gakis
04/26/2024, 9:38 AMfun lightColorScheme(
primary: Color = YourLibraryTokens.Primary,
onPrimary: Color = YourLibraryTokens.OnPrimary,
primaryContainer: Color = YourLibraryTokens.PrimaryContainer,
onPrimaryContainer: Color = YourLibraryTokens.OnPrimaryContainer,
inversePrimary: Color = YourLibraryTokens.InversePrimary,
secondary: Color = YourLibraryTokens.Secondary,
onSecondary: Color = YourLibraryTokens.OnSecondary,
secondaryContainer: Color = YourLibraryTokens.SecondaryContainer,
onSecondaryContainer: Color = YourLibraryTokens.OnSecondaryContainer,
tertiary: Color = YourLibraryTokens.Tertiary,
onTertiary: Color = YourLibraryTokens.OnTertiary,
tertiaryContainer: Color = YourLibraryTokens.TertiaryContainer,
onTertiaryContainer: Color = YourLibraryTokens.OnTertiaryContainer,
background: Color = YourLibraryTokens.Background,
onBackground: Color = YourLibraryTokens.OnBackground,
surface: Color = YourLibraryTokens.Surface,
onSurface: Color = YourLibraryTokens.OnSurface,
surfaceVariant: Color = YourLibraryTokens.SurfaceVariant,
onSurfaceVariant: Color = YourLibraryTokens.OnSurfaceVariant,
surfaceTint: Color = primary,
inverseSurface: Color = YourLibraryTokens.InverseSurface,
inverseOnSurface: Color = YourLibraryTokens.InverseOnSurface,
error: Color = YourLibraryTokens.Error,
onError: Color = YourLibraryTokens.OnError,
errorContainer: Color = YourLibraryTokens.ErrorContainer,
onErrorContainer: Color = YourLibraryTokens.OnErrorContainer,
outline: Color = YourLibraryTokens.Outline,
outlineVariant: Color = YourLibraryTokens.OutlineVariant,
scrim: Color = YourLibraryTokens.Scrim,
surfaceBright: Color = YourLibraryTokens.SurfaceBright,
surfaceContainer: Color = YourLibraryTokens.SurfaceContainer,
surfaceContainerHigh: Color = YourLibraryTokens.SurfaceContainerHigh,
surfaceContainerHighest: Color = YourLibraryTokens.SurfaceContainerHighest,
surfaceContainerLow: Color = YourLibraryTokens.SurfaceContainerLow,
surfaceContainerLowest: Color = YourLibraryTokens.SurfaceContainerLowest,
surfaceDim: Color = YourLibraryTokens.SurfaceDim,
): ColorScheme
or whatever?Lukasz Kalnik
04/26/2024, 10:09 AM