Skip to content

Commit

Permalink
fix(android): text with negative letterSpacing wraps at wrong position
Browse files Browse the repository at this point in the history
  • Loading branch information
iPel committed Jan 6, 2023
1 parent f29c4ae commit caacdf0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -749,24 +749,24 @@ protected Layout createLayout(float width, FlexMeasureMode widthMode) {
} catch (Throwable e) {
LogUtils.d("TextNode", "createLayout: " + e.getMessage());
}
float desiredWidth = boring == null ? Layout.getDesiredWidth(text, textPaint) : Float.NaN;

boolean unconstrainedWidth = widthMode == FlexMeasureMode.UNDEFINED || width < 0;
if (boring == null && (unconstrainedWidth || (!FlexConstants.isUndefined(desiredWidth)
&& desiredWidth <= width))) {
layout = buildStaticLayout(text, textPaint, (int)Math.ceil(desiredWidth));
} else if (boring != null && (unconstrainedWidth || boring.width <= width)) {
if (boring != null && (unconstrainedWidth || boring.width <= width)) {
layout = BoringLayout.make(text, textPaint, boring.width, mTextAlign, getLineSpacingMultiplier(), mLineSpacingExtra, boring, true);
} else {
layout = buildStaticLayout(text, textPaint, (int)Math.ceil(width));
}
if (mNumberOfLines != UNSET && mNumberOfLines > 0) {
if (layout.getLineCount() > mNumberOfLines) {
int lastLineStart = layout.getLineStart(mNumberOfLines - 1);
int lastLineEnd = layout.getLineEnd(mNumberOfLines - 1);
if (lastLineStart < lastLineEnd) {
int measureWidth = (int)Math.ceil(unconstrainedWidth ? desiredWidth : width);
layout = truncateLayoutWithNumberOfLine(layout, measureWidth, mNumberOfLines);
float desiredWidth = Layout.getDesiredWidth(text, textPaint);
if (!unconstrainedWidth && (widthMode == FlexMeasureMode.EXACTLY || desiredWidth > width)) {
desiredWidth = width;
}
layout = buildStaticLayout(text, textPaint, (int) Math.ceil(desiredWidth));
if (mNumberOfLines != UNSET && mNumberOfLines > 0) {
if (layout.getLineCount() > mNumberOfLines) {
int lastLineStart = layout.getLineStart(mNumberOfLines - 1);
int lastLineEnd = layout.getLineEnd(mNumberOfLines - 1);
if (lastLineStart < lastLineEnd) {
int measureWidth = (int)Math.ceil(unconstrainedWidth ? desiredWidth : width);
layout = truncateLayoutWithNumberOfLine(layout, measureWidth, mNumberOfLines);
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions docs/en-us/style/appearance.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ The horizontal spacing behavior between text characters

!> hippy-vue should use @hippy/vue-css-loader `2.14.1` or above version

!> On some Android devices, setting a negative value for letterSpacing has compatibility issues, which may cause line breaks at unexpected positions

| Type | Required | Supported Platforms
| ------ | -------- | --- |
| number | No | Android、iOS
Expand Down
2 changes: 2 additions & 0 deletions docs/style/appearance.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@

!> hippy-vue 需采用 @hippy/vue-css-loader `2.14.1` 以上版本

!> 在部分 Android 设备上,letterSpacing 设置负值有兼容性问题,可能会导致在非预期的位置换行

| 类型 | 必需 | 支持平台
| ------ | -------- | --- |
| number | 否 | Android、iOS
Expand Down

0 comments on commit caacdf0

Please sign in to comment.