forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Setting the line height with the help of Android-provided StaticLayout is incorrect. A simple example app will display the following when `setLineSpacing(50.f, 0.f)` is set: {F62987699}. You'll notice that the height of the first line is a few pixels shorter than the other lines. So we use a custom LineHeightSpan instead, which needs to be applied to the text itself, and no height-related attributes need to be set on the TextView itself. Reviewed By: lexs Differential Revision: D3751097 fbshipit-source-id: c3574a1080efec26436a5c61afbff89afa8679e7
- Loading branch information
1 parent
e7521a1
commit 483953d
Showing
5 changed files
with
42 additions
and
35 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
ReactAndroid/src/main/java/com/facebook/react/views/text/CustomLineHeightSpan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
package com.facebook.react.views.text; | ||
|
||
import android.graphics.Paint; | ||
import android.text.style.LineHeightSpan; | ||
|
||
/** | ||
* We use a custom {@link LineHeightSpan}, because `lineSpacingExtra` is broken. Details here: | ||
* https://github.com/facebook/react-native/issues/7546 | ||
*/ | ||
public class CustomLineHeightSpan implements LineHeightSpan { | ||
private final float mHeight; | ||
|
||
CustomLineHeightSpan(float height) { | ||
this.mHeight = height; | ||
} | ||
|
||
@Override | ||
public void chooseHeight( | ||
CharSequence text, | ||
int start, | ||
int end, | ||
int spanstartv, | ||
int v, | ||
Paint.FontMetricsInt fm) { | ||
fm.ascent = fm.top = 0; | ||
fm.descent = fm.bottom = (int) Math.ceil(mHeight); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters