-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
Comments
lineHeight
style cause those characters not on one baselinelineHeight
style cause characters not on one baseline
lineHeight
style cause characters not on one baselinelineHeight
style cause characters not on same baseline
Any updates? |
1 similar comment
Any updates? |
+1 I'm seeing this too on:
|
+1 |
Any updates? |
@lynnic26 thank you for your wonder solution . other detail as below: |
…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
Great job ! @kaixiniOSTT |
I found a hack for this workaround: 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. |
…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
+1 |
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
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.Actual Behavior
Chinese characters on one baseline, while English and numbers on another.
There's the screenshot.
And seems the problem only affects the iOS.
The text was updated successfully, but these errors were encountered: