From ed905027cd1290f558f3b10cedd28db1d08070d7 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Thu, 24 Oct 2019 19:53:05 -0700 Subject: [PATCH] Add support for Text.textBreakStrategy prop into RN Android for Fabric Summary: This diff extends the rendering on Text on Android to support textBreakStrategy prop. Changelog: Add support for Text.textBreakStrategy prop into RN Android for Fabric Reviewed By: JoshuaGross Differential Revision: D18101403 fbshipit-source-id: c7f0b1cdc0de05172f0978d4dd3493620dcd941a --- .../views/text/ReactTextViewManager.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java index d5fced0d4b0..15719809e79 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java @@ -12,6 +12,7 @@ import android.text.Layout; import android.text.Spannable; import androidx.annotation.Nullable; import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.bridge.ReadableNativeMap; import com.facebook.react.common.MapBuilder; import com.facebook.react.common.annotations.VisibleForTesting; import com.facebook.react.module.annotations.ReactModule; @@ -77,7 +78,9 @@ public class ReactTextViewManager public Object updateState( ReactTextView view, ReactStylesDiffMap props, @Nullable StateWrapper stateWrapper) { // TODO T55794595: Add support for updating state with null stateWrapper - ReadableMap attributedString = stateWrapper.getState().getMap("attributedString"); + ReadableNativeMap state = stateWrapper.getState(); + ReadableMap attributedString = state.getMap("attributedString"); + ReadableMap paragraphAttributes = state.getMap("paragraphAttributes"); Spannable spanned = TextLayoutManager.getOrCreateSpannableForText(view.getContext(), attributedString); @@ -85,8 +88,8 @@ public class ReactTextViewManager TextAttributeProps textViewProps = new TextAttributeProps(props); - // TODO add textBreakStrategy prop into local Data - int textBreakStrategy = Layout.BREAK_STRATEGY_HIGH_QUALITY; + int textBreakStrategy = + getTextBreakStrategy(paragraphAttributes.getString("textBreakStrategy")); // TODO add justificationMode prop into local Data int justificationMode = Layout.JUSTIFICATION_MODE_NONE; @@ -104,6 +107,24 @@ public class ReactTextViewManager justificationMode); } + private int getTextBreakStrategy(@Nullable String textBreakStrategy) { + int androidTextBreakStrategy = Layout.BREAK_STRATEGY_HIGH_QUALITY; + if (textBreakStrategy != null) { + switch (textBreakStrategy) { + case "simple": + androidTextBreakStrategy = Layout.BREAK_STRATEGY_SIMPLE; + break; + case "balanced": + androidTextBreakStrategy = Layout.BREAK_STRATEGY_BALANCED; + break; + default: + androidTextBreakStrategy = Layout.BREAK_STRATEGY_HIGH_QUALITY; + break; + } + } + return androidTextBreakStrategy; + } + @Override public @Nullable Map getExportedCustomDirectEventTypeConstants() { return MapBuilder.of(