halilozercan / compose-richtext

A collection of Compose libraries for advanced text formatting and alternative display types.
https://halilibo.com/compose-richtext
Apache License 2.0
750 stars 59 forks source link

Support for `CompositionLocalProvider` #102

Open ln-12 opened 1 year ago

ln-12 commented 1 year ago

I want to display my text with an alpha value dependent on its state. Usually, I would do it like shown here to wrap all composables which should be affected:

CompositionLocalProvider(LocalContentAlpha provides if(isDisabled) { ContentAlpha.high } else { ContentAlpha.disabled }) {
    RichText(
        modifier = Modifier.padding(8.dp),
    ) {
        Markdown(message.body)
    }
}

However, this solution does not work with RichText, so I found this alternative solution:

MaterialRichText(
    modifier = Modifier.alpha(if(isDisabled) { ContentAlpha.high } else { ContentAlpha.disabled })
) {
    RichText(
        modifier = Modifier.padding(8.dp),
    ) {
            Markdown(message.body)
    }
}

Are you planning to support setting values using CompositionLocalProvider?