Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom theming #77

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Custom theming #77

wants to merge 5 commits into from

Conversation

ninovanhooff
Copy link
Collaborator

@ninovanhooff ninovanhooff commented Sep 10, 2024

Why is this important?

  • It was on the wishlist (in readme)
  • MaterialTheme is nice, but it cannot be reconciled with iOS. Therefore tokens in a shared design system are always necessary

Notes

  • Inspired by Hema
  • Removes dynamic color. Can probably be incorporated somewhere, but definetlely not 90% of projects use it
  • explicitly setting font style and color for all texts seems tedious, but in practice the boilerplate is reduced by creating core components like buttons etc (see TemplateButton())

because that is what we are implementing here
Inspired by Hema implementation
@ninovanhooff ninovanhooff added the enhancement New feature or request label Sep 10, 2024
Copy link
Collaborator

@izadiegizabal izadiegizabal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice seeing some more theming added to the template app! i left a couple of comments 🪄

Comment on lines -75 to 54
MaterialTheme(
colorScheme = colorScheme,
typography = Typography,
CompositionLocalProvider(
LocalAppTypography provides typography,
LocalAppColorTokens provides if (darkTheme) AppColorTokensDark else AppColorTokensLight,
LocalAppShapes provides shapes,
content = content
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would expand this a little bit to also provide some crucial elements used thought the app (namely ripples & indicators):

    CompositionLocalProvider(
        LocalAppColorTokens provides if (darkTheme) AppColorTokensDark else AppColorTokensLight,
        LocalAppTypography provides typography,
        LocalAppShapes provides shapes,
        /** configures the ripple for material components */
        LocalRippleConfiguration provides AppRippleConfiguration,
        /** needed for non-material components to have a material ripple. eg [Modifier.clickable] */
        LocalIndication provides AppRipple,
        /** merges the platform style with our type, @see [ProvideTextStyle] for more context */
        LocalTextStyle provides LocalTextStyle.current.merge(typography.body),
        content = content
    )

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potentially also a default LocalContentColor so that at least the base text/content color is defined. it could avoid a lot of issues where a dev forgets to manually specify the color on any component.

Comment on lines 42 to 45
SideEffect {
val window = (view.context as Activity).window
window.statusBarColor = colorScheme.primary.toArgb()
window.statusBarColor = colors.accent.toArgb()
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


@Immutable
data class AppShapes(
val small: Shape = RoundedCornerShape(Dimens.Containers.cornerRadius),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also define a cornerRadiusSmall?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we move the shapes & type to its own files similar to colors?

Comment on lines +6 to +9
object Containers {
val cornerRadius = 8.dp
val cornerRadiusLarge = 16.dp
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we only want this for the shapes, should we move it there instead of leaving it public here? it might be nice to force the usage of the AppTheme.shapes instead of creating new shapes using the corner here


import androidx.compose.ui.graphics.Color

interface AppColorTokens {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would name this AppColorScheme (TemplateColorScheme?) to avoid using token in the word. token is too vague for what this is (for me).

Comment on lines +14 to +17
colors = ButtonDefaults.buttonColors(
containerColor = AppTheme.colors.accent,
contentColor = AppTheme.colors.buttonText
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we define every button color? not doing it could mean that the usage of this button is expanded without defining the colours for it and thus ending with a weirdly themed state

WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
}
}

MaterialTheme(
Copy link
Collaborator Author

@ninovanhooff ninovanhooff Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert: We still need the MaterialTheme wrapper for system Composables like AlertDialog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants