-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Add letterSpacing
style property for Text
#482
Conversation
Restarted the Travis build. @a2 / @nicklockwood - what do you think? |
👍 - I'd love to see this get merged |
@@ -105,6 +111,8 @@ - (NSAttributedString *)_attributedStringWithFontFamily:(NSString *)fontFamily | |||
[self _addAttribute:RCTReactTagAttributeName withValue:self.reactTag toAttributedString:attributedString]; | |||
[self _setParagraphStyleOnAttributedString:attributedString]; | |||
|
|||
[self _addAttribute:NSKernAttributeName withValue:@(letterSpacing) toAttributedString:attributedString]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a tiny nit, but I would move this to after the line that adds the NSFontAttributeName
attribute to maintain consistency but that's really the only thing I have against this. Looks good otherwise! 👍
06e01e6
to
d1451fe
Compare
@a2 thank you, fixed the nit |
Hey, can you make sure it actually follows the same behavior as CSS. Example, can you run this in React Native, take a screenshot and make sure it looks pixel perfect: If you want to try a different font: http://iosfonts.com/ |
It is super important that any feature which has the same name as CSS does actually work exactly the same as CSS, otherwise it makes debugging a lot hard and confuses developers. |
@vjeux here is what I get: The code: return (
<View style={{ flex: 1, backgroundColor: 'white' }}>
<View style={{ flex: 1, justifyContent: 'flex-end', alignItems: 'flex-start' }}>
<Text style={{ fontFamily: 'Copperplate', letterSpacing: 5, fontSize: 10 }}>
This is <Text style={{ letterSpacing: 0 }}>a text with a lot</Text> of spaces
</Text>
</View>
<View style={{ flex: 1, backgroundColor: 'blue' }}>
<WebView url="http://localhost:8082/" renderLoading={() => <View/>} renderError={() => <View/>}/>
</View>
</View>
);
} Html: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body style="padding: 0; margin: 0">
<span style="font-family: Copperplate; letter-spacing: 5px; font-size: 10px;">
This is <span style="letter-spacing:0">a text with a lot</span> of spaces
</span>
</body>
</html> |
Can you also check what's the behavior for negative spacing? Thanks a lot for making sure it's the same |
There is the last nasty problem: width calculation. One the web letter spacing affects width, both positive and negative. Negative letter spacing makes width less than required to display text, but it is not clipped according to this width (even with all kinds of |
Pushed a fix for this problem, now behaves exactly the same way |
@@ -32,6 +32,7 @@ var TextStylePropTypes = Object.assign(Object.create(ViewStylePropTypes), { | |||
writingDirection: ReactPropTypes.oneOf( | |||
['auto' /*default*/, 'ltr', 'rtl'] | |||
), | |||
letterSpacing: ReactPropTypes.number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can you add a trailing comma
Great work @vkurchatkin - looking forward to putting this to use! |
869bdb7
to
f3f0828
Compare
@vjeux all done |
Awesome work @vkurchatkin - I badly want to see this getting merged. |
@vjeux ping |
This looks good to me. Not sure what's holding it up. I'll check. |
+1 |
@nicklockwood any update? |
Sorry about the radio silence. There were a few issues merging - notably this broke the UIExplorer snapshot tests because the default letterSpacing value of 0 is not pixel-for-pixel identical to having no letterSpacing set at all (it disables iOS's per-character smart kerning). Anyway, that's fixed now, and I've merged this internally so it should be appearing on GitHub real soon. |
🌴 that's great, thanks! |
Summary: Fixes facebook#457 Closes facebook#482 Github Author: Vladimir Kurchatkin <vladimir.kurchatkin@gmail.com> Test Plan: Imported from GitHub, without a `Test Plan:` line.
* View Properties accessibilityRole/States Added documentation for accessibilityRole and accessibilityStates on View * Update view.md * Update view.md
Fixes #457