Skip to content

Commit bf174ce

Browse files
committed
Make it work
1 parent c6e93ee commit bf174ce

23 files changed

+189
-99
lines changed

packages/react-native-reanimated/Common/cpp/reanimated/CSS/configs/CSSTransitionConfig.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111

1212
namespace reanimated::css {
1313

14+
enum class TransitionPropertyStatus : uint8_t {
15+
Updated,
16+
Removed,
17+
Reversed,
18+
};
19+
20+
struct TransitionPropertyUpdate {
21+
std::string name;
22+
TransitionPropertyStatus status;
23+
};
24+
1425
struct CSSTransitionPropertySettings {
1526
double duration;
1627
EasingFunction easingFunction;

packages/react-native-reanimated/Common/cpp/reanimated/CSS/core/CSSTransition.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#include <reanimated/CSS/core/CSSTransition.h>
22

33
#include <memory>
4+
#include <optional>
45
#include <string>
5-
#include <unordered_map>
6+
#include <unordered_set>
67
#include <utility>
78
#include <vector>
89

@@ -49,18 +50,27 @@ void CSSTransition::updateSettings(const CSSTransitionPropertySettingsUpdates &s
4950
}
5051
}
5152

52-
folly::dynamic
53-
CSSTransition::run(jsi::Runtime &rt, const CSSTransitionPropertyUpdates &propertyUpdates, const double timestamp) {
54-
const auto reversedPropertyNames = styleInterpolator_.updateInterpolatedProperties(rt, propertyUpdates);
55-
56-
std::vector<std::string> propertyNames;
57-
propertyNames.reserve(propertyUpdates.size());
58-
for (const auto &[key, value] : propertyUpdates) {
59-
propertyNames.emplace_back(key);
53+
std::optional<std::unordered_set<std::string>> CSSTransition::getProperties() const {
54+
const auto allIt = settings_.find("all");
55+
if (allIt != settings_.end()) {
56+
return std::nullopt; // "all" means no specific properties
6057
}
6158

62-
progressProvider_.runProgressProviders(timestamp, settings_, propertyNames, reversedPropertyNames);
59+
std::unordered_set<std::string> properties;
60+
for (const auto &[property, _] : settings_) {
61+
properties.insert(property);
62+
}
63+
return properties;
64+
}
6365

66+
folly::dynamic CSSTransition::run(
67+
jsi::Runtime &rt,
68+
const CSSTransitionPropertyUpdates &propertyUpdates,
69+
const jsi::Value &lastUpdates,
70+
const double timestamp) {
71+
const auto updatedProperties =
72+
styleInterpolator_.updateInterpolatedProperties(rt, propertyUpdates, lastUpdates, settings_);
73+
progressProvider_.runProgressProviders(timestamp, updatedProperties, settings_);
6474
return update(timestamp);
6575
}
6676

packages/react-native-reanimated/Common/cpp/reanimated/CSS/core/CSSTransition.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ class CSSTransition {
2222
double getMinDelay(double timestamp) const;
2323
TransitionProgressState getState() const;
2424
void updateSettings(const CSSTransitionPropertySettingsUpdates &settingsUpdates);
25-
folly::dynamic run(jsi::Runtime &rt, const CSSTransitionPropertyUpdates &propertyUpdates, double timestamp);
25+
std::optional<std::unordered_set<std::string>> getProperties() const;
26+
folly::dynamic run(
27+
jsi::Runtime &rt,
28+
const CSSTransitionPropertyUpdates &propertyUpdates,
29+
const jsi::Value &lastUpdates,
30+
double timestamp);
2631
folly::dynamic update(double timestamp);
2732

2833
private:

packages/react-native-reanimated/Common/cpp/reanimated/CSS/interpolation/InterpolatorFactory.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <reanimated/CSS/interpolation/InterpolatorFactory.h>
22
#include <reanimated/CSS/interpolation/filters/FilterStyleInterpolator.h>
33

4+
#include <algorithm>
45
#include <memory>
56
#include <string>
67
#include <unordered_map>
@@ -12,6 +13,11 @@ class RecordInterpolatorFactory : public PropertyInterpolatorFactory {
1213
explicit RecordInterpolatorFactory(const InterpolatorFactoriesRecord &factories)
1314
: PropertyInterpolatorFactory(), factories_(factories) {}
1415

16+
bool isDiscrete() const override {
17+
return std::all_of(
18+
factories_.begin(), factories_.end(), [](const auto &pair) { return pair.second->isDiscrete(); });
19+
}
20+
1521
const CSSValue &getDefaultValue() const override {
1622
static EmptyObjectValue emptyObjectValue;
1723
return emptyObjectValue;
@@ -63,6 +69,10 @@ class ArrayInterpolatorFactory : public ArrayLikeInterpolatorFactory {
6369
explicit ArrayInterpolatorFactory(const InterpolatorFactoriesArray &factories)
6470
: ArrayLikeInterpolatorFactory(), factories_(factories) {}
6571

72+
bool isDiscrete() const override {
73+
return std::all_of(factories_.begin(), factories_.end(), [](const auto &factory) { return factory->isDiscrete(); });
74+
}
75+
6676
std::shared_ptr<PropertyInterpolator> create(
6777
const PropertyPath &propertyPath,
6878
const std::shared_ptr<ViewStylesRepository> &viewStylesRepository) const override {
@@ -78,6 +88,10 @@ class FiltersInterpolatorFactory : public ArrayLikeInterpolatorFactory {
7888
explicit FiltersInterpolatorFactory(const std::shared_ptr<StyleOperationInterpolators> &interpolators)
7989
: ArrayLikeInterpolatorFactory(), interpolators_(interpolators) {}
8090

91+
bool isDiscrete() const override {
92+
return false;
93+
}
94+
8195
std::shared_ptr<PropertyInterpolator> create(
8296
const PropertyPath &propertyPath,
8397
const std::shared_ptr<ViewStylesRepository> &viewStylesRepository) const override {
@@ -93,6 +107,10 @@ class TransformsInterpolatorFactory : public PropertyInterpolatorFactory {
93107
explicit TransformsInterpolatorFactory(const std::shared_ptr<StyleOperationInterpolators> &interpolators)
94108
: PropertyInterpolatorFactory(), interpolators_(interpolators) {}
95109

110+
bool isDiscrete() const override {
111+
return false;
112+
}
113+
96114
const CSSValue &getDefaultValue() const override {
97115
static EmptyTransformsValue emptyTransformsValue;
98116
return emptyTransformsValue;

packages/react-native-reanimated/Common/cpp/reanimated/CSS/interpolation/InterpolatorFactory.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class SimpleValueInterpolatorFactory : public PropertyInterpolatorFactory {
2828
explicit SimpleValueInterpolatorFactory(const TValue &defaultValue)
2929
: PropertyInterpolatorFactory(), defaultValue_(defaultValue) {}
3030

31+
bool isDiscrete() const override {
32+
return (Discrete<AllowedTypes> && ...);
33+
}
34+
3135
const CSSValue &getDefaultValue() const override {
3236
return defaultValue_;
3337
}
@@ -50,6 +54,10 @@ class ResolvableValueInterpolatorFactory : public PropertyInterpolatorFactory {
5054
explicit ResolvableValueInterpolatorFactory(const TValue &defaultValue, ResolvableValueInterpolatorConfig config)
5155
: PropertyInterpolatorFactory(), defaultValue_(defaultValue), config_(std::move(config)) {}
5256

57+
bool isDiscrete() const override {
58+
return (Discrete<AllowedTypes> && ...);
59+
}
60+
5361
const CSSValue &getDefaultValue() const override {
5462
return defaultValue_;
5563
}

packages/react-native-reanimated/Common/cpp/reanimated/CSS/interpolation/PropertyInterpolator.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ PropertyInterpolator::PropertyInterpolator(
1212
const std::shared_ptr<ViewStylesRepository> &viewStylesRepository)
1313
: propertyPath_(std::move(propertyPath)), viewStylesRepository_(viewStylesRepository) {}
1414

15-
bool PropertyInterpolator::isDiscrete() const {
16-
return false;
17-
}
18-
1915
std::string PropertyInterpolator::getPropertyPathString() const {
2016
if (propertyPath_.empty()) {
2117
return "";

packages/react-native-reanimated/Common/cpp/reanimated/CSS/interpolation/PropertyInterpolator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class PropertyInterpolator {
1919
PropertyPath propertyPath,
2020
const std::shared_ptr<ViewStylesRepository> &viewStylesRepository);
2121

22-
virtual bool isDiscrete() const = 0;
2322
virtual folly::dynamic getStyleValue(const std::shared_ptr<const ShadowNode> &shadowNode) const = 0;
2423
virtual folly::dynamic getResetStyle(const std::shared_ptr<const ShadowNode> &shadowNode) const = 0;
2524
virtual folly::dynamic getFirstKeyframeValue() const = 0;
@@ -49,6 +48,7 @@ class PropertyInterpolatorFactory {
4948
PropertyInterpolatorFactory() = default;
5049
virtual ~PropertyInterpolatorFactory() = default;
5150

51+
virtual bool isDiscrete() const = 0;
5252
virtual const CSSValue &getDefaultValue() const = 0;
5353

5454
virtual std::shared_ptr<PropertyInterpolator> create(

packages/react-native-reanimated/Common/cpp/reanimated/CSS/interpolation/groups/ArrayPropertiesInterpolator.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@ ArrayPropertiesInterpolator::ArrayPropertiesInterpolator(
1111
const std::shared_ptr<ViewStylesRepository> &viewStylesRepository)
1212
: GroupPropertiesInterpolator(propertyPath, viewStylesRepository), factories_(factories) {}
1313

14-
bool ArrayPropertiesInterpolator::isDiscrete() const {
15-
for (const auto &interpolator : interpolators_) {
16-
if (!interpolator->isDiscrete()) {
17-
return false;
18-
}
19-
}
20-
return true;
21-
}
22-
2314
void ArrayPropertiesInterpolator::updateKeyframes(jsi::Runtime &rt, const jsi::Value &keyframes) {
2415
const jsi::Array keyframesArray = keyframes.asObject(rt).asArray(rt);
2516
const size_t valuesCount = keyframesArray.size(rt);

packages/react-native-reanimated/Common/cpp/reanimated/CSS/interpolation/groups/ArrayPropertiesInterpolator.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class ArrayPropertiesInterpolator : public GroupPropertiesInterpolator {
1515
const std::shared_ptr<ViewStylesRepository> &viewStylesRepository);
1616
virtual ~ArrayPropertiesInterpolator() = default;
1717

18-
bool isDiscrete() const override;
1918
void updateKeyframes(jsi::Runtime &rt, const jsi::Value &keyframes) override;
2019
bool updateKeyframesFromStyleChange(
2120
jsi::Runtime &rt,

packages/react-native-reanimated/Common/cpp/reanimated/CSS/interpolation/groups/GroupPropertiesInterpolator.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class GroupPropertiesInterpolator : public PropertyInterpolator {
1414
const PropertyPath &propertyPath,
1515
const std::shared_ptr<ViewStylesRepository> &viewStylesRepository);
1616

17-
bool isDiscrete() const override;
1817
folly::dynamic getStyleValue(const std::shared_ptr<const ShadowNode> &shadowNode) const override;
1918
folly::dynamic getResetStyle(const std::shared_ptr<const ShadowNode> &shadowNode) const override;
2019
folly::dynamic getFirstKeyframeValue() const override;

0 commit comments

Comments
 (0)