applyStyles

Returns a new AnnotatedString with SpanStyle matching AnnotatedString.Range. The transform function is invoked on each element of the annotations list.

Example

    val str = buildAnnotatedString {
pushStringAnnotation("value", "")
append("12")
pop()
pushStringAnnotation("separator", "")
append(" - ")
pop()
pushStringAnnotation("unit", "")
append("hours")
pop()
}.applyStyles { annotation ->
when(annotation.tag) {
"value" -> SpanStyle(color = Color.Red)
"unit" -> SpanStyle(color = Color.Blue)
else -> null // strip 'separator'
}
}

In the above example, given the AnnotatesString with annotations:

<value>12</value><separator> - </separator><unit>hours</unit>

the applyStyle() transform will produce a new AnnotatedString with following styles:

<style color="red">12</style> - <style color="blue">hours</style>

Parameters

transform

function converting string annotation into SpanStyle. Returning null value won't apply any style to the annotation range.