Skip to content

Commit

Permalink
Support iterator-style prop parsing in ParagraphProps
Browse files Browse the repository at this point in the history
Summary:
Support iterator-style prop parsing in ParagraphProps

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D38833627

fbshipit-source-id: 31eac4e86c5855bb47f634da7cffaf2418273a36
  • Loading branch information
rshest authored and facebook-github-bot committed Oct 2, 2022
1 parent 7de2b6b commit 4766755
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 22 deletions.
97 changes: 80 additions & 17 deletions ReactCommon/react/renderer/components/text/ParagraphProps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,29 @@ ParagraphProps::ParagraphProps(
RawProps const &rawProps)
: ViewProps(context, sourceProps, rawProps),
BaseTextProps(context, sourceProps, rawProps),
paragraphAttributes(convertRawProp(
context,
rawProps,
sourceProps.paragraphAttributes,
{})),
isSelectable(convertRawProp(
context,
rawProps,
"selectable",
sourceProps.isSelectable,
false)),
onTextLayout(convertRawProp(
context,
rawProps,
"onTextLayout",
sourceProps.onTextLayout,
{})) {
paragraphAttributes(
Props::enablePropIteratorSetter ? sourceProps.paragraphAttributes
: convertRawProp(
context,
rawProps,
sourceProps.paragraphAttributes,
{})),
isSelectable(
Props::enablePropIteratorSetter ? sourceProps.isSelectable
: convertRawProp(
context,
rawProps,
"selectable",
sourceProps.isSelectable,
false)),
onTextLayout(
Props::enablePropIteratorSetter ? sourceProps.onTextLayout
: convertRawProp(
context,
rawProps,
"onTextLayout",
sourceProps.onTextLayout,
{})) {
/*
* These props are applied to `View`, therefore they must not be a part of
* base text attributes.
Expand All @@ -59,6 +65,63 @@ void ParagraphProps::setProp(
ViewProps::setProp(context, hash, propName, value);
BaseTextProps::setProp(context, hash, propName, value);

// ParagraphAttributes has its own switch statement - to keep all
// of these fields together, and because there are some collisions between
// propnames parsed here and outside of ParagraphAttributes.
// This code is also duplicated in AndroidTextInput.
static auto paDefaults = ParagraphAttributes{};
switch (hash) {
REBUILD_FIELD_SWITCH_CASE(
paDefaults,
value,
paragraphAttributes,
maximumNumberOfLines,
"numberOfLines");
REBUILD_FIELD_SWITCH_CASE(
paDefaults, value, paragraphAttributes, ellipsizeMode, "ellipsizeMode");
REBUILD_FIELD_SWITCH_CASE(
paDefaults,
value,
paragraphAttributes,
textBreakStrategy,
"textBreakStrategy");
REBUILD_FIELD_SWITCH_CASE(
paDefaults,
value,
paragraphAttributes,
adjustsFontSizeToFit,
"adjustsFontSizeToFit");
REBUILD_FIELD_SWITCH_CASE(
paDefaults,
value,
paragraphAttributes,
minimumFontSize,
"minimumFontSize");
REBUILD_FIELD_SWITCH_CASE(
paDefaults,
value,
paragraphAttributes,
maximumFontSize,
"maximumFontSize");
REBUILD_FIELD_SWITCH_CASE(
paDefaults,
value,
paragraphAttributes,
includeFontPadding,
"includeFontPadding");
REBUILD_FIELD_SWITCH_CASE(
paDefaults,
value,
paragraphAttributes,
android_hyphenationFrequency,
"android_hyphenationFrequency");
}

switch (hash) {
RAW_SET_PROP_SWITCH_CASE_BASIC(isSelectable, false);
RAW_SET_PROP_SWITCH_CASE_BASIC(onTextLayout, {});
}

/*
* These props are applied to `View`, therefore they must not be a part of
* base text attributes.
Expand Down
6 changes: 3 additions & 3 deletions ReactCommon/react/renderer/components/text/ParagraphProps.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ class ParagraphProps : public ViewProps, public BaseTextProps {
* Contains all prop values that affect visual representation of the
* paragraph.
*/
ParagraphAttributes const paragraphAttributes{};
ParagraphAttributes paragraphAttributes{};

/*
* Defines can the text be selected (and copied) or not.
*/
bool const isSelectable{};
bool isSelectable{};

bool const onTextLayout{};
bool onTextLayout{};

#pragma mark - DebugStringConvertible

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,12 @@ void AndroidTextInputProps::setProp(
ViewProps::setProp(context, hash, propName, value);
BaseTextProps::setProp(context, hash, propName, value);

static auto paDefaults = ParagraphAttributes{};

// ParagraphAttributes has its own switch statement - to keep all
// of these fields together, and because there are some collisions between
// propnames parsed here and outside of ParagraphAttributes. For example,
// textBreakStrategy is duplicated.
// This code is also duplicated in ParagraphProps.
static auto paDefaults = ParagraphAttributes{};
switch (hash) {
REBUILD_FIELD_SWITCH_CASE(
paDefaults,
Expand Down

0 comments on commit 4766755

Please sign in to comment.