react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[Style][iOS]The style lineHeight behaves not exactly same as CSS

Open cxfeng1-zz opened this issue 11 years ago • 8 comments

I write a Text component whose style is:

text: {
    height: 60,
    fontSize: 12,
    width:50,
    padding:5,
    color: 'rgb(238, 238, 238)',
    fontFamily: 'Helvetica Neue',
    lineHeight: 50,
    backgroundColor: 'rgb(190, 173, 146)'
  },

It appears like this in iOS device :

2015-09-23 9 33 12

But in Web, it is supposed to be like :

2015-09-23 9 38 05

The text should be vertically centered.

Is there any way to fix this ? Some FE is used to use lineHeight=height to make the text vertically centered.

cxfeng1-zz avatar Sep 24 '15 02:09 cxfeng1-zz

In addition, the text height measured in RCTMeasure is also not exactly same as H5, about 1.5px smaller than H5's text height

cxfeng1-zz avatar Sep 25 '15 02:09 cxfeng1-zz

What is "H5"? Do you mean an h5 element?

ide avatar Sep 25 '15 02:09 ide

@ide H5 = HTML5 = Web, I used same CSS style in Web, but it behaves differently.

cxfeng1-zz avatar Sep 25 '15 02:09 cxfeng1-zz

OK. The centering behavior should probably be the same but I'm not sure about the text height. There are some things that iOS and Android and browsers all do differently and font rendering is one of them.

ide avatar Sep 25 '15 02:09 ide

I wrote a demo in https://rnplay.org/apps/mJMANg. and the lineHeight has no effect on Android. maybe. I should use marginTop/marginBottom instead of lineHeight.

timzaak avatar Sep 30 '15 06:09 timzaak

Does this issue have a good solution? I have the same problem and it cause a lot problems when typesetting.

iplus26 avatar Nov 14 '15 06:11 iplus26

Same problem here. I set lineHeight to 40, but the real line height is 40.975.

john916zhang avatar Feb 18 '16 23:02 john916zhang

Sure, I found this problem when I use line-height attribute ,hope that the text is is vertical align in the box, but it is not.

xueduany avatar Mar 29 '16 07:03 xueduany