react-native-reanimated 4.7.0 → 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/ReanimatedCommitHook.cpp +34 -2
- package/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.h +15 -1
- package/Common/cpp/reanimated/Fabric/ReanimatedMountHook.cpp +9 -0
- package/Common/cpp/reanimated/Fabric/ReanimatedMountHook.h +3 -0
- 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/SynchronousWritesTracker.cpp +103 -0
- package/Common/cpp/reanimated/Fabric/updates/SynchronousWritesTracker.h +74 -0
- package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.cpp +43 -0
- package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.h +13 -0
- package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistryManager.cpp +14 -1
- package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistryManager.h +3 -0
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp +318 -134
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h +27 -6
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.cpp +32 -17
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.h +17 -1
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.cpp +14 -13
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.h +5 -2
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +57 -9
- package/Common/cpp/reanimated/LayoutAnimations/PropsDiffer.h +2 -2
- package/Common/cpp/reanimated/LayoutAnimations/SharedTransitions.cpp +11 -11
- package/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +114 -11
- package/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h +12 -2
- package/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h +17 -1
- package/Common/cpp/reanimated/Tools/TextMetrics.h +22 -0
- package/android/src/main/cpp/reanimated/android/NativeProxy.cpp +32 -3
- package/android/src/main/cpp/reanimated/android/NativeProxy.h +3 -0
- package/android/src/main/java/com/swmansion/reanimated/NativeProxy.kt +108 -9
- package/android/src/main/java/com/swmansion/reanimated/NodesManager.kt +2 -4
- package/android/src/main/java/com/swmansion/reanimated/nativeProxy/EventHandler.kt +4 -3
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensor.kt +1 -1
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.kt +44 -33
- package/apple/reanimated/apple/REAReducedMotion.h +1 -3
- package/apple/reanimated/apple/REASynchronousPropsRewriter.h +18 -0
- package/apple/reanimated/apple/REASynchronousPropsRewriter.mm +37 -0
- package/apple/reanimated/apple/ReanimatedModule.mm +7 -0
- package/apple/reanimated/apple/keyboardObserver/REAKeyboardEventObserver.mm +20 -3
- package/apple/reanimated/apple/native/PlatformDepMethodsHolderImpl.mm +52 -1
- 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/animation/timing.js +15 -2
- package/lib/module/animation/timing.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/animation/timing.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 +9 -7
- package/src/PropsRegistryGarbageCollector.ts +46 -25
- package/src/ReanimatedModule/NativeReanimated.ts +2 -2
- package/src/ReanimatedModule/reanimatedModuleProxy.ts +1 -1
- package/src/animation/timing.ts +20 -2
- 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
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <reanimated/Fabric/updates/UpdatesRegistry.h>
|
|
4
|
+
|
|
5
|
+
#include <react/renderer/components/root/RootShadowNode.h>
|
|
6
|
+
#include <react/renderer/core/ShadowNodeFamily.h>
|
|
7
|
+
|
|
8
|
+
#include <cstdint>
|
|
9
|
+
#include <deque>
|
|
10
|
+
#include <memory>
|
|
11
|
+
#include <mutex>
|
|
12
|
+
#include <thread>
|
|
13
|
+
#include <unordered_map>
|
|
14
|
+
#include <vector>
|
|
15
|
+
|
|
16
|
+
using namespace facebook::react;
|
|
17
|
+
|
|
18
|
+
namespace reanimated {
|
|
19
|
+
|
|
20
|
+
// A React commit takes its animated values from the registries in the commit hook, but the platform can mount it
|
|
21
|
+
// after newer synchronous writes. This class keeps the views with such writes until every such commit is mounted, so
|
|
22
|
+
// that the platform can write their current values again after a mount.
|
|
23
|
+
class SynchronousWritesTracker {
|
|
24
|
+
public:
|
|
25
|
+
void onWillCommit(const RootShadowNode::Shared &rootShadowNode, bool carriesRegistryValues);
|
|
26
|
+
void onDidCommit(const RootShadowNode::Shared &rootShadowNode);
|
|
27
|
+
void onSynchronousWrite(const UpdatesBatch &synchronousUpdatesBatch);
|
|
28
|
+
void onMountReport(const RootShadowNode::Shared &mountedRootShadowNode);
|
|
29
|
+
void onSurfaceStop(SurfaceId surfaceId);
|
|
30
|
+
std::vector<ShadowNodeFamily::Shared> getFamiliesToRewrite() const;
|
|
31
|
+
void onRewrite();
|
|
32
|
+
|
|
33
|
+
private:
|
|
34
|
+
using Epoch = uint64_t;
|
|
35
|
+
|
|
36
|
+
struct CommittedRoot {
|
|
37
|
+
std::weak_ptr<const RootShadowNode> rootShadowNode;
|
|
38
|
+
Epoch epoch;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
struct Write {
|
|
42
|
+
ShadowNodeFamily::Shared shadowNodeFamily;
|
|
43
|
+
Epoch epoch;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
struct PendingCommit {
|
|
47
|
+
SurfaceId surfaceId;
|
|
48
|
+
Epoch epoch;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
struct SurfaceState {
|
|
52
|
+
// Number of commits that carried registry values. A write with epoch N is newer than the values in commits 1..N.
|
|
53
|
+
Epoch epoch{0};
|
|
54
|
+
// Android reports a mount at the pull, before the mount items run. The next mount callback writes the props
|
|
55
|
+
// again. That callback also runs for a dispatch that has only view commands. If such a dispatch runs before the
|
|
56
|
+
// mount items, the tracker removes the writes too early. The old value then stays on screen until the next
|
|
57
|
+
// synchronous write.
|
|
58
|
+
Epoch reportedEpoch{0};
|
|
59
|
+
Epoch mountedEpoch{0};
|
|
60
|
+
std::deque<CommittedRoot> committedRoots;
|
|
61
|
+
std::unordered_map<Tag, Write> writes;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
static void rememberRoot(SurfaceState &surface, const RootShadowNode::Shared &rootShadowNode, Epoch epoch);
|
|
65
|
+
|
|
66
|
+
mutable std::mutex mutex_;
|
|
67
|
+
// Carries the epoch from `onWillCommit` (known at the registry read) to `onDidCommit` (final root, after all
|
|
68
|
+
// hooks). Both run on the committing thread, but commits on different threads can overlap on one surface, so
|
|
69
|
+
// the key is the thread. A failed or cancelled commit gets no `onDidCommit`; `onWillCommit` drops its entry.
|
|
70
|
+
std::unordered_map<std::thread::id, PendingCommit> pendingCommits_;
|
|
71
|
+
std::unordered_map<SurfaceId, SurfaceState> surfaces_;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
} // namespace reanimated
|
|
@@ -37,11 +37,32 @@ void UpdatesRegistry::mergeInto(const Tag tag, folly::dynamic &target) const {
|
|
|
37
37
|
target.update(it->second.second);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
#ifdef ANDROID
|
|
41
|
+
void UpdatesRegistry::mergeInto(const Tag tag, folly::dynamic &target, const PropNamePredicate isIncluded) const {
|
|
42
|
+
react_native_assert(UpdatesRegistryManager::isLockedByCurrentThread());
|
|
43
|
+
auto it = updatesRegistry_.find(tag);
|
|
44
|
+
if (it == updatesRegistry_.cend()) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
for (const auto &[name, value] : it->second.second.items()) {
|
|
48
|
+
if (isIncluded(name.getString())) {
|
|
49
|
+
target[name] = value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
#endif // ANDROID
|
|
54
|
+
|
|
40
55
|
void UpdatesRegistry::remove(const Tag tag) {
|
|
41
56
|
react_native_assert(UpdatesRegistryManager::isLockedByCurrentThread());
|
|
42
57
|
removeTag(tag);
|
|
43
58
|
}
|
|
44
59
|
|
|
60
|
+
void UpdatesRegistry::removeUnmounted(const ShadowNodeFamily::Shared &shadowNodeFamily) {
|
|
61
|
+
const auto tag = shadowNodeFamily->getTag();
|
|
62
|
+
remove(tag);
|
|
63
|
+
removePendingUpdates(tag);
|
|
64
|
+
}
|
|
65
|
+
|
|
45
66
|
void UpdatesRegistry::flushUpdates(UpdatesBatch &updatesBatch) {
|
|
46
67
|
react_native_assert(UpdatesRegistryManager::isLockedByCurrentThread());
|
|
47
68
|
flush(updatesBatch);
|
|
@@ -203,6 +224,15 @@ void UpdatesRegistry::addUpdatesToBatch(const ShadowNodeFamily::Shared &shadowNo
|
|
|
203
224
|
updatesBatch_.emplace_back(shadowNodeFamily, props);
|
|
204
225
|
}
|
|
205
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
|
+
|
|
206
236
|
void UpdatesRegistry::setInUpdatesRegistry(
|
|
207
237
|
const ShadowNodeFamily::Shared &shadowNodeFamily,
|
|
208
238
|
const folly::dynamic &props) {
|
|
@@ -228,6 +258,19 @@ void UpdatesRegistry::removeFromUpdatesRegistry(const Tag tag) {
|
|
|
228
258
|
updatesRegistry_.erase(tag);
|
|
229
259
|
}
|
|
230
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
|
+
|
|
231
274
|
void UpdatesRegistry::flushUpdatesToRegistry(const UpdatesBatch &updatesBatch) {
|
|
232
275
|
for (auto &[shadowNodeFamily, props] : updatesBatch) {
|
|
233
276
|
const auto tag = shadowNodeFamily->getTag();
|
|
@@ -29,6 +29,8 @@ struct AnimatedPropsEntry {
|
|
|
29
29
|
};
|
|
30
30
|
using UpdatesBatchAnimatedProps = std::vector<AnimatedPropsEntry>;
|
|
31
31
|
|
|
32
|
+
using PropNamePredicate = bool (*)(const std::string &);
|
|
33
|
+
|
|
32
34
|
using RegistryMap = std::unordered_map<Tag, std::pair<ShadowNodeFamily::Shared, folly::dynamic>>;
|
|
33
35
|
|
|
34
36
|
#ifdef ANDROID
|
|
@@ -48,7 +50,12 @@ class UpdatesRegistry {
|
|
|
48
50
|
virtual bool isEmpty() const;
|
|
49
51
|
folly::dynamic get(Tag tag) const;
|
|
50
52
|
void mergeInto(Tag tag, folly::dynamic &target) const;
|
|
53
|
+
#ifdef ANDROID
|
|
54
|
+
void mergeInto(Tag tag, folly::dynamic &target, PropNamePredicate isIncluded) const;
|
|
55
|
+
#endif
|
|
51
56
|
void remove(Tag tag);
|
|
57
|
+
virtual void removeUnmounted(const ShadowNodeFamily::Shared &shadowNodeFamily);
|
|
58
|
+
virtual void handleRemount(Tag /*tag*/) {}
|
|
52
59
|
|
|
53
60
|
#ifdef ANDROID
|
|
54
61
|
bool hasPropsToRevert() const;
|
|
@@ -92,6 +99,9 @@ class UpdatesRegistry {
|
|
|
92
99
|
/// Assumes the caller already locked the registry.
|
|
93
100
|
void addUpdatesToBatch(const ShadowNodeFamily::Shared &shadowNodeFamily, const folly::dynamic &props);
|
|
94
101
|
|
|
102
|
+
/// Assumes the caller already locked the registry.
|
|
103
|
+
std::unordered_set<Tag> getPendingTags() const;
|
|
104
|
+
|
|
95
105
|
/// Assumes the caller already locked the registry.
|
|
96
106
|
folly::dynamic getUpdatesFromRegistry(const Tag tag) const;
|
|
97
107
|
|
|
@@ -101,6 +111,9 @@ class UpdatesRegistry {
|
|
|
101
111
|
/// Assumes the caller already locked the registry.
|
|
102
112
|
void removeFromUpdatesRegistry(Tag tag);
|
|
103
113
|
|
|
114
|
+
/// Assumes the caller already locked the registry.
|
|
115
|
+
void removePendingUpdates(Tag tag);
|
|
116
|
+
|
|
104
117
|
private:
|
|
105
118
|
UpdatesBatch updatesBatch_;
|
|
106
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 {
|
|
@@ -115,6 +118,16 @@ void UpdatesRegistryManager::mergeRegistryProps(const Tag viewTag, folly::dynami
|
|
|
115
118
|
|
|
116
119
|
#ifdef ANDROID
|
|
117
120
|
|
|
121
|
+
void UpdatesRegistryManager::mergeRegistryProps(
|
|
122
|
+
const Tag viewTag,
|
|
123
|
+
folly::dynamic &target,
|
|
124
|
+
const PropNamePredicate isIncluded) {
|
|
125
|
+
react_native_assert(isLockedByCurrentThread());
|
|
126
|
+
for (const auto ®istry : registries_) {
|
|
127
|
+
registry->mergeInto(viewTag, target, isIncluded);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
118
131
|
bool UpdatesRegistryManager::hasPropsToRevert() {
|
|
119
132
|
react_native_assert(isLockedByCurrentThread());
|
|
120
133
|
for (auto ®istry : registries_) {
|
|
@@ -49,6 +49,9 @@ class UpdatesRegistryManager {
|
|
|
49
49
|
void handleNodeRemovals(const RootShadowNode &rootShadowNode);
|
|
50
50
|
PropsMap collectProps();
|
|
51
51
|
void mergeRegistryProps(Tag viewTag, folly::dynamic &target);
|
|
52
|
+
#ifdef ANDROID
|
|
53
|
+
void mergeRegistryProps(Tag viewTag, folly::dynamic &target, PropNamePredicate isIncluded);
|
|
54
|
+
#endif
|
|
52
55
|
|
|
53
56
|
#ifdef ANDROID
|
|
54
57
|
bool hasPropsToRevert();
|