Skip to content

Commit

Permalink
feat(iOS): line break mode prop iOS updates to consume new cpp functi…
Browse files Browse the repository at this point in the history
…ons (#46129)

Summary:
Solves this issue: #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](#45968) PR.

Pull Request resolved: #46129

Test Plan: - Tested builds in new and old architecture mode.

Reviewed By: andrewdacenko

Differential Revision: D61656969

Pulled By: cipolleschi

fbshipit-source-id: 4c6ed983ad15841ce52443bba13962d45c04e756
  • Loading branch information
shubhamguptadream11 authored and facebook-github-bot committed Aug 23, 2024
1 parent 6cab6c2 commit fe941a8
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ - (RCTShadowView *)shadowView
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -216,6 +219,7 @@ SharedDebugStringConvertibleList TextAttributes::getDebugProps() const {
debugStringConvertibleItem("alignment", alignment),
debugStringConvertibleItem("baseWritingDirection", baseWritingDirection),
debugStringConvertibleItem("lineBreakStrategyIOS", lineBreakStrategy),
debugStringConvertibleItem("lineBreakModeIOS", lineBreakMode),

// Decoration
debugStringConvertibleItem("textDecorationColor", textDecorationColor),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit fe941a8

Please sign in to comment.