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]

Reviewed By: NickGerleman

Differential Revision: D49114771

fbshipit-source-id: 171dfceef61d9851094465be8ff4eb9a87a3ab8f
  • Loading branch information
zeyap authored and facebook-github-bot committed Sep 14, 2023
1 parent 7dbb52a commit 88e19c0
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,140 @@
#include <react/renderer/debug/debugStringConvertibleUtils.h>
#include <react/utils/CoreFeatures.h>
#include <yoga/Yoga.h>
#include <unordered_set>

#include "conversions.h"

namespace facebook::react {

namespace {
inline RawProps filterYogaProps(const RawProps& rawProps) {
const static std::unordered_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)
: Props(context, sourceProps, rawProps),
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);

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

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

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

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

Expand Down
24 changes: 12 additions & 12 deletions packages/react-native/ReactCommon/react/renderer/core/Props.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ namespace facebook::react {
Props::Props(
const PropsParserContext& context,
const Props& sourceProps,
const RawProps& rawProps)
: nativeId(
CoreFeatures::enablePropIteratorSetter ? sourceProps.nativeId
: convertRawProp(
context,
rawProps,
"nativeID",
sourceProps.nativeId,
{}))
const RawProps& rawProps) {
initialize(context, sourceProps, rawProps);
}

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

void Props::setProp(
Expand Down
7 changes: 7 additions & 0 deletions packages/react-native/ReactCommon/react/renderer/core/Props.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ 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);
};

} // namespace facebook::react

0 comments on commit 88e19c0

Please sign in to comment.