diff --git a/packages/react-native/Libraries/Text/BaseText/RCTBaseTextViewManager.mm b/packages/react-native/Libraries/Text/BaseText/RCTBaseTextViewManager.mm index ece68768c40..e9ce272b5f5 100644 --- a/packages/react-native/Libraries/Text/BaseText/RCTBaseTextViewManager.mm +++ b/packages/react-native/Libraries/Text/BaseText/RCTBaseTextViewManager.mm @@ -44,6 +44,7 @@ RCT_REMAP_SHADOW_PROPERTY(lineHeight, textAttributes.lineHeight, CGFloat) RCT_REMAP_SHADOW_PROPERTY(textAlign, textAttributes.alignment, NSTextAlignment) RCT_REMAP_SHADOW_PROPERTY(writingDirection, textAttributes.baseWritingDirection, NSWritingDirection) RCT_REMAP_SHADOW_PROPERTY(lineBreakStrategyIOS, textAttributes.lineBreakStrategy, NSLineBreakStrategy) +RCT_REMAP_SHADOW_PROPERTY(lineBreakModeIOS, textAttributes.lineBreakMode, NSLineBreakMode) // Decoration RCT_REMAP_SHADOW_PROPERTY(textDecorationColor, textAttributes.textDecorationColor, UIColor) RCT_REMAP_SHADOW_PROPERTY(textDecorationStyle, textAttributes.textDecorationStyle, NSUnderlineStyle) diff --git a/packages/react-native/ReactCommon/react/renderer/attributedstring/TextAttributes.cpp b/packages/react-native/ReactCommon/react/renderer/attributedstring/TextAttributes.cpp index cd32048480f..9b06f12948a 100644 --- a/packages/react-native/ReactCommon/react/renderer/attributedstring/TextAttributes.cpp +++ b/packages/react-native/ReactCommon/react/renderer/attributedstring/TextAttributes.cpp @@ -68,6 +68,9 @@ void TextAttributes::apply(TextAttributes textAttributes) { lineBreakStrategy = textAttributes.lineBreakStrategy.has_value() ? textAttributes.lineBreakStrategy : lineBreakStrategy; + lineBreakMode = textAttributes.lineBreakMode.has_value() + ? textAttributes.lineBreakMode + : lineBreakMode; // Decoration textDecorationColor = textAttributes.textDecorationColor @@ -216,6 +219,7 @@ SharedDebugStringConvertibleList TextAttributes::getDebugProps() const { debugStringConvertibleItem("alignment", alignment), debugStringConvertibleItem("baseWritingDirection", baseWritingDirection), debugStringConvertibleItem("lineBreakStrategyIOS", lineBreakStrategy), + debugStringConvertibleItem("lineBreakModeIOS", lineBreakMode), // Decoration debugStringConvertibleItem("textDecorationColor", textDecorationColor), diff --git a/packages/react-native/ReactCommon/react/renderer/attributedstring/conversions.h b/packages/react-native/ReactCommon/react/renderer/attributedstring/conversions.h index d2a40f49765..8e365c52523 100644 --- a/packages/react-native/ReactCommon/react/renderer/attributedstring/conversions.h +++ b/packages/react-native/ReactCommon/react/renderer/attributedstring/conversions.h @@ -589,6 +589,60 @@ inline std::string toString(const LineBreakStrategy& lineBreakStrategy) { return "none"; } +inline void fromRawValue( + const PropsParserContext& /*context*/, + const RawValue& value, + LineBreakMode& result) { + react_native_expect(value.hasType()); + if (value.hasType()) { + auto string = (std::string)value; + if (string == "wordWrapping") { + result = LineBreakMode::Word; + } else if (string == "char") { + result = LineBreakMode::Char; + } else if (string == "clip") { + result = LineBreakMode::Clip; + } else if (string == "head") { + result = LineBreakMode::Head; + } else if (string == "middle") { + result = LineBreakMode::Middle; + } else if (string == "tail") { + result = LineBreakMode::Tail; + } else { + LOG(ERROR) << "Unsupported LineBreakStrategy value: " << string; + react_native_expect(false); + // sane default for prod + result = LineBreakMode::Word; + } + return; + } + + LOG(ERROR) << "Unsupported LineBreakStrategy type"; + // sane default for prod + result = LineBreakMode::Word; +} + +inline std::string toString(const LineBreakMode& lineBreakMode) { + switch (lineBreakMode) { + case LineBreakMode::Word: + return "wordWrapping"; + case LineBreakMode::Char: + return "char"; + case LineBreakMode::Clip: + return "clip"; + case LineBreakMode::Head: + return "head"; + case LineBreakMode::Middle: + return "middle"; + case LineBreakMode::Tail: + return "tail"; + } + + LOG(ERROR) << "Unsupported LineBreakStrategy value"; + // sane default for prod + return "wordWrapping"; +} + inline void fromRawValue( const PropsParserContext& context, const RawValue& value, diff --git a/packages/react-native/ReactCommon/react/renderer/components/text/BaseTextProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/text/BaseTextProps.cpp index 2dfe49020d2..e5fd9513461 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/text/BaseTextProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/text/BaseTextProps.cpp @@ -123,6 +123,12 @@ static TextAttributes convertRawProp( "lineBreakStrategyIOS", sourceTextAttributes.lineBreakStrategy, defaultTextAttributes.lineBreakStrategy); + textAttributes.lineBreakMode = convertRawProp( + context, + rawProps, + "lineBreakModeIOS", + sourceTextAttributes.lineBreakMode, + defaultTextAttributes.lineBreakMode); // Decoration textAttributes.textDecorationColor = convertRawProp( @@ -286,6 +292,8 @@ void BaseTextProps::setProp( textAttributes, lineBreakStrategy, "lineBreakStrategyIOS"); + REBUILD_FIELD_SWITCH_CASE( + defaults, value, textAttributes, lineBreakMode, "lineBreakModeIOS"); REBUILD_FIELD_SWITCH_CASE( defaults, value,