Skip to content

Commit

Permalink
filter yoga props 2/x - filter out yoga props at creation of YogaStyl…
Browse files Browse the repository at this point in the history
…ableProps (#39431)

Summary:
Pull Request resolved: #39431

Changelog: [Android][Breaking] - Do not enable `excludeYogaFromRawProps` feature flag, if you need to pass layout props to Java view managers when using new architecture
[Internal]

Differential Revision: D49114771

fbshipit-source-id: 8bec358040c9473c03615ccf8fb0fd07a1fab475
  • Loading branch information
zeyap authored and facebook-github-bot committed Sep 13, 2023
1 parent 78f757b commit 2f363c5
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,141 @@
#include <react/renderer/debug/debugStringConvertibleUtils.h>
#include <react/utils/CoreFeatures.h>
#include <yoga/Yoga.h>
#include <set>

#include "conversions.h"

namespace facebook::react {

namespace {
inline RawProps filterYogaProps(const RawProps& rawProps) {
const static std::set<std::string> yogaStylePropNames = {
{"direction",
"flexDirection",
"justifyContent",
"alignContent",
"alignItems",
"alignSelf",
"position",
"flexWrap",
"display",
"flex",
"flexGrow",
"flexShrink",
"flexBasis",
"margin",
"padding",
"rowGap",
"columnGap",
"gap",
// TODO: T163711275 also filter out width/height when SVG no longer read
// them from RawProps
"minWidth",
"maxWidth",
"minHeight",
"maxHeight",
"aspectRatio",

// edges
"left",
"right",
"top",
"bottom",
"start",
"end",

// variants of inset
"inset",
"insetStart",
"insetEnd",
"insetInline",
"insetInlineStart",
"insetInlineEnd",
"insetBlock",
"insetBlockEnd",
"insetBlockStart",
"insetVertical",
"insetHorizontal",
"insetTop",
"insetBottom",
"insetLeft",
"insetRight",

// variants of margin
"marginStart",
"marginEnd",
"marginInline",
"marginInlineStart",
"marginInlineEnd",
"marginBlock",
"marginBlockStart",
"marginBlockEnd",
"marginVertical",
"marginHorizontal",
"marginTop",
"marginBottom",
"marginLeft",
"marginRight",

// variants of padding
"paddingStart",
"paddingEnd",
"paddingInline",
"paddingInlineStart",
"paddingInlineEnd",
"paddingBlock",
"paddingBlockStart",
"paddingBlockEnd",
"paddingVertical",
"paddingHorizontal",
"paddingTop",
"paddingBottom",
"paddingLeft",
"paddingRight"}};

auto filteredRawProps = (folly::dynamic)rawProps;

auto it = filteredRawProps.items().begin();
while (it != filteredRawProps.items().end()) {
auto key = it->first.asString();
if (yogaStylePropNames.find(key) != yogaStylePropNames.end()) {
it = filteredRawProps.erase(it);
} else {
++it;
}
}

return RawProps(filteredRawProps);
}
} // namespace

YogaStylableProps::YogaStylableProps(
const PropsParserContext& context,
const YogaStylableProps& sourceProps,
const RawProps& rawProps,
bool shouldSetRawProps)
: Props(context, sourceProps, rawProps, shouldSetRawProps),
yogaStyle(
CoreFeatures::enablePropIteratorSetter
? sourceProps.yogaStyle
: convertRawProp(context, rawProps, sourceProps.yogaStyle)) {
if (!CoreFeatures::enablePropIteratorSetter) {
convertRawPropAliases(context, sourceProps, rawProps);
: Props() {
if (CoreFeatures::excludeYogaFromRawProps) {
const auto filteredRawProps = filterYogaProps(rawProps);
initialize(context, sourceProps, filteredRawProps, shouldSetRawProps);

yogaStyle = CoreFeatures::enablePropIteratorSetter
? sourceProps.yogaStyle
: convertRawProp(context, filteredRawProps, sourceProps.yogaStyle);

if (!CoreFeatures::enablePropIteratorSetter) {
convertRawPropAliases(context, sourceProps, filteredRawProps);
}
} else {
initialize(context, sourceProps, rawProps, shouldSetRawProps);

yogaStyle = CoreFeatures::enablePropIteratorSetter
? sourceProps.yogaStyle
: convertRawProp(context, rawProps, sourceProps.yogaStyle);

if (!CoreFeatures::enablePropIteratorSetter) {
convertRawPropAliases(context, sourceProps, rawProps);
}
}
};

Expand Down
28 changes: 14 additions & 14 deletions packages/react-native/ReactCommon/react/renderer/core/Props.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ Props::Props(
const PropsParserContext& context,
const Props& sourceProps,
const RawProps& rawProps,
const bool shouldSetRawProps)
: nativeId(
CoreFeatures::enablePropIteratorSetter ? sourceProps.nativeId
: convertRawProp(
context,
rawProps,
"nativeID",
sourceProps.nativeId,
{}))
const bool shouldSetRawProps) {
initialize(context, sourceProps, rawProps, shouldSetRawProps);
}

void Props::initialize(
const PropsParserContext& context,
const Props& sourceProps,
const RawProps& rawProps,
const bool shouldSetRawProps) {
nativeId = CoreFeatures::enablePropIteratorSetter
? sourceProps.nativeId
: convertRawProp(context, rawProps, "nativeID", sourceProps.nativeId, {});
#ifdef ANDROID
,
rawProps(
shouldSetRawProps ? (folly::dynamic)rawProps
: /* null */ folly::dynamic())
this->rawProps = shouldSetRawProps ? (folly::dynamic)rawProps
: /* null */ folly::dynamic();
#endif
{
}

void Props::setProp(
Expand Down
8 changes: 8 additions & 0 deletions packages/react-native/ReactCommon/react/renderer/core/Props.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ class Props : public virtual Sealable, public virtual DebugStringConvertible {
const Props* oldProps,
MapBufferBuilder& builder) const;
#endif

protected:
/** Initialize member variables of Props instance */
void initialize(
const PropsParserContext& context,
const Props& sourceProps,
const RawProps& rawProps,
bool shouldSetRawProps);
};

} // namespace facebook::react

0 comments on commit 2f363c5

Please sign in to comment.