Skip to content
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

fix(android): text with negative letterSpacing wraps at wrong position #2843

Merged
merged 2 commits into from
Jan 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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