Skip to content

Commit 76c50c1

Browse files
soh335facebook-github-bot
authored andcommitted
Fix some languages wrapped texts are cut off on android (#25306)
Summary: Fix wrapped some languages (like Japanese, Chinese) texts are cut off on android. This p-r is based on linjson [patch](#25275 (comment)). - related (maybe) - #25297 - #25275 - #24837 - #25155 `setUseLineSpacingFromFallbacks` is recommended to set true on [document](https://developer.android.com/reference/android/text/StaticLayout.Builder#setUseLineSpacingFromFallbacks(boolean)) >For backward compatibility reasons, the default is false, but setting this to true is strongly recommended. It is required to be true if text could be in languages like Burmese or Tibetan where text is typically much taller or deeper than Latin text. ## Changelog [Android] [Fixed] - Fix some languages wrapped texts are cut off. Pull Request resolved: #25306 Test Plan: Set the target SDK to 28 in ``fbsource/fbandroid/java/com/facebook/catalyst/shell/AndroidManifest.xml``: ``` <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="28"/> ``` Insert the following code into Playground.js: P67720709 Start the Catalyst Android app and navigate to the playground: `buck install -r catalyst` |Before|After| |{F163482789}|{F163481060}| Reviewed By: cpojer Differential Revision: D15985809 Pulled By: makovkastar fbshipit-source-id: 0f98760b7a7fe4689fa3fe90ca747e9bf9fc4780
1 parent 454bbff commit 76c50c1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ public long measure(
115115
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
116116
builder.setJustificationMode(mJustificationMode);
117117
}
118+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
119+
builder.setUseLineSpacingFromFallbacks(true);
120+
}
118121
layout = builder.build();
119122
}
120123

@@ -139,14 +142,18 @@ public long measure(
139142
new StaticLayout(
140143
text, textPaint, (int) width, alignment, 1.f, 0.f, mIncludeFontPadding);
141144
} else {
142-
layout =
145+
StaticLayout.Builder builder =
143146
StaticLayout.Builder.obtain(text, 0, text.length(), textPaint, (int) width)
144147
.setAlignment(alignment)
145148
.setLineSpacing(0.f, 1.f)
146149
.setIncludePad(mIncludeFontPadding)
147150
.setBreakStrategy(mTextBreakStrategy)
148-
.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL)
149-
.build();
151+
.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL);
152+
153+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
154+
builder.setUseLineSpacingFromFallbacks(true);
155+
}
156+
layout = builder.build();
150157
}
151158
}
152159

0 commit comments

Comments
 (0)