From 6f1df3bcc576c53a1d6a469f339349ea9b6a74b0 Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Fri, 11 Aug 2023 10:04:20 -0700 Subject: [PATCH] Fixes regression of prop parsing for elevation (#38959) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38959 When refactoring ViewProps in D47492635, `elevation` prop parsing was dropped. This restores it. ## Changelog: [General] [Fixed] - Fabric regression for elevation prop in Android Reviewed By: mdvacca Differential Revision: D48269510 fbshipit-source-id: 336fad2fd53689102be80624e2b6c71d6d43c24b --- .../react/renderer/components/view/BaseViewProps.h | 2 -- .../renderer/components/view/HostPlatformViewProps.cpp | 8 ++++++++ .../renderer/components/view/HostPlatformViewProps.h | 2 ++ .../ReactCommon/react/test_utils/shadowTreeGeneration.h | 6 ++++++ 4 files changed, 16 insertions(+), 2 deletions(-) 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 9d2530e7061505..e5dd072407815a 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.h @@ -72,8 +72,6 @@ class BaseViewProps : public YogaStylableProps, public AccessibilityProps { LayoutConformance experimental_layoutConformance{}; - Float elevation{}; /* Android-only */ - #pragma mark - Convenience Methods BorderMetrics resolveBorderMetrics(LayoutMetrics const &layoutMetrics) const; 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 85f74f20a2c45b..9559d3dcb69512 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 @@ -23,6 +23,14 @@ HostPlatformViewProps::HostPlatformViewProps( RawProps const &rawProps, bool shouldSetRawProps) : BaseViewProps(context, sourceProps, rawProps, shouldSetRawProps), + elevation( + CoreFeatures::enablePropIteratorSetter ? sourceProps.elevation + : convertRawProp( + context, + rawProps, + "elevation", + sourceProps.elevation, + {})), nativeBackground( CoreFeatures::enablePropIteratorSetter ? sourceProps.nativeBackground 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 dd08ff16edf84a..c8a4bef1153971 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 @@ -40,6 +40,8 @@ class HostPlatformViewProps : public BaseViewProps { #pragma mark - Props + Float elevation{}; + std::optional nativeBackground{}; std::optional nativeForeground{}; diff --git a/packages/react-native/ReactCommon/react/test_utils/shadowTreeGeneration.h b/packages/react-native/ReactCommon/react/test_utils/shadowTreeGeneration.h index da8aa09e1682bc..eeb959a3186a89 100644 --- a/packages/react-native/ReactCommon/react/test_utils/shadowTreeGeneration.h +++ b/packages/react-native/ReactCommon/react/test_utils/shadowTreeGeneration.h @@ -164,9 +164,11 @@ static inline ShadowNode::Unshared messWithLayoutableOnlyFlag( : Transform::Perspective(42); } +#ifdef ANDROID if (entropy.random(0.1)) { viewProps.elevation = entropy.random() ? 1 : 0; } +#endif return shadowNode.clone({newProps}); } @@ -195,7 +197,9 @@ static inline ShadowNode::Unshared messWithNodeFlattenednessFlags( viewProps.zIndex = {}; viewProps.pointerEvents = PointerEventsMode::Auto; viewProps.transform = Transform::Identity(); +#ifdef ANDROID viewProps.elevation = 0; +#endif } else { viewProps.nativeId = "42"; viewProps.backgroundColor = whiteColor(); @@ -204,7 +208,9 @@ static inline ShadowNode::Unshared messWithNodeFlattenednessFlags( viewProps.zIndex = {entropy.random()}; viewProps.pointerEvents = PointerEventsMode::None; viewProps.transform = Transform::Perspective(entropy.random()); +#ifdef ANDROID viewProps.elevation = entropy.random(); +#endif } return shadowNode.clone({newProps});