Skip to content

Commit 85fc370

Browse files
coadofacebook-github-bot
authored andcommitted
Add support for shadow props to AnimationBackend
Summary: Adds support for shadow color/offset/opacity/radius prop to the animation backend. Differential Revision: D88007307
1 parent 084710e commit 85fc370

File tree

4 files changed

+98
-4
lines changed

4 files changed

+98
-4
lines changed

packages/react-native/ReactCommon/react/renderer/animationbackend/AnimatedPropSerializer.cpp

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,40 @@ void AnimatedPropsSerializer::packBackgroundColor(
8585
folly::dynamic& dyn,
8686
const AnimatedPropBase& animatedProp) {
8787
const auto& backgroundColor = get<SharedColor>(animatedProp);
88-
if (backgroundColor) {
89-
dyn.insert("backgroundColor", static_cast<int32_t>(*backgroundColor));
90-
}
88+
dyn.insert("backgroundColor", static_cast<int32_t>(*backgroundColor));
89+
}
90+
91+
/* static */
92+
void packShadowColor(
93+
folly::dynamic& dyn,
94+
const AnimatedPropBase& animatedProp) {
95+
const auto& shadowColor = get<SharedColor>(animatedProp);
96+
dyn.insert("shadowColor", static_cast<int32_t>(*shadowColor));
97+
}
98+
99+
/* static */
100+
void packShadowOffset(
101+
folly::dynamic& dyn,
102+
const AnimatedPropBase& animatedProp) {
103+
const auto& shadowOffset = get<Size>(animatedProp);
104+
dyn.insert(
105+
"shadowOffset",
106+
folly::dynamic::object("width", shadowOffset.width)(
107+
"height", shadowOffset.height));
108+
}
109+
110+
/* static */
111+
void packShadowOpacity(
112+
folly::dynamic& dyn,
113+
const AnimatedPropBase& animatedProp) {
114+
dyn.insert("shadowOpacity", get<Float>(animatedProp));
115+
}
116+
117+
/* static */
118+
void packShadowRadius(
119+
folly::dynamic& dyn,
120+
const AnimatedPropBase& animatedProp) {
121+
dyn.insert("shadowRadius", get<Float>(animatedProp));
91122
}
92123

93124
/* static */
@@ -111,6 +142,22 @@ void AnimatedPropsSerializer::packAnimatedProp(
111142
packBorderRadii(dyn, *animatedProp);
112143
break;
113144

145+
case SHADOW_COLOR:
146+
packShadowColor(dyn, *animatedProp);
147+
break;
148+
149+
case SHADOW_OFFSET:
150+
packShadowOffset(dyn, *animatedProp);
151+
break;
152+
153+
case SHADOW_OPACITY:
154+
packShadowOpacity(dyn, *animatedProp);
155+
break;
156+
157+
case SHADOW_RADIUS:
158+
packShadowRadius(dyn, *animatedProp);
159+
break;
160+
114161
case WIDTH:
115162
case HEIGHT:
116163
case FLEX:

packages/react-native/ReactCommon/react/renderer/animationbackend/AnimatedProps.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,19 @@
1212

1313
namespace facebook::react {
1414

15-
enum PropName { OPACITY, WIDTH, HEIGHT, BORDER_RADII, FLEX, TRANSFORM, BACKGROUND_COLOR };
15+
enum PropName {
16+
OPACITY,
17+
WIDTH,
18+
HEIGHT,
19+
BORDER_RADII,
20+
FLEX,
21+
TRANSFORM,
22+
BACKGROUND_COLOR,
23+
SHADOW_COLOR,
24+
SHADOW_OFFSET,
25+
SHADOW_OPACITY,
26+
SHADOW_RADIUS
27+
};
1628

1729
struct AnimatedPropBase {
1830
PropName propName;
@@ -74,6 +86,25 @@ inline void cloneProp(BaseViewProps &viewProps, const AnimatedPropBase &animated
7486
case BACKGROUND_COLOR:
7587
viewProps.backgroundColor = get<SharedColor>(animatedProp);
7688
break;
89+
90+
case SHADOW_COLOR:
91+
viewProps.shadowColor = get<SharedColor>(animatedProp);
92+
break;
93+
94+
case SHADOW_OFFSET:
95+
viewProps.shadowOffset = get<Size>(animatedProp);
96+
break;
97+
98+
case SHADOW_OPACITY:
99+
viewProps.shadowOpacity = get<Float>(animatedProp);
100+
break;
101+
102+
case SHADOW_RADIUS:
103+
viewProps.shadowRadius = get<Float>(animatedProp);
104+
break;
105+
106+
default:
107+
break;
77108
}
78109
}
79110
} // namespace facebook::react

packages/react-native/ReactCommon/react/renderer/animationbackend/AnimatedPropsBuilder.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ struct AnimatedPropsBuilder {
3939
{
4040
props.push_back(std::make_unique<AnimatedProp<SharedColor>>(BACKGROUND_COLOR, value));
4141
}
42+
void setShadowColor(SharedColor value)
43+
{
44+
props.push_back(std::make_unique<AnimatedProp<SharedColor>>(SHADOW_COLOR, value));
45+
}
46+
void setShadowOpacity(Float value)
47+
{
48+
props.push_back(std::make_unique<AnimatedProp<Float>>(SHADOW_OPACITY, value));
49+
}
50+
void setShadowRadius(Float value)
51+
{
52+
props.push_back(std::make_unique<AnimatedProp<Float>>(SHADOW_RADIUS, value));
53+
}
4254
void storeDynamic(folly::dynamic &d)
4355
{
4456
rawProps = std::make_unique<RawProps>(std::move(d));

packages/react-native/ReactCommon/react/renderer/animationbackend/AnimatedPropsSerializer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ class AnimatedPropsSerializer {
2121
static void packBorderRadii(folly::dynamic &dyn, const AnimatedPropBase &animatedProp);
2222
static void packTransform(folly::dynamic &dyn, const AnimatedPropBase &animatedProp);
2323
static void packBackgroundColor(folly::dynamic &dyn, const AnimatedPropBase &animatedProp);
24+
static void packShadowColor(folly::dynamic &dyn, const AnimatedPropBase &animatedProp);
25+
static void packShadowOffset(folly::dynamic &dyn, const AnimatedPropBase &animatedProp);
26+
static void packShadowOpacity(folly::dynamic &dyn, const AnimatedPropBase &animatedProp);
27+
static void packShadowRadius(folly::dynamic &dyn, const AnimatedPropBase &animatedProp);
2428
static void
2529
packBorderRadiusCorner(folly::dynamic &dyn, const std::string &propName, const std::optional<ValueUnit> &cornerValue);
2630
};

0 commit comments

Comments
 (0)