Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why isn't Line Height supported yet? #32

Open
peetzweg opened this issue Dec 8, 2020 · 2 comments
Open

Why isn't Line Height supported yet? #32

peetzweg opened this issue Dec 8, 2020 · 2 comments

Comments

@peetzweg
Copy link

peetzweg commented Dec 8, 2020

This library looks very promising to me, it has a lot of options and seems to be even quite fast!
However, I wonder why line-height is not supported yet as an option for the flatHeights function? 🤔
We use the line-height style prop every now and then and it's a common typography setting as well.

@leeqiangzi
Copy link

遇到这种问题,我的解决方案是获取行数,行数 * 固定行高,然后在标签中再设置一下lineHeight,就能完美解决问题

let content = await NativeModules.RNTextSize.measure({
text: 'xxxxxx....'
....
})

const {lineCount = 0} = content;

const textHeight = lineCount * 20;

@mfkrause
Copy link

mfkrause commented May 5, 2022

We found that this library seems to use the fontSize as the lineHeight for its calculation. So when the lineHeight is different from the fontSize, the calculated height indeed isn't correct anymore. We implemented a little hack around this, which requires the measure() method to be used though instead of the flatHeights() method (since it requires the lineCount property):

const [textHeight, setTextHeight] = useState(0);

const newTextHeight = await RNTextSize.measure({
  text,
  width: maxTextWidth,
  fontFamily,
  fontWeight,
  fontSize,
});
setTextHeight(newTextHeight.height + (newTextHeight.lineCount * (lineHeight - fontSize)));

So we subtract the font size from the line height in order to get the excess line height, multiply that with the calculated amount of lines and add the result of that to the height calculated by the library. Works great for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants