Does Compose provide a way to measure intrinsic te...
# compose
b
Does Compose provide a way to measure intrinsic text width/height, synchronously, offscreen OUTSIDE of @Composable function? I'm integrating with a legacy system and it requires measuring certain things ahead of time, with View's you can simply do:
Copy code
val view = MyView(context)
view.measure(widthMeasureSpec, heightMeasureSpec)
return Pair(textView.measuredWidth, view.measuredHeight)
I guess I could use
ComposeView
for this but I'm wondering if there is something more directly available in Compose API.
a
Can you describe the system you're working with a bit more? What is being measured and why?
b
It's a custom layout system that's badly integrated into Android (trust me, I'm trying to migrate away ASAP). I need the intrinsic width/height of a TextView specifically, as we still use Android to render the text.
If there's a lower level API to calculate intrinsic text size specifically (with all the same font/formatting params as
Text()
), that would also work.
a
There is but its name escapes me at the moment, @Siyamed probably knows it off the top of his head or you could search back in this channel's history for text measurement
b
Ahh, I found
TextDelegate
used by
CoreText
which might be it, it's marked as internal but looks like it will work 🙂
a
I think there was something else that isn't marked internal. Expect anything marked internal to change in incompatible ways between stable releases.
🙏 1
👌 1
b
Yeah I see that internally uses
MultiParagraphIntrinsics
which is not marked internal. Also found
ParagraphIntrinsics
. Cool! I think one of those will work for my silly use case.
Better yet, there's
Paragraph
which takes a
width
parameter, this is exactly what I need 🙂
👍 1
158 Views