mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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](https://github.com/facebook/react-native/issues/25275#issuecomment-502548807). - related (maybe) - https://github.com/facebook/react-native/issues/25297 - https://github.com/facebook/react-native/issues/25275 - https://github.com/facebook/react-native/issues/24837 - https://github.com/facebook/react-native/issues/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: https://github.com/facebook/react-native/pull/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
This commit is contained in:
@@ -115,6 +115,9 @@ public class ReactTextShadowNode extends ReactBaseTextShadowNode {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
builder.setJustificationMode(mJustificationMode);
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
builder.setUseLineSpacingFromFallbacks(true);
|
||||
}
|
||||
layout = builder.build();
|
||||
}
|
||||
|
||||
@@ -139,14 +142,18 @@ public class ReactTextShadowNode extends ReactBaseTextShadowNode {
|
||||
new StaticLayout(
|
||||
text, textPaint, (int) width, alignment, 1.f, 0.f, mIncludeFontPadding);
|
||||
} else {
|
||||
layout =
|
||||
StaticLayout.Builder builder =
|
||||
StaticLayout.Builder.obtain(text, 0, text.length(), textPaint, (int) width)
|
||||
.setAlignment(alignment)
|
||||
.setLineSpacing(0.f, 1.f)
|
||||
.setIncludePad(mIncludeFontPadding)
|
||||
.setBreakStrategy(mTextBreakStrategy)
|
||||
.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL)
|
||||
.build();
|
||||
.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
builder.setUseLineSpacingFromFallbacks(true);
|
||||
}
|
||||
layout = builder.build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user