@@ -13,7 +13,13 @@ std::shared_ptr<TransformOperation> TransformInterpolator::resolveOperation(
1313 return operation;
1414}
1515
16- folly::dynamic
16+ TransformOperationInterpolator<PerspectiveOperation>::
17+ TransformOperationInterpolator (
18+ const std::shared_ptr<PerspectiveOperation> &defaultOperation)
19+ : TransformOperationInterpolatorBase<PerspectiveOperation>(
20+ defaultOperation) {}
21+
22+ std::unique_ptr<TransformOperation>
1723TransformOperationInterpolator<PerspectiveOperation>::interpolate(
1824 double progress,
1925 const std::shared_ptr<TransformOperation> &from,
@@ -24,16 +30,16 @@ TransformOperationInterpolator<PerspectiveOperation>::interpolate(
2430 const auto &toValue =
2531 std::static_pointer_cast<PerspectiveOperation>(to)->value ;
2632
27- if (fromValue.value == 0 )
28- return from->toDynamic ();
29- if (toValue.value == 0 )
30- return to->toDynamic ();
31-
32- return PerspectiveOperation (fromValue.interpolate (progress, toValue))
33- .toDynamic ();
33+ return std::make_unique<PerspectiveOperation>(
34+ fromValue.interpolate (progress, toValue));
3435}
3536
36- folly::dynamic TransformOperationInterpolator<MatrixOperation>::interpolate(
37+ TransformOperationInterpolator<MatrixOperation>::TransformOperationInterpolator(
38+ const std::shared_ptr<MatrixOperation> &defaultOperation)
39+ : TransformOperationInterpolatorBase<MatrixOperation>(defaultOperation) {}
40+
41+ std::unique_ptr<TransformOperation>
42+ TransformOperationInterpolator<MatrixOperation>::interpolate(
3743 double progress,
3844 const std::shared_ptr<TransformOperation> &from,
3945 const std::shared_ptr<TransformOperation> &to,
@@ -43,21 +49,18 @@ folly::dynamic TransformOperationInterpolator<MatrixOperation>::interpolate(
4349 const auto fromMatrix = matrixFromOperation (from, shouldBe3D, context);
4450 const auto toMatrix = matrixFromOperation (to, shouldBe3D, context);
4551
46- folly::dynamic value;
47-
4852 if (shouldBe3D) {
49- value = interpolateMatrix<TransformMatrix3D>(progress, fromMatrix, toMatrix)
50- .toDynamic ();
51- } else {
52- // Unfortunately 2D matrices aren't handled properly in RN, so we have to
53- // convert them to 3D
54- // see the issue: https://github.com/facebook/react-native/issues/53639
55- const auto result2D =
56- interpolateMatrix<TransformMatrix2D>(progress, fromMatrix, toMatrix);
57- value = TransformMatrix3D::from2D (result2D).toDynamic ();
53+ return std::make_unique<MatrixOperation>(
54+ interpolateMatrix<TransformMatrix3D>(progress, fromMatrix, toMatrix));
5855 }
5956
60- return folly::dynamic::object (from->getOperationName (), value);
57+ const auto result2D =
58+ interpolateMatrix<TransformMatrix2D>(progress, fromMatrix, toMatrix);
59+
60+ // Unfortunately 2D matrices aren't handled properly in RN, so we have to
61+ // convert them to 3D
62+ // see the issue: https://github.com/facebook/react-native/issues/53639
63+ return std::make_unique<MatrixOperation>(TransformMatrix3D::from2D (result2D));
6164}
6265
6366template <typename MatrixType>
@@ -139,21 +142,23 @@ template TransformMatrix3D TransformOperationInterpolator<MatrixOperation>::
139142 const TransformMatrix::Shared &) const ;
140143
141144// Template implementations
142- template <typename OperationType >
143- TransformOperationInterpolator<OperationType >::TransformOperationInterpolator(
144- std::shared_ptr<OperationType> defaultOperation)
145- : TransformOperationInterpolatorBase<OperationType >(defaultOperation) {}
145+ template <typename TOperation >
146+ TransformOperationInterpolator<TOperation >::TransformOperationInterpolator(
147+ const std::shared_ptr<TOperation> & defaultOperation)
148+ : TransformOperationInterpolatorBase<TOperation >(defaultOperation) {}
146149
147- template <typename OperationType>
148- folly::dynamic TransformOperationInterpolator<OperationType>::interpolate(
150+ template <typename TOperation>
151+ std::unique_ptr<TransformOperation>
152+ TransformOperationInterpolator<TOperation>::interpolate(
149153 double progress,
150154 const std::shared_ptr<TransformOperation> &from,
151155 const std::shared_ptr<TransformOperation> &to,
152156 const TransformInterpolationContext &context) const {
153- const auto &fromOp = *std::static_pointer_cast<OperationType>(from);
154- const auto &toOp = *std::static_pointer_cast<OperationType>(to);
155- return OperationType (fromOp.value .interpolate (progress, toOp.value ))
156- .toDynamic ();
157+ const auto &fromOp = *std::static_pointer_cast<TOperation>(from);
158+ const auto &toOp = *std::static_pointer_cast<TOperation>(to);
159+
160+ return std::make_unique<TOperation>(
161+ fromOp.value .interpolate (progress, toOp.value ));
157162}
158163
159164template <ResolvableTransformOp TOperation>
@@ -164,17 +169,17 @@ TransformOperationInterpolator<TOperation>::TransformOperationInterpolator(
164169 config_ (std::move(config)) {}
165170
166171template <ResolvableTransformOp TOperation>
167- folly::dynamic TransformOperationInterpolator<TOperation>::interpolate(
172+ std::unique_ptr<TransformOperation>
173+ TransformOperationInterpolator<TOperation>::interpolate(
168174 double progress,
169175 const std::shared_ptr<TransformOperation> &from,
170176 const std::shared_ptr<TransformOperation> &to,
171177 const TransformInterpolationContext &context) const {
172178 const auto &fromOp = *std::static_pointer_cast<TOperation>(from);
173179 const auto &toOp = *std::static_pointer_cast<TOperation>(to);
174- return TOperation (
175- fromOp.value .interpolate (
176- progress, toOp.value , getResolvableValueContext (context)))
177- .toDynamic ();
180+
181+ return std::make_unique<TOperation>(fromOp.value .interpolate (
182+ progress, toOp.value , getResolvableValueContext (context)));
178183}
179184
180185template <ResolvableTransformOp TOperation>
0 commit comments