I'm currently trying to make my React Native application based on Expo without dropping down to native dependencies. I'm wondering if there is a way to measure text (down to the pixel) so I can make some intelligent choices about layouts without ending up with elides or weird wrapping.
Basically I'd like to be able to do something like:
//Pseudo Code
class SomeScreen extends React.Component {
//returns a height that fits the width without wrapping
fitToWidth(text, width) {
//I don't have a framework for this in Expo
}
render() {
<View>
<MyText fontSize={fitToWidth('SomeString', 375)} value='Some String' />
</View>
}
}
It would be really nice to have this run in Expo due to the ease of testing and I'm hoping someone has an idea of how to achieve this. There are some libraries that I can drop down into, but it requires ejecting out of the Expo build process which means it is no longer portable.
I realize there's a lot more to do to be able to render this, but I can already figure out the width and height of views and I'm hoping I can find a way to measure text to select a font based on the screen size rather than trying to depend on points.