https://kotlinlang.org logo
#compose
Title
# compose
k

Kevin Hester

02/17/2020, 6:49 PM
Is this the preferred way to merge TextStyles (in this case picking a standard style and then bumping down the opacity)?
Copy code
Text(
    text = "9:49 AM",
    modifier = LayoutPadding(left = 8.dp),
    style = MaterialTheme.typography().caption.merge(
        TextStyle(
            color = palette.onSecondary.copy(
                alpha = 0.2f
            )
        )
    )
)
If so, what about letting TextStyles have an + operator to make their usage more similar to Modifiers?
l

Louis Pullen-Freilich [G]

02/17/2020, 6:58 PM
In this example, you can just use
.copy(color =...
instead of needing to fully merge. Although instead of copying text styles and changing opacity, you should take a look at
ProvideEmphasis
- it's intended for the use case of modifying opacity of some content
k

Kevin Hester

02/17/2020, 7:16 PM
ooh thanks a lot I'll take a look at ProvideEmphasis!
k

Kevin Hester

02/17/2020, 7:22 PM
thanks! worked great.
Copy code
ProvideEmphasis(emphasis = MaterialTheme.emphasisLevels().disabled) {
    Text(
        text = dateFormat.format(msg.date),
        modifier = LayoutPadding(left = 8.dp),
        style = MaterialTheme.typography().caption
    )
}
l

Louis Pullen-Freilich [G]

02/17/2020, 7:23 PM
Cool, happy to hear 🙂 Semantically it means a lot more than just copying an alpha value too, so I think it's a nice way of expressing alpha
k

Kevin Hester

02/17/2020, 7:24 PM
yep - though I'd say in this case I'm not really trying to convey "disabled" as much as I'm trying to convey "minor"
(and yep - I'm cribbing from the slack look and feel also - I suck at UX)
l

Louis Pullen-Freilich [G]

02/17/2020, 7:26 PM
Yeah, disabled is wrong here for sure. If this doesn't map cleanly to something from the Material spec, I think it would make sense to just create your own emphasis for this component.
Copy code
val TimestampEmphasis = object: Emphasis {
    override fun emphasize(color: Color) = color.copy(alpha = 0.12f)
}
    
ProvideEmphasis(TimestampEmphasis) { ... }
❤️ 1
k

Kevin Hester

02/17/2020, 7:27 PM
ooh! that is nice. thanks again. (I'm a 99% embedded device sw or backend geek ;-))