orangy
AnnotatedString
and InlineTextContent
and what blocks me is the static structure of Placeholder
’s width & height. What I’d like to have is placeholder’s size to be derived from the text measurements it replaces. For example, like this text in Slack
I’d like to put background (that I can with SpanStyle) and a border (which is missing from SpanStyle) with rounded rectangle (also not in SpanStyle). I could do this easily with InlineTextContent
if only I could measure it relative to text size, e.g. with some margins/paddings, etc. Any ideas? Thanks!kotlinforandroid
06/20/2022, 9:24 AMColton Idle
06/20/2022, 11:44 PMHalil Ozercan
06/21/2022, 1:23 AM1.em
work in your case? Ofc width is another question. You can then use onTextLayout callback to get a TextLayoutResult and find the bounding box for your replaced text. I'm on mobile right now so I cannot go into detail easily. You can always create a feature request through the issue trackerkotlinforandroid
06/21/2022, 8:02 AMTextLayoutResult
would work with the placeholder together? TextLayoutResult
would need to be called in a composable context, probably the children
argument of InlineTextContent
. But how do you propagate the width information to the placeholder? AFAIK the placeholder data is used to layout the text and only then the children
are evaluated. See my previous answer and the link where I posted my code. I do not see a way on how to propagate that information.
I think this is only a problem for me since I calculate the AnnotatedString
based on my composable input. I remember
the input, thus disallowing composable context during calculation. The only composable context I have is the children
property.
@Composable
fun UI (textData: List<TextData>) {
val (annotatedText, inlineContent) = remember { calculateContent(textData = textData) }
Text(text = text, inlineContent = inlineContent)
}
private fun calculateContent(textData: List<TextData>): Pair<AnnotatedString, Map<String, InlineContent>> {
val inlineContent = mutableMapOf<String, InlineContent>()
return buildAnnotatedString {
// ...
} to inlineContent
}
orangy
<span>
in HTML, including text. So content can keep flowing from left to right (or RTL), and wrapping when needed, even in the middle of the text.orangy
code spans
, people mentions, links (with hover effects) etc.orangy
Halil Ozercan
06/27/2022, 12:38 PMonTextLayout
is definitely not a good solution. It can be a workaround until a better API is added.Halil Ozercan
06/27/2022, 12:39 PMorangy
orangy
kotlinforandroid
07/29/2022, 4:30 PMorangy
Zach Klippenstein (he/him) [MOD]
07/29/2022, 7:15 PM