Skip to content

Commit 6ec578e

Browse files
committed
background color
1 parent 4f5ddce commit 6ec578e

File tree

3 files changed

+49
-25
lines changed

3 files changed

+49
-25
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
1212

1313
namespace facebook::react {
1414

15-
enum PropName { OPACITY, WIDTH, HEIGHT, BORDER_RADII, FLEX, TRANSFORM };
15+
enum PropName {
16+
OPACITY,
17+
WIDTH,
18+
HEIGHT,
19+
BORDER_RADII,
20+
FLEX,
21+
TRANSFORM,
22+
BACKGROUND_COLOR
23+
};
1624

1725
struct AnimatedPropBase {
1826
PropName propName;
@@ -24,13 +32,13 @@ template <typename T>
2432
struct AnimatedProp : AnimatedPropBase {
2533
T value;
2634
AnimatedProp() = default;
27-
AnimatedProp(PropName propName, const T &value) : AnimatedPropBase{propName}, value(std::move(value)) {}
35+
AnimatedProp(PropName propName, const T& value)
36+
: AnimatedPropBase{propName}, value(std::move(value)) {}
2837
};
2938

3039
template <typename T>
31-
T get(const std::unique_ptr<AnimatedPropBase> &animatedProp)
32-
{
33-
return static_cast<AnimatedProp<T> *>(animatedProp.get())->value;
40+
T get(const std::unique_ptr<AnimatedPropBase>& animatedProp) {
41+
return static_cast<AnimatedProp<T>*>(animatedProp.get())->value;
3442
}
3543

3644
struct AnimatedProps {

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,36 @@ struct AnimatedPropsBuilder {
1515
std::vector<std::unique_ptr<AnimatedPropBase>> props;
1616
std::unique_ptr<RawProps> rawProps;
1717

18-
void setOpacity(Float value)
19-
{
18+
void setOpacity(Float value) {
2019
props.push_back(std::make_unique<AnimatedProp<Float>>(OPACITY, value));
2120
}
22-
void setWidth(yoga::Style::SizeLength value)
23-
{
24-
props.push_back(std::make_unique<AnimatedProp<yoga::Style::SizeLength>>(WIDTH, value));
21+
void setWidth(yoga::Style::SizeLength value) {
22+
props.push_back(
23+
std::make_unique<AnimatedProp<yoga::Style::SizeLength>>(WIDTH, value));
2524
}
26-
void setHeight(yoga::Style::SizeLength value)
27-
{
28-
props.push_back(std::make_unique<AnimatedProp<yoga::Style::SizeLength>>(HEIGHT, value));
25+
void setHeight(yoga::Style::SizeLength value) {
26+
props.push_back(
27+
std::make_unique<AnimatedProp<yoga::Style::SizeLength>>(HEIGHT, value));
2928
}
30-
void setBorderRadii(CascadedBorderRadii &value)
31-
{
32-
props.push_back(std::make_unique<AnimatedProp<CascadedBorderRadii>>(BORDER_RADII, value));
29+
void setBorderRadii(CascadedBorderRadii& value) {
30+
props.push_back(std::make_unique<AnimatedProp<CascadedBorderRadii>>(
31+
BORDER_RADII, value));
3332
}
34-
void setTransform(Transform &t)
35-
{
36-
props.push_back(std::make_unique<AnimatedProp<Transform>>(TRANSFORM, std::move(t)));
33+
void setTransform(Transform& t) {
34+
props.push_back(
35+
std::make_unique<AnimatedProp<Transform>>(TRANSFORM, std::move(t)));
3736
}
38-
void storeDynamic(folly::dynamic &d)
39-
{
37+
void setBackgroundColor(SharedColor value) {
38+
props.push_back(
39+
std::make_unique<AnimatedProp<SharedColor>>(BACKGROUND_COLOR, value));
40+
}
41+
void storeDynamic(folly::dynamic& d) {
4042
rawProps = std::make_unique<RawProps>(std::move(d));
4143
}
42-
void storeJSI(jsi::Runtime &runtime, jsi::Value &value)
43-
{
44+
void storeJSI(jsi::Runtime& runtime, jsi::Value& value) {
4445
rawProps = std::make_unique<RawProps>(runtime, value);
4546
}
46-
AnimatedProps get()
47-
{
47+
AnimatedProps get() {
4848
return AnimatedProps{std::move(props), std::move(rawProps)};
4949
}
5050
};

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include "AnimationBackend.h"
9+
#include <react/renderer/graphics/Color.h>
910
#include <chrono>
1011

1112
namespace facebook::react {
@@ -68,6 +69,10 @@ static inline Props::Shared cloneProps(
6869
case TRANSFORM:
6970
viewProps->transform = get<Transform>(animatedProp);
7071
break;
72+
73+
case BACKGROUND_COLOR:
74+
viewProps->backgroundColor = get<SharedColor>(animatedProp);
75+
break;
7176
}
7277
}
7378
return newProps;
@@ -302,6 +307,17 @@ void AnimationBackend::synchronouslyUpdateProps(
302307
break;
303308
}
304309

310+
case BACKGROUND_COLOR: {
311+
const auto& backgroundColor = get<SharedColor>(animatedProp);
312+
313+
if (backgroundColor) {
314+
dyn.insert(
315+
"backgroundColor", static_cast<int32_t>(*backgroundColor));
316+
}
317+
318+
break;
319+
}
320+
305321
case WIDTH:
306322
case HEIGHT:
307323
case FLEX:

0 commit comments

Comments
 (0)