diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.cpp index 66f0b545c1a..493ba9217e9 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.cpp @@ -53,8 +53,9 @@ std::array getTranslateForTransformOrigin( BaseViewProps::BaseViewProps( const PropsParserContext& context, const BaseViewProps& sourceProps, - const RawProps& rawProps) - : YogaStylableProps(context, sourceProps, rawProps), + const RawProps& rawProps, + const std::function& filterObjectKeys) + : YogaStylableProps(context, sourceProps, rawProps, filterObjectKeys), AccessibilityProps(context, sourceProps, rawProps), opacity( ReactNativeFeatureFlags::enableCppPropsIteratorSetter() diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.h b/packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.h index f33bcf265ee..c750832b143 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.h @@ -31,7 +31,9 @@ class BaseViewProps : public YogaStylableProps, public AccessibilityProps { BaseViewProps( const PropsParserContext& context, const BaseViewProps& sourceProps, - const RawProps& rawProps); + const RawProps& rawProps, + const std::function& filterObjectKeys = + nullptr); void setProp( const PropsParserContext& context, diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp index 9277715e8e4..28c4cdaa276 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp @@ -18,9 +18,10 @@ namespace facebook::react { YogaStylableProps::YogaStylableProps( const PropsParserContext& context, const YogaStylableProps& sourceProps, - const RawProps& rawProps) + const RawProps& rawProps, + const std::function& filterObjectKeys) : Props() { - initialize(context, sourceProps, rawProps); + initialize(context, sourceProps, rawProps, filterObjectKeys); yogaStyle.setDirection(convertRawProp( context, diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.h b/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.h index ef120f4f432..1f7dfa908a9 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.h @@ -21,7 +21,9 @@ class YogaStylableProps : public Props { YogaStylableProps( const PropsParserContext& context, const YogaStylableProps& sourceProps, - const RawProps& rawProps); + const RawProps& rawProps, + const std::function& filterObjectKeys = + nullptr); void setProp( const PropsParserContext& context, diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.cpp index 737a09a1eca..dfbae60abd7 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.cpp @@ -20,8 +20,9 @@ namespace facebook::react { HostPlatformViewProps::HostPlatformViewProps( const PropsParserContext& context, const HostPlatformViewProps& sourceProps, - const RawProps& rawProps) - : BaseViewProps(context, sourceProps, rawProps), + const RawProps& rawProps, + const std::function& filterObjectKeys) + : BaseViewProps(context, sourceProps, rawProps, filterObjectKeys), elevation( ReactNativeFeatureFlags::enableCppPropsIteratorSetter() ? sourceProps.elevation diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.h b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.h index 89325ab7083..25a6cd30529 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.h @@ -26,7 +26,9 @@ class HostPlatformViewProps : public BaseViewProps { HostPlatformViewProps( const PropsParserContext& context, const HostPlatformViewProps& sourceProps, - const RawProps& rawProps); + const RawProps& rawProps, + const std::function& filterObjectKeys = + nullptr); void setProp( const PropsParserContext& context, diff --git a/packages/react-native/ReactCommon/react/renderer/core/Props.cpp b/packages/react-native/ReactCommon/react/renderer/core/Props.cpp index 2e494ba7d2f..811febf1177 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/Props.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/Props.cpp @@ -17,19 +17,22 @@ namespace facebook::react { Props::Props( const PropsParserContext& context, const Props& sourceProps, - const RawProps& rawProps) { - initialize(context, sourceProps, rawProps); + const RawProps& rawProps, + const std::function& filterObjectKeys) { + initialize(context, sourceProps, rawProps, filterObjectKeys); } void Props::initialize( const PropsParserContext& context, const Props& sourceProps, - const RawProps& rawProps) { + const RawProps& rawProps, + [[maybe_unused]] const std::function& + filterObjectKeys) { nativeId = ReactNativeFeatureFlags::enableCppPropsIteratorSetter() ? sourceProps.nativeId : convertRawProp(context, rawProps, "nativeID", sourceProps.nativeId, {}); #ifdef ANDROID - this->rawProps = (folly::dynamic)rawProps; + this->rawProps = rawProps.toDynamic(filterObjectKeys); #endif } diff --git a/packages/react-native/ReactCommon/react/renderer/core/Props.h b/packages/react-native/ReactCommon/react/renderer/core/Props.h index 144cc8a039d..0270121a953 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/Props.h +++ b/packages/react-native/ReactCommon/react/renderer/core/Props.h @@ -33,7 +33,9 @@ class Props : public virtual Sealable, public virtual DebugStringConvertible { Props( const PropsParserContext& context, const Props& sourceProps, - const RawProps& rawProps); + const RawProps& rawProps, + const std::function& filterObjectKeys = + nullptr); virtual ~Props() = default; Props(const Props& other) = delete; @@ -71,7 +73,13 @@ class Props : public virtual Sealable, public virtual DebugStringConvertible { void initialize( const PropsParserContext& context, const Props& sourceProps, - const RawProps& rawProps); + const RawProps& rawProps, + /** + * Filter object keys to be excluded when converting the RawProps to + * folly::dynamic (android only) + */ + const std::function& filterObjectKeys = + nullptr); }; } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/core/RawProps.cpp b/packages/react-native/ReactCommon/react/renderer/core/RawProps.cpp index 06226c5267e..8026dad0e18 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/RawProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/RawProps.cpp @@ -172,13 +172,38 @@ void RawProps::parse(const RawPropsParser& parser) noexcept { * The support for explicit conversion to `folly::dynamic` is deprecated and * will be removed as soon Android implementation does not need it. */ -RawProps::operator folly::dynamic() const noexcept { +RawProps::operator folly::dynamic() const { + return toDynamic(); +} + +/* + * Deprecated. Do not use. + * The support for explicit conversion to `folly::dynamic` is deprecated and + * will be removed as soon Android implementation does not need it. + */ +folly::dynamic RawProps::toDynamic( + const std::function& filterObjectKeys) const { switch (mode_) { case Mode::Empty: return folly::dynamic::object(); - case Mode::JSI: - return jsi::dynamicFromValue( - *runtime_, value_, ignoreYogaStyleProps_ ? isYogaStyleProp : nullptr); + case Mode::JSI: { + if (ignoreYogaStyleProps_ || filterObjectKeys != nullptr) { + // We need to filter props + return jsi::dynamicFromValue( + *runtime_, value_, [&](const std::string& key) { + if (ignoreYogaStyleProps_ && isYogaStyleProp(key)) { + return true; + } + if (filterObjectKeys) { + return filterObjectKeys(key); + } + return false; + }); + } else { + // We don't need to filter, just include all props by default + return jsi::dynamicFromValue(*runtime_, value_, nullptr); + } + } case Mode::Dynamic: return dynamic_; } diff --git a/packages/react-native/ReactCommon/react/renderer/core/RawProps.h b/packages/react-native/ReactCommon/react/renderer/core/RawProps.h index b7716be5a97..3e63bce5a74 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/RawProps.h +++ b/packages/react-native/ReactCommon/react/renderer/core/RawProps.h @@ -71,7 +71,16 @@ class RawProps final { * The support for explicit conversion to `folly::dynamic` is deprecated and * will be removed as soon Android implementation does not need it. */ - explicit operator folly::dynamic() const noexcept; + explicit operator folly::dynamic() const; + + /* + * Deprecated. Do not use. + * The support for explicit conversion to `folly::dynamic` is deprecated and + * will be removed as soon Android implementation does not need it. + */ + folly::dynamic toDynamic( + const std::function& filterObjectKeys = + nullptr) const; /* * Once called, Yoga style props will be filtered out during conversion to