You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LineHeight is working weird on specific fonts (Android Only) #29232
Unfortunately the issue still persists for me in 0.65.1. But I found a super strange workaround for this issue and would be curious if that also works for you. Maybe it also helps finding out what the underlying issue is.
Starting Point
<Text>aaa...</Text>
fontSize: 16,
lineHeight: 24
Strange workaround
Add an empty nested Text and give it lineHeight +1 of the parent.
I noticed that lineHeight + 1 seems to add a noticeable amount of space to the text node (I'm using react-native-capsize to trim space above capital letters and below the baseline).
It looks like literally any non-zero difference to the parent line height also fixes it, e.g.lineHeight + 0.001 also works for me and doesn't introduce unwanted space.
Reacted by Nicolás M. Pardo, mike douges, fatfisz, Nahuel Ambrosini, Kennet Postigo, Parichay Agrawal and Emin Khateeb
I also noticed that this bug can affect text nodes on Android when when numberOfLines causes text to truncate, even when it's just a single line of text. Luckily the workaround posted earlier fixes this issue too, but decided to share for completeness.
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.
Reacted by SeungRyeol Lee, Emin Khateeb, Mark Dalgleish, Pierre Saikali, Daniel Morales González, Nikita K, Felipe Lima, Salma BENSALAH, Simon Quick, Dániel Gergely and 2 more
Unfortunately the issue still persists for me in 0.65.1. But I found a super strange workaround for this issue and would be curious if that also works for you. Maybe it also helps finding out what the underlying issue is.
Starting Point
<Text>aaa...</Text>
fontSize: 16,
lineHeight: 24
Strange workaround
Add an empty nested Text and give it lineHeight +1 of the parent.
Reporting back after a while - this issue is still present. While the provided workaround might solve the issue with the first two lines, it unfortunately is not a "one size fits all" solution. When applied on single line texts it causes the vertical alignment to be off. includeFontPadding and textAlignVertical don't help in that case either.
I'm also seeing this issue when trying to correctly align the placeholder text inside the Android-specific SearchBar component from React Native Elements. Unfortunately, the workaround mentioned doesn't work for me, and the placeholder remains too high, so I've had to resort to the crude paddingTop: 3 to give it the nudge it needs. This is with the Poppins font, specifically Poppins_400Regular.
Reacted by Ali-Hassan, Devio__ and earlGrantHomage
There is some complex logic that tries to center the font in an appropriate way if the line size is below a certain amount. It can happen if the font has unusual metadata, like the capheight being very tall.
I don't think this happens on IOS or web, at least I don't see it happening in practice nor can I find any code that does it.
Adding magic offsets to line height will only make it work for that specific font, at that specific size and line height.
Reacted by Daniel Morales González and SeungRyeol Lee
There is some complex logic that tries to center the font in an appropriate way if the line size is below a certain amount. It can happen if the font has unusual metadata, like the capheight being very tall.
I don't think this happens on IOS or web, at least I don't see it happening in practice nor can I find any code that does it.
Adding magic offsets to line height will only make it work for that specific font, at that specific size and line height.
This issue still persists. I tried the workaround suggested by @emin93, but it didn't work. To fix it, I added a marginTop specifically for Android. However, it feels somewhat dirty.
For most of the fonts you should apply ascender/descender metrics to make it render correctly at first and last lines.
this tool might help you understand https://vertical-metrics.netlify.app/
Though there are broken fonts (made by font designers) where you should add workarounds 😄
based on ascender/descender data you can dynamically calculate your padding top
Though maybe someone has better approach, for me nothing worked except doing all calculations on my own
Unfortunately the issue still persists for me in 0.65.1. But I found a super strange workaround for this issue and would be curious if that also works for you. Maybe it also helps finding out what the underlying issue is.
Starting Point
<Text>aaa...</Text>
fontSize: 16,
lineHeight: 24
Strange workaround
Add an empty nested Text and give it lineHeight +1 of the parent.
For most of the fonts you should apply ascender/descender metrics to make it render correctly at first and last lines. this tool might help you understand https://vertical-metrics.netlify.app/
Though there are broken fonts (made by font designers) where you should add workarounds 😄
based on ascender/descender data you can dynamically calculate your padding top
Though maybe someone has better approach, for me nothing worked except doing all calculations on my own
Thank you so much! I ran into this issue with custom font after switching to target SDK 33 and this app was immensely useful in showing what to fix in the font to make it behave 'normally'. I ended up rebuilding the font with proper location of glyphs.
The solution from @emin93 is nice! But I found that solution can't fix the paragragh problem. The lines still stick together after a newline. If you are facing same issue like me, I have another solution that is based on @emin93's solution.
My workaround. Is not breaking ref, works as drop in replacement
pnpm i react-fast-hoc
importReactfrom'react';import{transformProps}from'react-fast-hoc';import*asRNfrom'react-native';// Fix of android lineHeight problems https://github.com/facebook/react-native/issues/29232#issuecomment-1721080348if(RN.Platform.OS==='android'){// Clone text since we modify itconstOriginalText=Object.assign({},RN.Text);Object.assign(RN.Text,transformProps(RN.Text,(props)=>{conststyle=RN.StyleSheet.flatten(props.style);if(!style?.lineHeight){returnprops;}constchildren=[
...React.Children.toArray(props.children),React.createElement(OriginalText,{key: '__text_fix',style: {lineHeight: style.lineHeight+0.0001,},}),];props.children=children;returnprops;}),);}
We have 1000+ issues, the dev would end up not being productive and better develop his app with the Android Sdk or iOS SDK. My patch does not fix 1 issue. I plan to fix 1000-2000 issues.
I don't think it is even worth documenting this. distributing 1 patch with react-native-improved and fixing the issue at the source is the solution.
My workaround. Is not breaking ref, works as drop in replacement
pnpm i react-fast-hoc
importReactfrom'react';import{transformProps}from'react-fast-hoc';import*asRNfrom'react-native';// Fix of android lineHeight problems https://github.com/facebook/react-native/issues/29232#issuecomment-1721080348if(RN.Platform.OS==='android'){// Clone text since we modify itconstOriginalText=Object.assign({},RN.Text);Object.assign(RN.Text,transformProps(RN.Text,(props)=>{conststyle=RN.StyleSheet.flatten(props.style);if(!style.lineHeight){returnprops;}constchildren=[
...React.Children.toArray(props.children),React.createElement(OriginalText,{key: '__text_fix',style: {lineHeight: style.lineHeight+0.0001,},}),];props.children=children;returnprops;}),);}
We have 1000+ issues, the dev would end up not being productive and better develop his app with the Android Sdk or iOS SDK. My patch does not fix 1 issue. I plan to fix 1000-2000 issues.
I don't think it is even worth documenting this. distributing 1 patch with react-native-improved and fixing the issue at the source is the solution.
I am sceptical about patching, it can be complicated and unsafe. But maybe you're doing it in the correct way.
Also our project is 0.72 RN version, so this solution is not appliable for us
The issue does not reproduce when you don't set the lineHeight?
because every text has by default a lineHeight, which is calculated on their font ascent and descent.
React Native often does not work well with custom font, because custom font has different font ascent and descent.
As react native over-rides onMeasure in ReactShadowTextView, it calculates the font lineHeight internally based on their font ascent and descent to calculate the Text height.
but maybe this does not work with custom fonts.
The PR from MD Vacca only sets the lineHeight, but when no lineHeight is set, do we really take in account that the Text onMeasure function correctly calculates height based on the custom font Text ascent and descent?
Maybe the issue is not fixed on nested text? The current implementation maybe does not support nested text.
I believe the change now sets 1 lineHeight for the entire Text, so in this case, they would all have lineHeight 20. Previously you could have 2 text with different lineHeight.
In my case, I am using a custom font and only setting the fontSize without specifying a lineHeight. When there are multiple paragraphs or just one, it has a strange effect. In the first lines, it's as if it applies less lineHeight than in the following ones:
In my case, I am using a custom font and only setting the fontSize without specifying a lineHeight. When there are multiple paragraphs or just one, it has a strange effect. In the first lines, it's as if it applies less lineHeight than in the following ones:
I think the only solution with this workaround is to use lineHeight explicitly. Because we cannot calc lineHeight from font size
As the solution from @XantreDev did not work for multiline paragraphs for me, I played a bit more with his solution and came up with an approach that does the trick for all sorts of Text in our app.
Hi, does this issue resolve. I use font NotoSans , with the normal text is working fine. But with special characters don't working. Does anyone have any solution for this?
Activity
emin93 commentedon Jul 30, 2021
Unfortunately the issue still persists for me in
0.65.1. But I found a super strange workaround for this issue and would be curious if that also works for you. Maybe it also helps finding out what the underlying issue is.Starting Point
Strange workaround
Add an empty nested
Textand give it lineHeight +1 of the parent.Summary
I created a component that does the job:
markdalgleish commentedon Sep 24, 2021
@emin93 Thanks for the workaround!
I noticed that
lineHeight + 1seems to add a noticeable amount of space to the text node (I'm using react-native-capsize to trim space above capital letters and below the baseline).It looks like literally any non-zero difference to the parent line height also fixes it, e.g.
lineHeight + 0.001also works for me and doesn't introduce unwanted space.emin93 commentedon Sep 29, 2021
@markdalgleish Ah that's good to know, thanks!
markdalgleish commentedon Sep 29, 2021
I also noticed that this bug can affect text nodes on Android when when
numberOfLinescauses text to truncate, even when it's just a single line of text. Luckily the workaround posted earlier fixes this issue too, but decided to share for completeness.stale commentedon Jan 9, 2022
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.
SleeplessByte commentedon Jan 10, 2022
Not stale.
manoj-clix commentedon Jan 12, 2022
Thanks @emin93 , it's working with your suggested changes.
zecergin commentedon Feb 14, 2022
The issue still persists for me in 0.64.3. However, the strange workaround from @emin93 works.
emin93 commentedon Feb 18, 2022
Reporting back after a while - this issue is still present. While the provided workaround might solve the issue with the first two lines, it unfortunately is not a "one size fits all" solution. When applied on single line texts it causes the vertical alignment to be off.
includeFontPaddingandtextAlignVerticaldon't help in that case either.darrylyoung commentedon Jun 14, 2022
I'm also seeing this issue when trying to correctly align the placeholder text inside the Android-specific
SearchBarcomponent from React Native Elements. Unfortunately, the workaround mentioned doesn't work for me, and the placeholder remains too high, so I've had to resort to the crudepaddingTop: 3to give it the nudge it needs. This is with thePoppinsfont, specificallyPoppins_400Regular.psaikali commentedon Aug 26, 2022
Can confirm, this is still a bug (using GrotaRounded custom font for instance) on Android.
But @emin93 weird workaround works indeed!
CapsAdmin commentedon Sep 14, 2022
I believe this is caused by
https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/views/text/CustomLineHeightSpan.java#L25
There is some complex logic that tries to center the font in an appropriate way if the line size is below a certain amount. It can happen if the font has unusual metadata, like the capheight being very tall.
I don't think this happens on IOS or web, at least I don't see it happening in practice nor can I find any code that does it.
Adding magic offsets to line height will only make it work for that specific font, at that specific size and line height.
felipecsl commentedon Mar 31, 2023
This file has moved to https://github.com/facebook/react-native/blob/main/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/CustomLineHeightSpan.java
CustomLineHeightSpanclaims to exist because of #7546 which seems to have been already fixed, so this workaround might not be needed anymoreKevinvdBurg commentedon Jun 13, 2023
This issue still persists. I tried the workaround suggested by @emin93, but it didn't work. To fix it, I added a marginTop specifically for Android. However, it feels somewhat dirty.
jerryphm commentedon Jun 22, 2023
I'm facing this problem too (version: react-native 0.70.9)
professorkolik commentedon Jun 22, 2023
For most of the fonts you should apply ascender/descender metrics to make it render correctly at first and last lines.
this tool might help you understand https://vertical-metrics.netlify.app/
Though there are broken fonts (made by font designers) where you should add workarounds 😄
based on ascender/descender data you can dynamically calculate your padding top
Though maybe someone has better approach, for me nothing worked except doing all calculations on my own
shixiaoquan commentedon Aug 14, 2023
This solution is awesome, but not work for me.
It worked when I place {children} after {Platform.OS ........} like below
sashagreen commentedon Aug 30, 2023
Thank you so much! I ran into this issue with custom font after switching to target SDK 33 and this app was immensely useful in showing what to fix in the font to make it behave 'normally'. I ended up rebuilding the font with proper location of glyphs.
carrie503 commentedon Sep 15, 2023
The solution from @emin93 is nice! But I found that solution can't fix the paragragh problem. The lines still stick together after a newline. If you are facing same issue like me, I have another solution that is based on @emin93's solution.
fabOnReact commentedon Jan 16, 2024
Do you still experience this issue? If yes, I will publish the fix in the react-native-improved package https://github.com/fabriziobertoglio1987/react-native-improved. Thanks a lot
XantreDev commentedon Jan 25, 2024
This is just crazy that this issue still a problem. @fabOnReact Can it be fixed without patches?)
XantreDev commentedon Jan 25, 2024
My workaround. Is not breaking ref, works as drop in replacement
Before
After
fabOnReact commentedon Jan 25, 2024
@XantreGodlike I believe this should be fixed in rn-core. If the developer needs:
We have 1000+ issues, the dev would end up not being productive and better develop his app with the Android Sdk or iOS SDK. My patch does not fix 1 issue. I plan to fix 1000-2000 issues.
I don't think it is even worth documenting this. distributing 1 patch with react-native-improved and fixing the issue at the source is the solution.
fabOnReact commentedon Jan 25, 2024
I will text this solution and implement it in rn-core. If you are interested, you can send PR to https://github.com/fabriziobertoglio1987/react-native-improved. Thanks
fabOnReact commentedon Jan 25, 2024
https://github.com/facebook/react-native/pull/42655/files
XantreDev commentedon Jan 25, 2024
I am sceptical about patching, it can be complicated and unsafe. But maybe you're doing it in the correct way.
Also our project is 0.72 RN version, so this solution is not appliable for us
XantreDev commentedon Jan 25, 2024
The issue says that it fixes this bug on new arch
fabOnReact commentedon Jan 25, 2024
The issue does not reproduce when you don't set the lineHeight?
because every text has by default a lineHeight, which is calculated on their font ascent and descent.
React Native often does not work well with custom font, because custom font has different font ascent and descent.
As react native over-rides onMeasure in ReactShadowTextView, it calculates the font lineHeight internally based on their font ascent and descent to calculate the Text height.
but maybe this does not work with custom fonts.
The PR from MD Vacca only sets the lineHeight, but when no lineHeight is set, do we really take in account that the Text onMeasure function correctly calculates height based on the custom font Text ascent and descent?
fabOnReact commentedon Jan 25, 2024
Maybe the issue is not fixed on nested text? The current implementation maybe does not support nested text.
I believe the change now sets 1 lineHeight for the entire Text, so in this case, they would all have lineHeight 20. Previously you could have 2 text with different lineHeight.
https://github.com/facebook/react-native/pull/42655/files#diff-e14e9099724d0087bcf9e2847733e8a132fbcb18c5f0d77d8867ff30528c704eR275
for ex.
I worked on something similar in the past and I can easily implement it in text.
Hyuchiha commentedon Jan 26, 2024
In my case, I am using a custom font and only setting the fontSize without specifying a lineHeight. When there are multiple paragraphs or just one, it has a strange effect. In the first lines, it's as if it applies less lineHeight than in the following ones:
XantreDev commentedon Jan 26, 2024
I think the only solution with this workaround is to use lineHeight explicitly. Because we cannot calc lineHeight from font size
react-native-bot commentedon Jul 27, 2024
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
XantreDev commentedon Jul 27, 2024
Bump
jdschin commentedon Jan 22, 2025
Im also facing this issue
breezertwo commentedon Feb 5, 2025
As the solution from @XantreDev did not work for multiline paragraphs for me, I played a bit more with his solution and came up with an approach that does the trick for all sorts of Text in our app.
This is the workaround we currently use:
Call the method somewhere (e.g App.tsx) in a useEffect and the
lineHeightshould work.huynextlevel commentedon Mar 30, 2025
Hi, does this issue resolve. I use font
NotoSans, with the normal text is working fine. But with special characters don't working. Does anyone have any solution for this?String:
✿ ♬ メ ༒ ☉ 亗 〆★ ㏾*㏾*㏾*㏾*㏾*㏾*㏾react-native-bot commentedon Sep 27, 2025
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
SleeplessByte commentedon Sep 27, 2025
Stale bots should not exist.
react-native-bot commentedon Mar 27, 2026
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
XantreDev commentedon Mar 28, 2026
Bump
react-native-bot commentedon Sep 25, 2026
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
react-native-bot commentedon Oct 2, 2026
This issue was closed because it has been stalled for 7 days with no activity.