mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
feat(iOS): line break mode prop iOS updates to consume new cpp functions (#46129)
Summary: Solves this issue: https://github.com/facebook/react-native/issues/44107 ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [IOS] [ADDED] - Line break mode for TextInput components. **This includes iOS updates to consume new cpp functions.** This PR is a breakdown of [this](https://github.com/facebook/react-native/pull/45968) PR. Pull Request resolved: https://github.com/facebook/react-native/pull/46129 Test Plan: - Tested builds in new and old architecture mode. Reviewed By: andrewdacenko Differential Revision: D61656969 Pulled By: cipolleschi fbshipit-source-id: 4c6ed983ad15841ce52443bba13962d45c04e756
This commit is contained in:
committed by
Facebook GitHub Bot
parent
6cab6c2a13
commit
fe941a8f4c
@@ -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)
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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<std::string>());
|
||||
if (value.hasType<std::string>()) {
|
||||
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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user