mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
This commit is contained in:
committed by
Facebook Github Bot
parent
81d6357be1
commit
ed905027cd
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user