Measure the size of a string of text in React Native synchronously.
This can be useful for calculating the size of a string of text before rendering it, for example for animation targets.
npm install @domir/react-native-measure-text
Run npx pod-install
after installing the npm package.
No additional configuration is needed.
import * as MeasureText from '@domir/react-native-measure-text';
MeasureText.measureWidth('Hello World', {
fontSize: 20,
fontFamily: 'Helvetica',
fontWeight: 'normal',
// TBD
// fontStyle: 'normal',
// fontVariant: ['small-caps'],
// letterSpacing: 0,
// lineHeight: 20,
// textAlign: 'left',
// textDecorationLine: 'none',
// textTransform: 'none',
// includeFontPadding: true,
// maxWidth: 100,
// maxHeight: 100,
// numberOfLines: 1,
// ellipsizeMode: 'tail',
})