Skip to content

Conversation

@ansman
Copy link

@ansman ansman commented Oct 10, 2025

They aren't affected by the brush directly, so we need to set the alpha.

They aren't affected by the brush directly, so we need to set the alpha.
AnnotatedString.Range(SpanStyle(brush = DynamicSolidColor(color, alpha)), 0, length)
val fullStyle = AnnotatedString.Range(
item = if (useDynamicColor) {
SpanStyle(brush = DynamicSolidColor(color, alpha))

Choose a reason for hiding this comment

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

i'm pretty confused here, why does it use dynamic color in one but..... also in the else block

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, so it's really annoying. The SpanStyle can either take in a color, or a brush. It also takes in an optional alpha.
If you pass a color (or a SolidColor brush), the the alpha you pass is multiplied into the color itself. But since Emojis ignore the color (since they can't be tinted) any alpha we pass is completely ignored. So we need to pass a ShaderBrush AND an alpha. Our DynamicSolidColor brush does accept an alpha but it too just multiplies the alpha into the color and thus has the same issue.

So we're forced to pass a shader brush and I chose to use DynamicSolidColor with an alpha of 1, then pass alpha separately which will set the paint alpha and thus affect emojis.

This does have the side effect of recomposing on alpha change but only for paragraphs with emojis so I think it's fine.

val cp = Character.codePointAt(this, i)

// --- Quick accepts: common emoji blocks ---
val isEmoji = when (cp) {

Choose a reason for hiding this comment

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

theres seriously no easier 'is emoji'??

Copy link
Author

Choose a reason for hiding this comment

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

Not really unfortunately because it's complicated. There is a regex you can use, but I figures this was faster since it's a best effort only.

@ansman ansman merged commit 4d3846b into main Oct 10, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants