mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
d269844cc1
Summary: Each ComponentDescriptor becomes capable of doing its own interpolation over props for animation purposes. This new custom interpolator is called by default by the ConcreteComponentDescriptor, but `ComponentDescriptor::interpolateProps` is a virtual function and each ComponentDescriptor can provide custom interpolation if necessary. For now, only View does any actual interpolation, to support LayoutAnimations. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D20965310 fbshipit-source-id: e1c1588107848e94c155efecb0da1cc1619ae544
56 lines
1.9 KiB
C++
56 lines
1.9 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <react/components/view/ViewShadowNode.h>
|
|
#include <react/core/ConcreteComponentDescriptor.h>
|
|
#include "ViewProps.h"
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
class ViewComponentDescriptor
|
|
: public ConcreteComponentDescriptor<ViewShadowNode> {
|
|
public:
|
|
ViewComponentDescriptor(ComponentDescriptorParameters const ¶meters)
|
|
: ConcreteComponentDescriptor<ViewShadowNode>(parameters) {}
|
|
|
|
virtual SharedProps interpolateProps(
|
|
float animationProgress,
|
|
const SharedProps &props,
|
|
const SharedProps &newProps) const override {
|
|
ViewProps const *oldViewProps =
|
|
dynamic_cast<ViewProps const *>(props.get());
|
|
ViewProps const *newViewProps =
|
|
dynamic_cast<ViewProps const *>(newProps.get());
|
|
float opacity = oldViewProps->opacity +
|
|
(newViewProps->opacity - oldViewProps->opacity) * animationProgress;
|
|
|
|
SharedProps interpolatedPropsShared = cloneProps(newProps, {});
|
|
ViewProps *interpolatedProps = const_cast<ViewProps *>(
|
|
dynamic_cast<ViewProps const *>(interpolatedPropsShared.get()));
|
|
interpolatedProps->opacity = opacity;
|
|
|
|
// Android uses RawProps, not props, to update props on the platform...
|
|
// Since interpolated props don't interpolate at all using RawProps, we need
|
|
// to "re-hydrate" raw props after interpolating. This is what actually gets
|
|
// sent to the mounting layer. This is a temporary hack, only for platforms
|
|
// that use RawProps/folly::dynamic instead of concrete props on the
|
|
// mounting layer. Once we can remove this, we should change `rawProps` to
|
|
// be const again.
|
|
#ifdef ANDROID
|
|
interpolatedProps->rawProps["opacity"] = opacity;
|
|
#endif
|
|
|
|
return interpolatedPropsShared;
|
|
};
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|