From 9837d2480c2d5d279e18ee9be2daa7ae20006dbb Mon Sep 17 00:00:00 2001 From: soh335 Date: Thu, 27 Jun 2019 02:27:05 -0700 Subject: [PATCH] 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``: ``` ``` 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 --- .../react/views/text/ReactTextShadowNode.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java index 16af513a29e..fd181c1c96e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java @@ -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(); } }