Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 25.2k
Fix android letter spacing#9420
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -18,6 +18,7 @@ | ||
| import android.widget.TextView; | ||
| import com.facebook.csslayout.FloatUtil; | ||
| import com.facebook.react.uimanager.PixelUtil; | ||
| import com.facebook.react.uimanager.ReactCompoundView; | ||
| public class ReactTextView extends TextView implements ReactCompoundView { | ||
| @@ -30,6 +31,7 @@ public class ReactTextView extends TextView implements ReactCompoundView { | ||
| private int mDefaultGravityVertical; | ||
| private boolean mTextIsSelectable; | ||
| private float mLineHeight = Float.NaN; | ||
| private float mLetterSpacing = Float.NaN; | ||
| private int mTextAlign = Gravity.NO_GRAVITY; | ||
| public ReactTextView(Context context) { | ||
| @@ -54,6 +56,19 @@ public void setText(ReactTextUpdate update) { | ||
| (int) Math.ceil(update.getPaddingRight()), | ||
| (int) Math.ceil(update.getPaddingBottom())); | ||
| float nextLetterSpacing = update.getLetterSpacing(); | ||
| int fontSize = update.getFontSize(); | ||
| if (!FloatUtil.floatsEqual(mLetterSpacing, nextLetterSpacing)) { | ||
| mLetterSpacing = nextLetterSpacing; | ||
| if(Float.isNaN(mLetterSpacing)) { | ||
| setLetterSpacing((float)0.0); | ||
| } else { | ||
| //calculate EM from proper font pixels | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: space after | ||
| setLetterSpacing(1+(mLetterSpacing-PixelUtil.toDIPFromPixel(fontSize))/PixelUtil.toDIPFromPixel(fontSize)); | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where does this formula come from - e.g. Android docs? | ||
| } | ||
| } | ||
| float nextLineHeight = update.getLineHeight(); | ||
| if (!FloatUtil.floatsEqual(mLineHeight, nextLineHeight)) { | ||
| mLineHeight = nextLineHeight; | ||
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: space after
if