When using `CompositionLocalProvider` to provide ...
# compose
a
When using
CompositionLocalProvider
to provide alpha and text values, should the approach be different when using an annotated string? When I use a simple Text composable, the alpha and color is applied, but a annotated string inside a clickable text does not reflect these changes.
Copy code
CompositionLocalProvider(
                    LocalContentAlpha provides ContentAlpha.medium,
                    LocalContentColor provides Color.White
                ) {
Text("Hello")
}
This works
Copy code
CompositionLocalProvider(
                    LocalContentAlpha provides ContentAlpha.medium,
                    LocalContentColor provides Color.White
                ) {
                    ClickableText(
                        text = annotatedString,
                        onClick = { offset ->
                            annotatedString.getStringAnnotations(
                                tag = "terms",
                                start = offset,
                                end = offset
                            ).firstOrNull()?.let {
                                Log.d("terms", it.item)
                            }
                            annotatedString.getStringAnnotations(
                                tag = "privacyPolicy",
                                start = offset,
                                end = offset
                            ).firstOrNull()?.let {
                                Log.d("privacyPolicy", it.item)
                            }
                        },
                        // style = MaterialTheme.typography.subtitle2,
                        modifier = Modifier.padding(start = 32.dp, end = 32.dp)
                    )
                }
This does not
z
Text
is a material component, and
LocalContent*
locals are part of the material theming implementation.
ClickableText
isn’t material, and doesn’t know about those. We’re aware that
ClickableText
has a lot of issues and are planning to come up with a more flexible solution eventually.
a
Ah ok makes sense, I got around my issue by just setting the alpha values/color values in the SpanStyle, the code isn't much cleaner having to copy paste it everywhere, but it works