question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android React Text Component includeFontPadding:false incorrect height

See original GitHub issue

On Android, when includeFontPadding is set to false, the React Text component does not adjust its height. This makes it difficult to lay out other components at a precise spacing relative to a Text component.

For the native TextView component, the height is different depending on the value of includeFontPadding-

When includeFontPadding is set to true, the height of the TextView is based on abs(FontMetrics.top) + abs(FontMetrics.bottom).

When includeFontPadding to set to false, the height of the TextView is based on abs(FontMetrics.ascent) + abs(FontMetrics.descent).

This is happening because in ReactTextShadowNode.java, includeFontPadding is hardcoded to true when passing parameters to StaticLayout and BoringLayout. This seems like an easy fix.

An example from the measure function in ReactTextShadowNode.java -

private final YogaMeasureFunction mTextMeasureFunction = new YogaMeasureFunction() {

BoringLayout.make(
                text,
                textPaint,
                boring.width,
                Layout.Alignment.ALIGN_NORMAL,
                1.f,
                0.f,
                boring,
                true); // this parameter is includeFontPadding and should be based on the includeFontPadding value style of the component
...
};

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
mishagreenbergcommented, Aug 4, 2017

#14609 is a PR to fix this issue

0reactions
mishagreenbergcommented, Aug 21, 2017

#14609 was merged

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native: Height of Text-component is calculated wrong ...
I popped it into my project and the Text component was now able to calculate its height correctly. Share.
Read more >
View - React Native
View maps directly to the native view equivalent on whatever platform React Native is running on, whether that is a UIView , <div>...
Read more >
React Text Field component - Material UI - MUI
The multiline prop transforms the text field into a TextareaAutosize element. Unless the rows prop is set, the height of the text field...
Read more >
Higher-Order Components - React
A higher-order component (HOC) is an advanced technique in React for reusing component logic. HOCs are not part of the React API, per...
Read more >
Why My Text Is Going Off Screen? The Truth about React ...
To all the ones who lost control of their Text in React Native ? ... is to add a style {{ flex:1, flexWrap:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found