21

I was wondering why am getting these weird padding on my Text in react-native. I tried every thing to just get a perfect text but nothing seems to work the only thing that worked was paddingVertical and paddingHorizontal but it's way too hacky and not reliable.

<Text numberOfLines={1} 
      style={{
            backgroundColor: 'red', 
            lineHeight: 92, 
            textAlign: 'center', 
            textAlignVertical: 'center', 
            padding: 0, 
            margin: 0, 
            fontSize: 92,  
            color: '#2d76ff', 
            fontFamily: 'Roboto-Regular', 
            includeFontPadding: false}}>
      {this.state.documents}
</Text>

Zeplin

enter image description here

Screenshot from my HTC

enter image description here

J. Chomel
  • 8,193
  • 15
  • 41
  • 69
Ibrahim Ahmed
  • 2,295
  • 4
  • 21
  • 35
  • Can you update your question to add a bit more information? Where exactly is the extra padding you are trying to remove in your screenshot? – Irfan Ayaz Jan 13 '17 at 03:07
  • Are you using a custom font (I don't think Roboto is default)? Is this behavior specific to either Android or iOS? I had a similar problem on Android where I found a kind of hacky solution: http://stackoverflow.com/questions/41570343 – henkimon Jan 16 '17 at 18:21

3 Answers3

22

I stumbled onto this issue because I was experiencing the same. The text component has a prop called includeFontPadding. You can set it to false to remove the extra padding.

Check the React Native Docs for reference: https://facebook.github.io/react-native/docs/text-style-props#includefontpadding

Wilfred Mulenga
  • 378
  • 3
  • 10
  • I had no idea this was a thing - this will save me a ton of headaches in future. Thanks! – boz Sep 16 '19 at 14:27
8

Try adding this to style

includeFontPadding:false
el2e10
  • 1,518
  • 22
  • 22
0

Additional: Every add or remove includeFontPadding property, should refresh(press r) on metro server(in my case react native 0.66 and use own font family)