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

Setting text contains combination of Chinese and English with lineHeight style cause characters not on same baseline #19193

Closed
3 tasks done
evianzhow opened this issue May 9, 2018 · 10 comments
Labels
Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.

Comments

@evianzhow
Copy link

evianzhow commented May 9, 2018

Environment

Environment:
OS: macOS High Sierra 10.13.4
Node: 10.0.0
Yarn: 1.6.0
npm: 6.0.0
Watchman: 4.9.0
Xcode: Xcode 9.3 Build version 9E145
Android Studio: 3.1 AI-173.4720617

Packages: (wanted => installed)
react: 16.3.1 => 16.3.1
react-native: ~0.55.2 => 0.55.3

Steps to Reproduce

https://snack.expo.io/rkOLGklCG

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <Text
          style={styles.text}
          numberOfLines={2}>
          这里是中文 This is English 1234567890 这里是数字 This is numbers 123456789
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
  text: {
    maxWidth: '80%',
    fontSize: 17,
    color: '#4e4e4e',
    lineHeight: 24,
  },
});

Expected Behavior

I migrated my app from 0.52.3 and previous version works fine. All characters are on one baseline.

There's the screenshot.

Please note that I took this screenshot without lineHeight style applied, so the expected behavior should render larger line spacing.

simulator screen shot - iphone 6 - 2018-05-09 at 10 41 42

Actual Behavior

Chinese characters on one baseline, while English and numbers on another.

There's the screenshot.

simulator screen shot - iphone 6 - 2018-05-09 at 10 41 32

And seems the problem only affects the iOS.

@evianzhow evianzhow changed the title Setting text contains combination of Chinese and English with lineHeight style cause those characters not on one baseline Setting text contains combination of Chinese and English with lineHeight style cause characters not on one baseline May 9, 2018
@evianzhow evianzhow changed the title Setting text contains combination of Chinese and English with lineHeight style cause characters not on one baseline Setting text contains combination of Chinese and English with lineHeight style cause characters not on same baseline May 9, 2018
@react-native-bot react-native-bot added Platform: iOS iOS applications. Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. labels May 11, 2018
@keech
Copy link

keech commented May 20, 2018

Any updates?

1 similar comment
@joseph2002
Copy link

Any updates?

@markymc
Copy link

markymc commented Jun 27, 2018

+1 I'm seeing this too on:

"react": "16.3.1",
"react-native": "~0.55.2",

e.g. (same styles except color):
screen shot 2018-06-27 at 15 01 31

@yusuke-nozoe
Copy link

+1 I'm seeing this too on:

 "react": "16.3.1",                                                                                                 
 "react-native": "0.55.4",  

@kgdev
Copy link

kgdev commented Jul 6, 2018

+1

@lynnic26
Copy link

lynnic26 commented Aug 28, 2018

Any updates?
---------------updates
I found a solution for this issue in iOS
set fontFamily: 'PingFang FC' in stylesheet will fix it
This issue may be caused by Chinese character and English are using different font family by default in iOS

@kaixiniOSTT
Copy link

kaixiniOSTT commented Sep 8, 2018

@lynnic26 thank you for your wonder solution . other detail as below:
苹方-简 常规体 : PingFangSC-Regular
苹方-简 极细体 :PingFangSC-Ultralight
苹方-简 细体 : PingFangSC-Light
苹方-简 纤细体 :PingFangSC-Thin
苹方-简 中黑体 :PingFangSC-Medium
苹方-简 中粗体 : PingFangSC-Semibold

grabbou pushed a commit that referenced this issue Oct 11, 2018
…nguage characters (#19653)

Summary:
This fixes #19193

Characters of different languages may have different height and different baseline, even with a same font and same font-size. When they mixed together, iOS will adjust their baselines automatically, to display a suitable view of text.

The problem is the behavior of dealing with the text-style property 'lineHeight'.

It once to be a right way at version 0.52.3, to setting a base-line-offset attribute for the whole range of the string. However, in current version, it enumerated the string, and set a different  base-line-offset for different font-height characters.

And this behavior broke the baseline adjustment made by the iOS. It just make every character's baseline aligned to a same line. But it is not supposed to displaying characters of different languages like that. Chinese characters' baseline is the bottom of each, however, it is not for English characters.

So maybe it is the better way to give a same value of base-line-offset attribute for the whole string. And this PR just did that: found the biggest value of font-height in the text, and calculate the offset with that biggest value, then set to the whole string. This will keep the origin baseline adjustment for different languages' chars made by iOS.

Since I always got an error when running the snapshot test locally, I can't even pass the them with the unmodified code in master branch.

The error is "Nesting of \<View\> within \<Text\> is not currently supported."

After I comment all of the check of that error from the source code, I got a different snapshot from the reference ones. It seems that all components which will cause that error are not rendered in the reference images.

Since this PR changed the behavior of 'lineHeight' property, it's better to add a new snapshot case for the situation of different-language-characters' mixture. So maybe somebody could help me with that or maybe it should be a issue?

[IOS] [BUGFIX] [Text] - fix the baseline issue when displaying a mixture of different-language characters
Pull Request resolved: #19653

Differential Revision: D10140131

Pulled By: shergin

fbshipit-source-id: 646a9c4046d497b78a980d82a015168cf940646b
@GuoZhiQiang
Copy link

Great job ! @kaixiniOSTT

@januslo
Copy link

januslo commented Feb 27, 2019

Any updates?
---------------updates
I found a solution for this issue in iOS
set fontFamily: 'PingFang FC' in stylesheet will fix it
This issue may be caused by Chinese character and English are using different font family by default in iOS

I found a hack for this workaround:
In App.js of my application:

constructor(props){
// ... super() and init state

if(Platform.OS == 'ios'){
            let oldRender = Text.render;
            Text.render = function (...args) {
                let origin = oldRender.call(this, ...args);
                return React.cloneElement(origin, {
                    style: [{fontFamily: 'PingFangSC-Regular'},origin.props.style]
                });
            };
        }
}

Replacing the render method of the Text make things works.

t-nanava pushed a commit to microsoft/react-native-macos that referenced this issue Jun 17, 2019
…nguage characters (facebook#19653)

Summary:
This fixes facebook#19193

Characters of different languages may have different height and different baseline, even with a same font and same font-size. When they mixed together, iOS will adjust their baselines automatically, to display a suitable view of text.

The problem is the behavior of dealing with the text-style property 'lineHeight'.

It once to be a right way at version 0.52.3, to setting a base-line-offset attribute for the whole range of the string. However, in current version, it enumerated the string, and set a different  base-line-offset for different font-height characters.

And this behavior broke the baseline adjustment made by the iOS. It just make every character's baseline aligned to a same line. But it is not supposed to displaying characters of different languages like that. Chinese characters' baseline is the bottom of each, however, it is not for English characters.

So maybe it is the better way to give a same value of base-line-offset attribute for the whole string. And this PR just did that: found the biggest value of font-height in the text, and calculate the offset with that biggest value, then set to the whole string. This will keep the origin baseline adjustment for different languages' chars made by iOS.

Since I always got an error when running the snapshot test locally, I can't even pass the them with the unmodified code in master branch.

The error is "Nesting of \<View\> within \<Text\> is not currently supported."

After I comment all of the check of that error from the source code, I got a different snapshot from the reference ones. It seems that all components which will cause that error are not rendered in the reference images.

Since this PR changed the behavior of 'lineHeight' property, it's better to add a new snapshot case for the situation of different-language-characters' mixture. So maybe somebody could help me with that or maybe it should be a issue?

[IOS] [BUGFIX] [Text] - fix the baseline issue when displaying a mixture of different-language characters
Pull Request resolved: facebook#19653

Differential Revision: D10140131

Pulled By: shergin

fbshipit-source-id: 646a9c4046d497b78a980d82a015168cf940646b
@Shangyunliang
Copy link

+1

@facebook facebook locked as resolved and limited conversation to collaborators Oct 2, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Oct 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet