Skip to content

Add letterSpacing style property for Text - #482

Closed
vkurchatkin wants to merge 1 commit into
react:masterfrom
vkurchatkin:text-letter-spacing
Closed

Add letterSpacing style property for Text#482
vkurchatkin wants to merge 1 commit into
react:masterfrom
vkurchatkin:text-letter-spacing

Conversation

@vkurchatkin

Copy link
Copy Markdown
Contributor

Fixes#457

@frantic

Copy link
Copy Markdown
Contributor

Restarted the Travis build. @a2 / @nicklockwood - what do you think?

@brentvatne

Copy link
Copy Markdown
Collaborator

👍 - I'd love to see this get merged

Comment threadLibraries/Text/RCTShadowText.m Outdated

Copy link
Copy Markdown
Contributor

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! 👍

@franticfrantic mentioned this pull request Mar 30, 2015
@vkurchatkin
vkurchatkinforce-pushed the text-letter-spacing branch 2 times, most recently from 06e01e6 to d1451feCompareMarch 30, 2015 21:54
@vkurchatkin

Copy link
Copy Markdown
ContributorAuthor

@a2 thank you, fixed the nit

@vjeux

Copy link
Copy Markdown
Contributor

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:
http://jsfiddle.net/y7h9j3uw/

If you want to try a different font: http://iosfonts.com/

@vjeux

Copy link
Copy Markdown
Contributor

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.

@vkurchatkin

Copy link
Copy Markdown
ContributorAuthor

@vjeux here is what I get:

screenshot

The code:

return(<Viewstyle={{flex: 1,backgroundColor: 'white'}}><Viewstyle={{flex: 1,justifyContent: 'flex-end',alignItems: 'flex-start'}}><Textstyle={{fontFamily: 'Copperplate',letterSpacing: 5,fontSize: 10}}>
This is <Textstyle={{letterSpacing: 0}}>a text with a lot</Text> of spaces
</Text></View><Viewstyle={{flex: 1,backgroundColor: 'blue'}}><WebViewurl="http://localhost:8082/"renderLoading={()=><View/>}renderError={()=><View/>}/></View></View>);}

Html:

<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><title></title></head><bodystyle="padding: 0; margin: 0"><spanstyle="font-family: Copperplate; letter-spacing: 5px; font-size: 10px;">
This is <spanstyle="letter-spacing:0">a text with a lot</span> of spaces
</span></body></html>

@vjeux

Copy link
Copy Markdown
Contributor

Can you also check what's the behavior for negative spacing? Thanks a lot for making sure it's the same

@vkurchatkin

Copy link
Copy Markdown
ContributorAuthor

For -3px I get the following:

screenshot

Pretty close

@vkurchatkin

Copy link
Copy Markdown
ContributorAuthor

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 overflow and text-overflow properties). On iOS, on the contrary, it is clipped.

@vkurchatkin

Copy link
Copy Markdown
ContributorAuthor

Pushed a fix for this problem, now behaves exactly the same way

Comment threadLibraries/Text/TextStylePropTypes.js Outdated

Copy link
Copy Markdown
Contributor

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

@brentvatne

Copy link
Copy Markdown
Collaborator

Great work @vkurchatkin - looking forward to putting this to use!

@vkurchatkin

Copy link
Copy Markdown
ContributorAuthor

@vjeux all done

@chirag04

Copy link
Copy Markdown
Contributor

Awesome work @vkurchatkin - I badly want to see this getting merged.

@facebook-github-botfacebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 7, 2015
@vkurchatkin

Copy link
Copy Markdown
ContributorAuthor

@vjeux ping

@nicklockwood

Copy link
Copy Markdown
Contributor

This looks good to me. Not sure what's holding it up. I'll check.

@ide

ide commented May 8, 2015

Copy link
Copy Markdown
Contributor

+1

@brentvatne

Copy link
Copy Markdown
Collaborator

@nicklockwood any update?

@nicklockwood

Copy link
Copy Markdown
Contributor

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.

@brentvatne

Copy link
Copy Markdown
Collaborator

🌴 that's great, thanks!

vjeux pushed a commit to vjeux/react-native that referenced this pull request May 13, 2015
Summary:
Fixesreact#457Closesreact#482
Github Author: Vladimir Kurchatkin <vladimir.kurchatkin@gmail.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
@vjeuxvjeux closed this in a142ed5May 13, 2015
jfrolich pushed a commit to jfrolich/react-native that referenced this pull request Apr 22, 2020
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Letter spacing CSS property

9 participants

@vkurchatkin@frantic@brentvatne@vjeux@chirag04@nicklockwood@ide@a2@facebook-github-bot