Skip to content

Commit fbd7eba

Browse files
Handle dynamic props
1 parent 785102b commit fbd7eba

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

packages/react-native/ReactCommon/AnimatedProps.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ T get(const std::unique_ptr<AnimatedPropBase>& animatedProp){
3737

3838
struct AnimatedProps{
3939
std::vector<std::unique_ptr<AnimatedPropBase>> props;
40-
// std::unique_ptr<RawProps> rest;
40+
std::unique_ptr<RawProps> rawProps;
4141
};
4242
}
4343

packages/react-native/ReactCommon/AnimatedPropsBuilder.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace facebook::react {
1313

1414
struct AnimatedPropsBuilder{
1515
std::vector<std::unique_ptr<AnimatedPropBase>> props;
16+
std::unique_ptr<RawProps> rawProps;
17+
1618
void setOpacity(Float value){
1719
props.push_back(std::make_unique<AnimatedProp<Float>>(OPACITY, value));
1820
}
@@ -29,13 +31,13 @@ struct AnimatedPropsBuilder{
2931
props.push_back(std::make_unique<AnimatedProp<Transform>>(TRANSFORM, std::move(t)));
3032
}
3133
void storeDynamic(folly::dynamic& d){
32-
// animatedProps.rest = std::make_unique<RawProps>(std::move(d));
34+
rawProps = std::make_unique<RawProps>(std::move(d));
3335
}
3436
void storeJSI(jsi::Runtime& runtime, jsi::Value& value){
35-
// animatedProps.rest = std::make_unique<RawProps>(runtime, value);
37+
rawProps = std::make_unique<RawProps>(runtime, value);
3638
}
3739
AnimatedProps get(){
38-
return AnimatedProps{std::move(props)};
40+
return AnimatedProps{std::move(props), std::move(rawProps)};
3941
}
4042
};
4143

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,18 @@ void AnimationBackend::onAnimationFrame(double timestamp) {
3939
return std::static_pointer_cast<RootShadowNode>(oldRootShadowNode.cloneMultiple(families, [this, families, &updates](const ShadowNode &shadowNode, const ShadowNodeFragment &fragment){
4040
PropsParserContext propsParserContext{
4141
shadowNode.getSurfaceId(), *shadowNode.getContextContainer()};
42-
auto newProps = shadowNode.getComponentDescriptor().cloneProps(propsParserContext, shadowNode.getProps(), {});
42+
43+
auto& animatedProps = updates.at(shadowNode.getTag());
44+
45+
Props::Shared newProps;
46+
if (animatedProps.rawProps){
47+
newProps = shadowNode.getComponentDescriptor().cloneProps(propsParserContext, shadowNode.getProps(), std::move(*animatedProps.rawProps));
48+
} else {
49+
newProps = shadowNode.getComponentDescriptor().cloneProps(propsParserContext, shadowNode.getProps(), {});
50+
}
51+
4352
auto viewProps = std::const_pointer_cast<BaseViewProps>(std::static_pointer_cast<const BaseViewProps>(newProps));
44-
for (auto& animatedProp: updates.at(shadowNode.getTag()).props){
53+
for (auto& animatedProp: animatedProps.props){
4554
switch (animatedProp->propName) {
4655
case OPACITY:
4756
viewProps->opacity = get<Float>(animatedProp);

0 commit comments

Comments
 (0)