react-native-reanimated 4.7.1 → 4.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Common/cpp/reanimated/CSS/common/values/CSSNumber.cpp +5 -9
- package/Common/cpp/reanimated/CSS/common/values/CSSNumber.h +2 -6
- package/Common/cpp/reanimated/Fabric/updates/AnimatedPropsRegistry.cpp +135 -33
- package/Common/cpp/reanimated/Fabric/updates/AnimatedPropsRegistry.h +37 -3
- package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.cpp +28 -0
- package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.h +8 -0
- package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistryManager.cpp +4 -1
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp +228 -87
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h +22 -5
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.cpp +9 -12
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.cpp +6 -5
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.h +5 -2
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +22 -1
- package/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +39 -9
- package/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h +1 -1
- package/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h +13 -0
- package/Common/cpp/reanimated/Tools/TextMetrics.h +22 -0
- package/android/src/main/cpp/reanimated/android/NativeProxy.cpp +19 -0
- package/android/src/main/cpp/reanimated/android/NativeProxy.h +1 -0
- package/android/src/main/java/com/swmansion/reanimated/NativeProxy.kt +24 -0
- package/apple/reanimated/apple/REAReducedMotion.h +1 -3
- package/apple/reanimated/apple/native/PlatformDepMethodsHolderImpl.mm +28 -0
- package/jest/resolver.js +4 -1
- package/lib/module/PropsRegistryGarbageCollector.js +43 -25
- package/lib/module/PropsRegistryGarbageCollector.js.map +1 -1
- package/lib/module/ReanimatedModule/NativeReanimated.js +2 -2
- package/lib/module/ReanimatedModule/NativeReanimated.js.map +1 -1
- package/lib/module/commonTypes.js.map +1 -1
- package/lib/module/createAnimatedComponent/AnimatedComponent.js +1 -1
- package/lib/module/createAnimatedComponent/AnimatedComponent.js.map +1 -1
- package/lib/module/createAnimatedComponent/AnimatedComponent.native.js +10 -34
- package/lib/module/createAnimatedComponent/AnimatedComponent.native.js.map +1 -1
- package/lib/module/platform-specific/jsVersion.js +1 -1
- package/lib/module/platformFunctions/setNativeProps.native.js +2 -1
- package/lib/module/platformFunctions/setNativeProps.native.js.map +1 -1
- package/lib/module/updateProps/updateProps.native.js +5 -4
- package/lib/module/updateProps/updateProps.native.js.map +1 -1
- package/lib/typescript/PropsRegistryGarbageCollector.d.ts +2 -2
- package/lib/typescript/PropsRegistryGarbageCollector.d.ts.map +1 -1
- package/lib/typescript/ReanimatedModule/reanimatedModuleProxy.d.ts +1 -1
- package/lib/typescript/ReanimatedModule/reanimatedModuleProxy.d.ts.map +1 -1
- package/lib/typescript/commonTypes.d.ts +3 -1
- package/lib/typescript/commonTypes.d.ts.map +1 -1
- package/lib/typescript/createAnimatedComponent/AnimatedComponent.d.ts +1 -1
- package/lib/typescript/createAnimatedComponent/AnimatedComponent.d.ts.map +1 -1
- package/lib/typescript/createAnimatedComponent/AnimatedComponent.native.d.ts +1 -1
- package/lib/typescript/createAnimatedComponent/AnimatedComponent.native.d.ts.map +1 -1
- package/lib/typescript/createAnimatedComponent/commonTypes.d.ts +1 -1
- package/lib/typescript/createAnimatedComponent/commonTypes.d.ts.map +1 -1
- package/lib/typescript/platform-specific/jsVersion.d.ts +1 -1
- package/lib/typescript/updateProps/updateProps.native.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/PropsRegistryGarbageCollector.ts +46 -25
- package/src/ReanimatedModule/NativeReanimated.ts +2 -2
- package/src/ReanimatedModule/reanimatedModuleProxy.ts +1 -1
- package/src/commonTypes.ts +3 -1
- package/src/createAnimatedComponent/AnimatedComponent.native.tsx +5 -30
- package/src/createAnimatedComponent/AnimatedComponent.tsx +1 -1
- package/src/createAnimatedComponent/commonTypes.ts +1 -1
- package/src/platform-specific/jsVersion.ts +1 -1
- package/src/platformFunctions/setNativeProps.native.ts +3 -1
- package/src/privateGlobals.d.ts +1 -0
- package/src/updateProps/updateProps.native.ts +10 -3
|
@@ -44,15 +44,7 @@ std::string CSSNumberBase<TDerived, TValue>::toString() const {
|
|
|
44
44
|
|
|
45
45
|
template <typename TDerived, typename TValue>
|
|
46
46
|
TDerived CSSNumberBase<TDerived, TValue>::interpolate(double progress, const TDerived &other) const {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if constexpr (requires { TDerived::epsilon; }) {
|
|
50
|
-
if (std::abs(other.value - interpolated) < TDerived::epsilon) {
|
|
51
|
-
return other;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return TDerived(interpolated);
|
|
47
|
+
return TDerived(value + progress * (other.value - value));
|
|
56
48
|
}
|
|
57
49
|
|
|
58
50
|
template <typename TDerived, typename TValue>
|
|
@@ -60,6 +52,10 @@ bool CSSNumberBase<TDerived, TValue>::operator==(const CSSNumberBase<TDerived, T
|
|
|
60
52
|
return value == other.value;
|
|
61
53
|
}
|
|
62
54
|
|
|
55
|
+
CSSTextDouble CSSTextDouble::interpolate(double progress, const CSSTextDouble &other) const {
|
|
56
|
+
return CSSTextDouble(roundTextMetric(value + progress * (other.value - value)));
|
|
57
|
+
}
|
|
58
|
+
|
|
63
59
|
CSSInteger CSSInteger::interpolate(double progress, const CSSInteger &other) const {
|
|
64
60
|
return CSSInteger(static_cast<int>(std::round(value + progress * (other.value - value))));
|
|
65
61
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
#include <reanimated/CSS/common/values/CSSValue.h>
|
|
4
4
|
|
|
5
|
-
#include <
|
|
5
|
+
#include <reanimated/Tools/TextMetrics.h>
|
|
6
6
|
|
|
7
7
|
#include <string>
|
|
8
8
|
|
|
@@ -44,11 +44,7 @@ struct CSSDouble : public CSSNumberBase<CSSDouble, double> {
|
|
|
44
44
|
struct CSSTextDouble : public CSSNumberBase<CSSTextDouble, double> {
|
|
45
45
|
using CSSNumberBase::CSSNumberBase;
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
/// exactly, so a smaller step moves the frame while the text keeps its old
|
|
49
|
-
/// metrics. Interpolation lands on the endpoint once it gets that close.
|
|
50
|
-
/// https://github.com/facebook/react-native/blob/v0.87.0/packages/react-native/ReactCommon/react/renderer/attributedstring/TextAttributes.cpp#L174-L177
|
|
51
|
-
static constexpr double epsilon = facebook::react::kDefaultEpsilon;
|
|
47
|
+
CSSTextDouble interpolate(double progress, const CSSTextDouble &other) const override;
|
|
52
48
|
};
|
|
53
49
|
|
|
54
50
|
struct CSSInteger : public CSSNumberBase<CSSInteger, int> {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
#include <reanimated/Fabric/updates/AnimatedPropsRegistry.h>
|
|
2
2
|
#include <reanimated/Fabric/updates/UpdatesRegistryManager.h>
|
|
3
3
|
#include <reanimated/Tools/FeatureFlags.h>
|
|
4
|
+
#include <reanimated/Tools/TextMetrics.h>
|
|
4
5
|
|
|
5
6
|
#include <react/debug/react_native_assert.h>
|
|
6
7
|
|
|
7
|
-
#include <
|
|
8
|
+
#include <algorithm>
|
|
8
9
|
#include <memory>
|
|
10
|
+
#include <string>
|
|
9
11
|
#include <utility>
|
|
10
12
|
#include <vector>
|
|
11
13
|
|
|
@@ -17,6 +19,16 @@ static inline std::shared_ptr<const ShadowNode> shadowNodeFromValue(
|
|
|
17
19
|
return Bridging<std::shared_ptr<const ShadowNode>>::fromJs(rt, shadowNodeWrapper);
|
|
18
20
|
}
|
|
19
21
|
|
|
22
|
+
static void roundTextMetrics(jsi::Runtime &rt, const jsi::Value &updates) {
|
|
23
|
+
const auto object = updates.asObject(rt);
|
|
24
|
+
for (const auto *propName : TEXT_METRIC_PROP_NAMES) {
|
|
25
|
+
const auto value = object.getProperty(rt, propName);
|
|
26
|
+
if (value.isNumber()) {
|
|
27
|
+
object.setProperty(rt, propName, roundTextMetric(value.asNumber()));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
20
32
|
void AnimatedPropsRegistry::update(jsi::Runtime &rt, const jsi::Value &operations, const double timestamp) {
|
|
21
33
|
react_native_assert(UpdatesRegistryManager::isLockedByCurrentThread());
|
|
22
34
|
auto operationsArray = operations.asObject(rt).asArray(rt);
|
|
@@ -25,91 +37,181 @@ void AnimatedPropsRegistry::update(jsi::Runtime &rt, const jsi::Value &operation
|
|
|
25
37
|
auto item = operationsArray.getValueAtIndex(rt, i).asObject(rt);
|
|
26
38
|
auto shadowNodeWrapper = item.getProperty(rt, "shadowNodeWrapper");
|
|
27
39
|
auto shadowNode = shadowNodeFromValue(rt, shadowNodeWrapper);
|
|
40
|
+
if (isUnmounted(shadowNode->getFamily())) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
28
43
|
|
|
29
44
|
jsi::Value updates = item.getProperty(rt, "updates");
|
|
45
|
+
roundTextMetrics(rt, updates);
|
|
30
46
|
|
|
31
47
|
if constexpr (StaticFeatureFlags::getFlag("USE_ANIMATION_BACKEND")) {
|
|
32
48
|
addJSIPropsToAnimatedPropsBatch(shadowNode->getFamilyShared(), rt, updates);
|
|
33
49
|
} else {
|
|
34
|
-
|
|
50
|
+
const auto dynamicUpdates = jsi::dynamicFromValue(rt, updates);
|
|
51
|
+
// With USE_ANIMATION_BACKEND, no update reaches `updatesRegistry_`, so
|
|
52
|
+
// `collectSettledUpdates` never reads `writeHistories_`.
|
|
53
|
+
if constexpr (StaticFeatureFlags::getFlag("FORCE_REACT_RENDER_FOR_SETTLED_ANIMATIONS")) {
|
|
54
|
+
const bool isAnimatedProps = item.getProperty(rt, "isAnimatedProps").asBool();
|
|
55
|
+
trackUpdate(shadowNode->getTag(), dynamicUpdates, isAnimatedProps, timestamp);
|
|
56
|
+
}
|
|
57
|
+
addUpdatesToBatch(shadowNode->getFamilyShared(), dynamicUpdates);
|
|
35
58
|
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
36
61
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
62
|
+
void AnimatedPropsRegistry::trackUpdate(
|
|
63
|
+
const Tag tag,
|
|
64
|
+
const folly::dynamic &updates,
|
|
65
|
+
const bool isAnimatedProps,
|
|
66
|
+
const double timestamp) {
|
|
67
|
+
auto &writeHistory = writeHistories_[tag];
|
|
68
|
+
writeHistory.lastWriteTimestamp = timestamp;
|
|
69
|
+
|
|
70
|
+
for (const auto &key : updates.keys()) {
|
|
71
|
+
auto &keyOrigins = writeHistory.keyOrigins[key.getString()];
|
|
72
|
+
if (isAnimatedProps) {
|
|
73
|
+
keyOrigins.writtenByAnimatedProps = true;
|
|
74
|
+
} else {
|
|
75
|
+
keyOrigins.writtenByAnimatedStyle = true;
|
|
50
76
|
}
|
|
77
|
+
keyOrigins.lastWrittenByAnimatedStyle = !isAnimatedProps;
|
|
51
78
|
}
|
|
79
|
+
|
|
80
|
+
invalidateSyncedTag(tag);
|
|
52
81
|
}
|
|
53
82
|
|
|
54
|
-
|
|
83
|
+
void AnimatedPropsRegistry::invalidateSyncedTag(const Tag tag) {
|
|
84
|
+
// If JS already has a `settledProps` snapshot for this tag, it is now
|
|
85
|
+
// stale — schedule a refresh on the next `collectSettledUpdates`.
|
|
86
|
+
if (syncedTags_.erase(tag) > 0) {
|
|
87
|
+
invalidatedTags_.insert(tag);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
jsi::Object AnimatedPropsRegistry::createSettledUpdate(
|
|
92
|
+
jsi::Runtime &rt,
|
|
93
|
+
const Tag viewTag,
|
|
94
|
+
const folly::dynamic &props,
|
|
95
|
+
const WriteHistory &writeHistory) {
|
|
96
|
+
jsi::Object settledProps(rt);
|
|
97
|
+
jsi::Object settledStyle(rt);
|
|
98
|
+
std::vector<jsi::Value> keysLastWrittenByAnimatedStyle;
|
|
99
|
+
|
|
100
|
+
for (const auto &[key, value] : props.items()) {
|
|
101
|
+
const auto &keyString = key.getString();
|
|
102
|
+
const auto keyOriginsIt = writeHistory.keyOrigins.find(keyString);
|
|
103
|
+
if (keyOriginsIt == writeHistory.keyOrigins.end()) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const auto &keyOrigins = keyOriginsIt->second;
|
|
107
|
+
if (keyOrigins.writtenByAnimatedProps) {
|
|
108
|
+
settledProps.setProperty(rt, keyString.c_str(), jsi::valueFromDynamic(rt, value));
|
|
109
|
+
}
|
|
110
|
+
if (keyOrigins.writtenByAnimatedStyle) {
|
|
111
|
+
settledStyle.setProperty(rt, keyString.c_str(), jsi::valueFromDynamic(rt, value));
|
|
112
|
+
}
|
|
113
|
+
if (keyOrigins.lastWrittenByAnimatedStyle) {
|
|
114
|
+
keysLastWrittenByAnimatedStyle.emplace_back(jsi::String::createFromUtf8(rt, keyString));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
jsi::Array keysLastWrittenByAnimatedStyleArray(rt, keysLastWrittenByAnimatedStyle.size());
|
|
119
|
+
for (size_t i = 0; i < keysLastWrittenByAnimatedStyle.size(); ++i) {
|
|
120
|
+
keysLastWrittenByAnimatedStyleArray.setValueAtIndex(rt, i, std::move(keysLastWrittenByAnimatedStyle[i]));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
jsi::Object settledUpdate(rt);
|
|
124
|
+
settledUpdate.setProperty(rt, "viewTag", viewTag);
|
|
125
|
+
settledUpdate.setProperty(rt, "props", std::move(settledProps));
|
|
126
|
+
settledUpdate.setProperty(rt, "style", std::move(settledStyle));
|
|
127
|
+
settledUpdate.setProperty(rt, "keysLastWrittenByAnimatedStyle", std::move(keysLastWrittenByAnimatedStyleArray));
|
|
128
|
+
return settledUpdate;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
jsi::Value AnimatedPropsRegistry::collectSettledUpdates(
|
|
132
|
+
jsi::Runtime &rt,
|
|
133
|
+
const double settledTimestamp,
|
|
134
|
+
const std::unordered_set<Tag> ®isteredViewTags) {
|
|
55
135
|
react_native_assert(UpdatesRegistryManager::isLockedByCurrentThread());
|
|
56
136
|
|
|
57
|
-
std::vector<
|
|
137
|
+
std::vector<jsi::Object> settledUpdates;
|
|
138
|
+
const auto pendingTags = getPendingTags();
|
|
58
139
|
|
|
59
140
|
for (auto it = updatesRegistry_.begin(); it != updatesRegistry_.end();) {
|
|
60
141
|
const auto viewTag = it->first;
|
|
61
142
|
|
|
143
|
+
if (!registeredViewTags.contains(viewTag) || pendingTags.contains(viewTag)) {
|
|
144
|
+
++it;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
|
|
62
148
|
if (syncedTags_.contains(viewTag)) {
|
|
63
149
|
// React already has the latest value for this tag (synced on a previous
|
|
64
150
|
// call, so the `settledProps` state is committed by now) — the registry
|
|
65
151
|
// entry is redundant. `syncedTags_` is intentionally retained to detect
|
|
66
152
|
// re-animation staleness. Note that `syncedTags_` and `invalidatedTags_`
|
|
67
153
|
// are disjoint — `update()` moves tags from the former to the latter.
|
|
68
|
-
timestampMap_.erase(viewTag);
|
|
69
154
|
it = updatesRegistry_.erase(it);
|
|
70
155
|
continue;
|
|
71
156
|
}
|
|
72
157
|
|
|
73
|
-
const auto
|
|
74
|
-
if (
|
|
158
|
+
const auto writeHistoryIt = writeHistories_.find(viewTag);
|
|
159
|
+
if (writeHistoryIt == writeHistories_.end()) {
|
|
75
160
|
++it;
|
|
76
161
|
continue;
|
|
77
162
|
}
|
|
78
|
-
const
|
|
163
|
+
const auto &writeHistory = writeHistoryIt->second;
|
|
164
|
+
const bool isSettled = writeHistory.lastWriteTimestamp < settledTimestamp;
|
|
79
165
|
const auto invalidatedIt = invalidatedTags_.find(viewTag);
|
|
80
166
|
const bool isInvalidated = invalidatedIt != invalidatedTags_.end();
|
|
81
167
|
if (isSettled || isInvalidated) {
|
|
82
|
-
|
|
168
|
+
settledUpdates.push_back(createSettledUpdate(rt, viewTag, it->second.second, writeHistory));
|
|
83
169
|
if (isSettled) {
|
|
84
170
|
// Only settled-path tags are tracked as "synced" so that an ongoing
|
|
85
171
|
// animation doesn't re-trigger an invalidation/sync on every GC tick.
|
|
86
172
|
syncedTags_.insert(viewTag);
|
|
87
173
|
}
|
|
88
174
|
if (isInvalidated) {
|
|
89
|
-
// Only erase serviced invalidations; if a tag was invalidated but the
|
|
90
|
-
// matching update batch hasn't been flushed into updatesRegistry_ yet,
|
|
91
|
-
// we leave the entry so the next sync picks it up.
|
|
92
175
|
invalidatedTags_.erase(invalidatedIt);
|
|
93
176
|
}
|
|
94
177
|
}
|
|
95
178
|
++it;
|
|
96
179
|
}
|
|
97
180
|
|
|
98
|
-
const jsi::Array array(rt,
|
|
99
|
-
size_t i = 0;
|
|
100
|
-
|
|
101
|
-
const jsi::Object item(rt);
|
|
102
|
-
item.setProperty(rt, "viewTag", viewTag);
|
|
103
|
-
item.setProperty(rt, "styleProps", jsi::valueFromDynamic(rt, styleProps.get()));
|
|
104
|
-
array.setValueAtIndex(rt, i++, item);
|
|
181
|
+
const jsi::Array array(rt, settledUpdates.size());
|
|
182
|
+
for (size_t i = 0; i < settledUpdates.size(); ++i) {
|
|
183
|
+
array.setValueAtIndex(rt, i, std::move(settledUpdates[i]));
|
|
105
184
|
}
|
|
106
185
|
|
|
107
186
|
return jsi::Value(rt, array);
|
|
108
187
|
}
|
|
109
188
|
|
|
189
|
+
void AnimatedPropsRegistry::removeUnmounted(const ShadowNodeFamily::Shared &shadowNodeFamily) {
|
|
190
|
+
UpdatesRegistry::removeUnmounted(shadowNodeFamily);
|
|
191
|
+
const auto tag = shadowNodeFamily->getTag();
|
|
192
|
+
unmountedFamilies_[tag] = shadowNodeFamily;
|
|
193
|
+
if (unmountedFamilies_.size() >= unmountedFamiliesPruneThreshold_) {
|
|
194
|
+
pruneExpiredUnmountedFamilies();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
void AnimatedPropsRegistry::handleRemount(const Tag tag) {
|
|
199
|
+
unmountedFamilies_.erase(tag);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
bool AnimatedPropsRegistry::isUnmounted(const ShadowNodeFamily &shadowNodeFamily) const {
|
|
203
|
+
const auto it = unmountedFamilies_.find(shadowNodeFamily.getTag());
|
|
204
|
+
return it != unmountedFamilies_.end() && it->second.lock().get() == &shadowNodeFamily;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
void AnimatedPropsRegistry::pruneExpiredUnmountedFamilies() {
|
|
208
|
+
std::erase_if(unmountedFamilies_, [](const auto &entry) { return entry.second.expired(); });
|
|
209
|
+
unmountedFamiliesPruneThreshold_ = std::max(MIN_UNMOUNTED_FAMILIES_PRUNE_THRESHOLD, 2 * unmountedFamilies_.size());
|
|
210
|
+
}
|
|
211
|
+
|
|
110
212
|
void AnimatedPropsRegistry::removeTag(const Tag tag) {
|
|
111
213
|
updatesRegistry_.erase(tag);
|
|
112
|
-
|
|
214
|
+
writeHistories_.erase(tag);
|
|
113
215
|
syncedTags_.erase(tag);
|
|
114
216
|
invalidatedTags_.erase(tag);
|
|
115
217
|
}
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
#include <react/renderer/uimanager/UIManager.h>
|
|
6
6
|
|
|
7
|
+
#include <memory>
|
|
8
|
+
#include <string>
|
|
7
9
|
#include <unordered_map>
|
|
8
10
|
#include <unordered_set>
|
|
9
11
|
|
|
@@ -15,20 +17,52 @@ class AnimatedPropsRegistry : public UpdatesRegistry {
|
|
|
15
17
|
|
|
16
18
|
/// Returns updates that settled (received no update since `settledTimestamp`)
|
|
17
19
|
/// or whose synced `settledProps` snapshot was invalidated by a fresh update.
|
|
20
|
+
/// Skips tags with updates not yet flushed into the registry.
|
|
18
21
|
/// Also evicts entries that have already been synced to React — by the time
|
|
19
22
|
/// of the next call, the corresponding `settledProps` state is guaranteed to
|
|
20
|
-
/// be committed, so the registry entries are redundant.
|
|
21
|
-
|
|
23
|
+
/// be committed, so the registry entries are redundant. Skips views that JS
|
|
24
|
+
/// cannot deliver to, e.g. ones hidden by a Suspense boundary.
|
|
25
|
+
jsi::Value
|
|
26
|
+
collectSettledUpdates(jsi::Runtime &rt, double settledTimestamp, const std::unordered_set<Tag> ®isteredViewTags);
|
|
27
|
+
|
|
28
|
+
void removeUnmounted(const ShadowNodeFamily::Shared &shadowNodeFamily) override;
|
|
29
|
+
void handleRemount(Tag tag) override;
|
|
22
30
|
|
|
23
31
|
private:
|
|
24
|
-
|
|
32
|
+
static constexpr size_t MIN_UNMOUNTED_FAMILIES_PRUNE_THRESHOLD = 256;
|
|
33
|
+
|
|
34
|
+
struct KeyOrigins {
|
|
35
|
+
bool writtenByAnimatedProps = false;
|
|
36
|
+
bool writtenByAnimatedStyle = false;
|
|
37
|
+
bool lastWrittenByAnimatedStyle = false;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
struct WriteHistory {
|
|
41
|
+
double lastWriteTimestamp = 0;
|
|
42
|
+
std::unordered_map<std::string, KeyOrigins> keyOrigins;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Kept after eviction of the registry entry, until `removeTag`. Each sync
|
|
46
|
+
// must send a key to the same React fields as the syncs before it.
|
|
47
|
+
std::unordered_map<Tag, WriteHistory> writeHistories_;
|
|
25
48
|
// Tags whose latest values have already been pushed to React `settledProps`.
|
|
26
49
|
// Intentionally retained after eviction to detect re-animation staleness.
|
|
27
50
|
std::unordered_set<Tag> syncedTags_;
|
|
28
51
|
// Tags that were synced to React but received a fresh worklet update since;
|
|
29
52
|
// their `settledProps` are stale and need to be refreshed on the next sync.
|
|
30
53
|
std::unordered_set<Tag> invalidatedTags_;
|
|
54
|
+
// A mapper can still update a view for a few frames after the view left the
|
|
55
|
+
// shadow tree. Such updates must not add the view to the registry again.
|
|
56
|
+
std::unordered_map<Tag, std::weak_ptr<const ShadowNodeFamily>> unmountedFamilies_;
|
|
57
|
+
size_t unmountedFamiliesPruneThreshold_ = MIN_UNMOUNTED_FAMILIES_PRUNE_THRESHOLD;
|
|
58
|
+
|
|
59
|
+
bool isUnmounted(const ShadowNodeFamily &shadowNodeFamily) const;
|
|
60
|
+
void pruneExpiredUnmountedFamilies();
|
|
31
61
|
|
|
62
|
+
void trackUpdate(Tag tag, const folly::dynamic &updates, bool isAnimatedProps, double timestamp);
|
|
63
|
+
void invalidateSyncedTag(Tag tag);
|
|
64
|
+
static jsi::Object
|
|
65
|
+
createSettledUpdate(jsi::Runtime &rt, Tag viewTag, const folly::dynamic &props, const WriteHistory &writeHistory);
|
|
32
66
|
void removeTag(Tag tag) override;
|
|
33
67
|
};
|
|
34
68
|
|
|
@@ -57,6 +57,12 @@ void UpdatesRegistry::remove(const Tag tag) {
|
|
|
57
57
|
removeTag(tag);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
void UpdatesRegistry::removeUnmounted(const ShadowNodeFamily::Shared &shadowNodeFamily) {
|
|
61
|
+
const auto tag = shadowNodeFamily->getTag();
|
|
62
|
+
remove(tag);
|
|
63
|
+
removePendingUpdates(tag);
|
|
64
|
+
}
|
|
65
|
+
|
|
60
66
|
void UpdatesRegistry::flushUpdates(UpdatesBatch &updatesBatch) {
|
|
61
67
|
react_native_assert(UpdatesRegistryManager::isLockedByCurrentThread());
|
|
62
68
|
flush(updatesBatch);
|
|
@@ -218,6 +224,15 @@ void UpdatesRegistry::addUpdatesToBatch(const ShadowNodeFamily::Shared &shadowNo
|
|
|
218
224
|
updatesBatch_.emplace_back(shadowNodeFamily, props);
|
|
219
225
|
}
|
|
220
226
|
|
|
227
|
+
std::unordered_set<Tag> UpdatesRegistry::getPendingTags() const {
|
|
228
|
+
react_native_assert(UpdatesRegistryManager::isLockedByCurrentThread());
|
|
229
|
+
std::unordered_set<Tag> pendingTags;
|
|
230
|
+
for (const auto &[shadowNodeFamily, _] : updatesBatch_) {
|
|
231
|
+
pendingTags.insert(shadowNodeFamily->getTag());
|
|
232
|
+
}
|
|
233
|
+
return pendingTags;
|
|
234
|
+
}
|
|
235
|
+
|
|
221
236
|
void UpdatesRegistry::setInUpdatesRegistry(
|
|
222
237
|
const ShadowNodeFamily::Shared &shadowNodeFamily,
|
|
223
238
|
const folly::dynamic &props) {
|
|
@@ -243,6 +258,19 @@ void UpdatesRegistry::removeFromUpdatesRegistry(const Tag tag) {
|
|
|
243
258
|
updatesRegistry_.erase(tag);
|
|
244
259
|
}
|
|
245
260
|
|
|
261
|
+
void UpdatesRegistry::removePendingUpdates(const Tag tag) {
|
|
262
|
+
std::erase_if(updatesBatch_, [tag](const auto &update) { return update.first->getTag() == tag; });
|
|
263
|
+
|
|
264
|
+
UpdatesBatchAnimatedProps remaining;
|
|
265
|
+
remaining.reserve(updatesBatchAnimatedProps_.size());
|
|
266
|
+
for (auto &entry : updatesBatchAnimatedProps_) {
|
|
267
|
+
if (entry.shadowNodeFamily->getTag() != tag) {
|
|
268
|
+
remaining.push_back(std::move(entry));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
updatesBatchAnimatedProps_ = std::move(remaining);
|
|
272
|
+
}
|
|
273
|
+
|
|
246
274
|
void UpdatesRegistry::flushUpdatesToRegistry(const UpdatesBatch &updatesBatch) {
|
|
247
275
|
for (auto &[shadowNodeFamily, props] : updatesBatch) {
|
|
248
276
|
const auto tag = shadowNodeFamily->getTag();
|
|
@@ -54,6 +54,8 @@ class UpdatesRegistry {
|
|
|
54
54
|
void mergeInto(Tag tag, folly::dynamic &target, PropNamePredicate isIncluded) const;
|
|
55
55
|
#endif
|
|
56
56
|
void remove(Tag tag);
|
|
57
|
+
virtual void removeUnmounted(const ShadowNodeFamily::Shared &shadowNodeFamily);
|
|
58
|
+
virtual void handleRemount(Tag /*tag*/) {}
|
|
57
59
|
|
|
58
60
|
#ifdef ANDROID
|
|
59
61
|
bool hasPropsToRevert() const;
|
|
@@ -97,6 +99,9 @@ class UpdatesRegistry {
|
|
|
97
99
|
/// Assumes the caller already locked the registry.
|
|
98
100
|
void addUpdatesToBatch(const ShadowNodeFamily::Shared &shadowNodeFamily, const folly::dynamic &props);
|
|
99
101
|
|
|
102
|
+
/// Assumes the caller already locked the registry.
|
|
103
|
+
std::unordered_set<Tag> getPendingTags() const;
|
|
104
|
+
|
|
100
105
|
/// Assumes the caller already locked the registry.
|
|
101
106
|
folly::dynamic getUpdatesFromRegistry(const Tag tag) const;
|
|
102
107
|
|
|
@@ -106,6 +111,9 @@ class UpdatesRegistry {
|
|
|
106
111
|
/// Assumes the caller already locked the registry.
|
|
107
112
|
void removeFromUpdatesRegistry(Tag tag);
|
|
108
113
|
|
|
114
|
+
/// Assumes the caller already locked the registry.
|
|
115
|
+
void removePendingUpdates(Tag tag);
|
|
116
|
+
|
|
109
117
|
private:
|
|
110
118
|
UpdatesBatch updatesBatch_;
|
|
111
119
|
|
|
@@ -73,6 +73,9 @@ void UpdatesRegistryManager::markNodeAsRemovable(const std::shared_ptr<const Sha
|
|
|
73
73
|
void UpdatesRegistryManager::unmarkNodeAsRemovable(Tag viewTag) {
|
|
74
74
|
react_native_assert(isLockedByCurrentThread());
|
|
75
75
|
removableShadowNodes_.erase(viewTag);
|
|
76
|
+
for (auto ®istry : registries_) {
|
|
77
|
+
registry->handleRemount(viewTag);
|
|
78
|
+
}
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
void UpdatesRegistryManager::handleNodeRemovals(const RootShadowNode &rootShadowNode) {
|
|
@@ -86,7 +89,7 @@ void UpdatesRegistryManager::handleNodeRemovals(const RootShadowNode &rootShadow
|
|
|
86
89
|
|
|
87
90
|
if (shadowNodeFamily->getAncestors(rootShadowNode).empty()) {
|
|
88
91
|
for (auto ®istry : registries_) {
|
|
89
|
-
registry->
|
|
92
|
+
registry->removeUnmounted(shadowNodeFamily);
|
|
90
93
|
}
|
|
91
94
|
staticPropsRegistry_->remove(tag);
|
|
92
95
|
} else {
|