react-native-reanimated 3.0.0-rc.7 → 3.0.0-rc.8

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.
Files changed (177) hide show
  1. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +32 -37
  2. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.h +4 -3
  3. package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp +76 -0
  4. package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.h +41 -0
  5. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +161 -165
  6. package/Common/cpp/NativeModules/NativeReanimatedModule.h +36 -34
  7. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +22 -34
  8. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.h +13 -14
  9. package/Common/cpp/SharedItems/RuntimeManager.h +1 -34
  10. package/Common/cpp/SharedItems/Shareables.cpp +142 -0
  11. package/Common/cpp/SharedItems/Shareables.h +455 -0
  12. package/Common/cpp/Tools/PlatformDepMethodsHolder.h +6 -0
  13. package/Common/cpp/Tools/RuntimeDecorator.cpp +54 -26
  14. package/Common/cpp/Tools/RuntimeDecorator.h +11 -2
  15. package/Common/cpp/Tools/Scheduler.cpp +10 -0
  16. package/Common/cpp/Tools/SingleInstanceChecker.h +1 -1
  17. package/android/src/main/cpp/LayoutAnimations.cpp +6 -16
  18. package/android/src/main/cpp/LayoutAnimations.h +4 -4
  19. package/android/src/main/cpp/NativeProxy.cpp +50 -63
  20. package/ios/native/NativeProxy.mm +26 -42
  21. package/lib/commonjs/createAnimatedComponent.js +7 -11
  22. package/lib/commonjs/createAnimatedComponent.js.map +1 -1
  23. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +24 -25
  24. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  25. package/lib/commonjs/reanimated2/ViewDescriptorsSet.js +27 -55
  26. package/lib/commonjs/reanimated2/ViewDescriptorsSet.js.map +1 -1
  27. package/lib/commonjs/reanimated2/WorkletEventHandler.js +5 -3
  28. package/lib/commonjs/reanimated2/WorkletEventHandler.js.map +1 -1
  29. package/lib/commonjs/reanimated2/animation/util.js.map +1 -1
  30. package/lib/commonjs/reanimated2/commonTypes.js +7 -0
  31. package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
  32. package/lib/commonjs/reanimated2/core.js +111 -209
  33. package/lib/commonjs/reanimated2/core.js.map +1 -1
  34. package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
  35. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js +15 -9
  36. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  37. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js +18 -8
  38. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js.map +1 -1
  39. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +27 -36
  40. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  41. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js +24 -50
  42. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  43. package/lib/commonjs/reanimated2/hook/useSharedValue.js +3 -2
  44. package/lib/commonjs/reanimated2/hook/useSharedValue.js.map +1 -1
  45. package/lib/commonjs/reanimated2/hook/utils.js.map +1 -1
  46. package/lib/commonjs/reanimated2/interpolateColor.js.map +1 -1
  47. package/lib/commonjs/reanimated2/jestUtils.js +8 -33
  48. package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
  49. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js +16 -100
  50. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  51. package/lib/commonjs/reanimated2/js-reanimated/index.js +5 -0
  52. package/lib/commonjs/reanimated2/js-reanimated/index.js.map +1 -1
  53. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  54. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  55. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +91 -0
  56. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -0
  57. package/lib/commonjs/reanimated2/layoutReanimation/index.js +1 -1
  58. package/lib/commonjs/reanimated2/layoutReanimation/index.js.map +1 -1
  59. package/lib/commonjs/reanimated2/mappers.js +186 -0
  60. package/lib/commonjs/reanimated2/mappers.js.map +1 -0
  61. package/lib/commonjs/reanimated2/mutables.js +173 -0
  62. package/lib/commonjs/reanimated2/mutables.js.map +1 -0
  63. package/lib/commonjs/reanimated2/shareables.js +153 -0
  64. package/lib/commonjs/reanimated2/shareables.js.map +1 -0
  65. package/lib/commonjs/reanimated2/threads.js +58 -0
  66. package/lib/commonjs/reanimated2/threads.js.map +1 -0
  67. package/lib/commonjs/reanimated2/time.js +55 -0
  68. package/lib/commonjs/reanimated2/time.js.map +1 -0
  69. package/lib/commonjs/reanimated2/valueSetter.js +81 -0
  70. package/lib/commonjs/reanimated2/valueSetter.js.map +1 -0
  71. package/lib/module/createAnimatedComponent.js +7 -12
  72. package/lib/module/createAnimatedComponent.js.map +1 -1
  73. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +24 -25
  74. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  75. package/lib/module/reanimated2/ViewDescriptorsSet.js +27 -53
  76. package/lib/module/reanimated2/ViewDescriptorsSet.js.map +1 -1
  77. package/lib/module/reanimated2/WorkletEventHandler.js +4 -3
  78. package/lib/module/reanimated2/WorkletEventHandler.js.map +1 -1
  79. package/lib/module/reanimated2/animation/util.js.map +1 -1
  80. package/lib/module/reanimated2/commonTypes.js +7 -0
  81. package/lib/module/reanimated2/commonTypes.js.map +1 -1
  82. package/lib/module/reanimated2/core.js +66 -188
  83. package/lib/module/reanimated2/core.js.map +1 -1
  84. package/lib/module/reanimated2/globals.d.js.map +1 -1
  85. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +16 -6
  86. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  87. package/lib/module/reanimated2/hook/useAnimatedRef.js +17 -8
  88. package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
  89. package/lib/module/reanimated2/hook/useAnimatedSensor.js +29 -34
  90. package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  91. package/lib/module/reanimated2/hook/useAnimatedStyle.js +26 -52
  92. package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  93. package/lib/module/reanimated2/hook/useSharedValue.js +3 -2
  94. package/lib/module/reanimated2/hook/useSharedValue.js.map +1 -1
  95. package/lib/module/reanimated2/hook/utils.js.map +1 -1
  96. package/lib/module/reanimated2/interpolateColor.js.map +1 -1
  97. package/lib/module/reanimated2/jestUtils.js +8 -31
  98. package/lib/module/reanimated2/jestUtils.js.map +1 -1
  99. package/lib/module/reanimated2/js-reanimated/JSReanimated.js +16 -95
  100. package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  101. package/lib/module/reanimated2/js-reanimated/index.js +5 -0
  102. package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
  103. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  104. package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  105. package/lib/module/reanimated2/layoutReanimation/animationsManager.js +84 -0
  106. package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -0
  107. package/lib/module/reanimated2/layoutReanimation/index.js +1 -1
  108. package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
  109. package/lib/module/reanimated2/mappers.js +173 -0
  110. package/lib/module/reanimated2/mappers.js.map +1 -0
  111. package/lib/module/reanimated2/mutables.js +149 -0
  112. package/lib/module/reanimated2/mutables.js.map +1 -0
  113. package/lib/module/reanimated2/shareables.js +133 -0
  114. package/lib/module/reanimated2/shareables.js.map +1 -0
  115. package/lib/module/reanimated2/threads.js +45 -0
  116. package/lib/module/reanimated2/threads.js.map +1 -0
  117. package/lib/module/reanimated2/time.js +37 -0
  118. package/lib/module/reanimated2/time.js.map +1 -0
  119. package/lib/module/reanimated2/valueSetter.js +66 -0
  120. package/lib/module/reanimated2/valueSetter.js.map +1 -0
  121. package/package.json +1 -1
  122. package/plugin.js +31 -15
  123. package/src/createAnimatedComponent.tsx +8 -24
  124. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +34 -53
  125. package/src/reanimated2/ViewDescriptorsSet.ts +30 -69
  126. package/src/reanimated2/WorkletEventHandler.ts +4 -11
  127. package/src/reanimated2/animation/util.ts +1 -0
  128. package/src/reanimated2/commonTypes.ts +29 -4
  129. package/src/reanimated2/core.ts +103 -230
  130. package/src/reanimated2/globals.d.ts +26 -26
  131. package/src/reanimated2/hook/useAnimatedKeyboard.ts +18 -9
  132. package/src/reanimated2/hook/useAnimatedRef.ts +27 -9
  133. package/src/reanimated2/hook/useAnimatedSensor.ts +33 -31
  134. package/src/reanimated2/hook/useAnimatedStyle.ts +26 -64
  135. package/src/reanimated2/hook/useSharedValue.ts +6 -3
  136. package/src/reanimated2/hook/utils.ts +1 -1
  137. package/src/reanimated2/interpolateColor.ts +2 -2
  138. package/src/reanimated2/jestUtils.ts +14 -29
  139. package/src/reanimated2/js-reanimated/JSReanimated.ts +19 -93
  140. package/src/reanimated2/js-reanimated/index.ts +4 -0
  141. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +7 -0
  142. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -0
  143. package/src/reanimated2/layoutReanimation/animationsManager.ts +94 -0
  144. package/src/reanimated2/layoutReanimation/index.ts +1 -1
  145. package/src/reanimated2/mappers.ts +179 -0
  146. package/src/reanimated2/mutables.ts +151 -0
  147. package/src/reanimated2/shareables.ts +121 -0
  148. package/src/reanimated2/threads.ts +46 -0
  149. package/src/reanimated2/time.ts +30 -0
  150. package/src/reanimated2/valueSetter.ts +64 -0
  151. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +0 -127
  152. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.h +0 -56
  153. package/Common/cpp/Registries/MapperRegistry.cpp +0 -147
  154. package/Common/cpp/Registries/MapperRegistry.h +0 -29
  155. package/Common/cpp/Registries/WorkletsCache.cpp +0 -45
  156. package/Common/cpp/Registries/WorkletsCache.h +0 -24
  157. package/Common/cpp/SharedItems/FrozenObject.cpp +0 -35
  158. package/Common/cpp/SharedItems/FrozenObject.h +0 -36
  159. package/Common/cpp/SharedItems/HostFunctionHandler.h +0 -28
  160. package/Common/cpp/SharedItems/MutableValue.cpp +0 -134
  161. package/Common/cpp/SharedItems/MutableValue.h +0 -54
  162. package/Common/cpp/SharedItems/MutableValueSetterProxy.cpp +0 -47
  163. package/Common/cpp/SharedItems/MutableValueSetterProxy.h +0 -25
  164. package/Common/cpp/SharedItems/RemoteObject.cpp +0 -45
  165. package/Common/cpp/SharedItems/RemoteObject.h +0 -35
  166. package/Common/cpp/SharedItems/ShareableValue.cpp +0 -529
  167. package/Common/cpp/SharedItems/ShareableValue.h +0 -63
  168. package/Common/cpp/SharedItems/ValueWrapper.h +0 -183
  169. package/Common/cpp/Tools/JSIStoreValueUser.cpp +0 -55
  170. package/Common/cpp/Tools/JSIStoreValueUser.h +0 -37
  171. package/Common/cpp/Tools/Mapper.cpp +0 -86
  172. package/Common/cpp/Tools/Mapper.h +0 -51
  173. package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js +0 -58
  174. package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +0 -1
  175. package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js +0 -52
  176. package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +0 -1
  177. package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.ts +0 -49
@@ -1,127 +0,0 @@
1
- #include "LayoutAnimationsProxy.h"
2
- #include "FrozenObject.h"
3
- #include "MutableValue.h"
4
- #include "ShareableValue.h"
5
- #include "ValueWrapper.h"
6
-
7
- #include <utility>
8
-
9
- namespace reanimated {
10
-
11
- const long long idOffset = 1e9;
12
-
13
- LayoutAnimationsProxy::LayoutAnimationsProxy(
14
- std::function<void(int, jsi::Object newProps)> progressHandler,
15
- std::function<void(int, bool, bool)> endHandler,
16
- std::weak_ptr<ErrorHandler> weakErrorHandler)
17
- : progressHandler_(std::move(progressHandler)),
18
- endHandler_(std::move(endHandler)),
19
- weakErrorHandler_(weakErrorHandler) {}
20
-
21
- void LayoutAnimationsProxy::startObserving(
22
- int tag,
23
- std::shared_ptr<MutableValue> sv,
24
- jsi::Runtime &rt) {
25
- observedValues_[tag] = sv;
26
- this->progressHandler_(tag, sv->value->toJSValue(rt).asObject(rt));
27
- sv->addListener(tag + idOffset, [sv, tag, this, &rt]() {
28
- this->progressHandler_(tag, sv->value->toJSValue(rt).asObject(rt));
29
- });
30
- }
31
-
32
- void LayoutAnimationsProxy::stopObserving(
33
- int tag,
34
- bool finished,
35
- bool removeView) {
36
- if (observedValues_.count(tag) == 0) {
37
- return;
38
- }
39
- std::shared_ptr<MutableValue> sv = observedValues_[tag];
40
- sv->removeListener(tag + idOffset);
41
- observedValues_.erase(tag);
42
- this->endHandler_(tag, !finished, removeView);
43
- }
44
-
45
- void LayoutAnimationsProxy::configureAnimation(
46
- int tag,
47
- const std::string &type,
48
- std::shared_ptr<ShareableValue> config,
49
- std::shared_ptr<ShareableValue> viewSharedValue) {
50
- auto lock = std::unique_lock<std::mutex>(animationsMutex_);
51
- if (type == "entering") {
52
- enteringAnimations_[tag] = config;
53
- } else if (type == "exiting") {
54
- exitingAnimations_[tag] = config;
55
- } else if (type == "layout") {
56
- layoutAnimations_[tag] = config;
57
- }
58
- viewSharedValues_[tag] = viewSharedValue;
59
- }
60
-
61
- bool LayoutAnimationsProxy::hasLayoutAnimation(
62
- int tag,
63
- const std::string &type) {
64
- auto lock = std::unique_lock<std::mutex>(animationsMutex_);
65
- if (type == "entering") {
66
- return enteringAnimations_.find(tag) != enteringAnimations_.end();
67
- } else if (type == "exiting") {
68
- return exitingAnimations_.find(tag) != exitingAnimations_.end();
69
- } else if (type == "layout") {
70
- return layoutAnimations_.find(tag) != layoutAnimations_.end();
71
- }
72
- return false;
73
- }
74
-
75
- void LayoutAnimationsProxy::clearLayoutAnimationConfig(int tag) {
76
- auto lock = std::unique_lock<std::mutex>(animationsMutex_);
77
- enteringAnimations_.erase(tag);
78
- exitingAnimations_.erase(tag);
79
- layoutAnimations_.erase(tag);
80
- viewSharedValues_.erase(tag);
81
- }
82
-
83
- void LayoutAnimationsProxy::startLayoutAnimation(
84
- jsi::Runtime &rt,
85
- int tag,
86
- const std::string &type,
87
- const jsi::Object &values) {
88
- std::shared_ptr<ShareableValue> config;
89
- std::shared_ptr<ShareableValue> viewSharedValue;
90
- {
91
- auto lock = std::unique_lock<std::mutex>(animationsMutex_);
92
- if (type == "entering") {
93
- config = enteringAnimations_[tag];
94
- } else if (type == "exiting") {
95
- config = exitingAnimations_[tag];
96
- } else if (type == "layout") {
97
- config = layoutAnimations_[tag];
98
- }
99
- viewSharedValue = viewSharedValues_[tag];
100
- }
101
-
102
- jsi::Value layoutAnimationRepositoryAsValue =
103
- rt.global()
104
- .getPropertyAsObject(rt, "global")
105
- .getProperty(rt, "LayoutAnimationRepository");
106
- if (layoutAnimationRepositoryAsValue.isUndefined()) {
107
- auto errorHandler = weakErrorHandler_.lock();
108
- if (errorHandler != nullptr) {
109
- errorHandler->setError(
110
- "startLayoutAnimation called before initializing LayoutAnimationRepository");
111
- errorHandler->raise();
112
- }
113
- return;
114
- }
115
- jsi::Function startAnimationForTag =
116
- layoutAnimationRepositoryAsValue.getObject(rt).getPropertyAsFunction(
117
- rt, "startAnimationForTag");
118
- startAnimationForTag.call(
119
- rt,
120
- jsi::Value(tag),
121
- jsi::String::createFromAscii(rt, type),
122
- values,
123
- config->toJSValue(rt),
124
- viewSharedValue->toJSValue(rt));
125
- }
126
-
127
- } // namespace reanimated
@@ -1,56 +0,0 @@
1
- #pragma once
2
-
3
- #include <ErrorHandler.h>
4
- #include <jsi/jsi.h>
5
- #include <stdio.h>
6
- #include <functional>
7
- #include <memory>
8
- #include <mutex>
9
- #include <string>
10
- #include <unordered_map>
11
-
12
- namespace reanimated {
13
-
14
- using namespace facebook;
15
-
16
- class MutableValue;
17
- class ShareableValue;
18
-
19
- class LayoutAnimationsProxy {
20
- public:
21
- LayoutAnimationsProxy(
22
- std::function<void(int, jsi::Object newProps)> progressHandler,
23
- std::function<void(int, bool, bool)> endHandler,
24
- std::weak_ptr<ErrorHandler> weakErrorHandler);
25
-
26
- void
27
- startObserving(int tag, std::shared_ptr<MutableValue> sv, jsi::Runtime &rt);
28
- void stopObserving(int tag, bool finished, bool removeView);
29
- void configureAnimation(
30
- int tag,
31
- const std::string &type,
32
- std::shared_ptr<ShareableValue> config,
33
- std::shared_ptr<ShareableValue> viewSharedValue);
34
- bool hasLayoutAnimation(int tag, const std::string &type);
35
- void startLayoutAnimation(
36
- jsi::Runtime &rt,
37
- int tag,
38
- const std::string &type,
39
- const jsi::Object &values);
40
- void clearLayoutAnimationConfig(int tag);
41
-
42
- private:
43
- std::function<void(int, jsi::Object newProps)> progressHandler_;
44
- std::function<void(int, bool, bool)> endHandler_;
45
- std::weak_ptr<ErrorHandler> weakErrorHandler_;
46
- std::unordered_map<int, std::shared_ptr<MutableValue>> observedValues_;
47
- std::unordered_map<int, std::shared_ptr<ShareableValue>> viewSharedValues_;
48
- std::unordered_map<int, std::shared_ptr<ShareableValue>> enteringAnimations_;
49
- std::unordered_map<int, std::shared_ptr<ShareableValue>> exitingAnimations_;
50
- std::unordered_map<int, std::shared_ptr<ShareableValue>> layoutAnimations_;
51
- mutable std::mutex
52
- animationsMutex_; // Protects `enteringAnimations_`, `exitingAnimations_`,
53
- // `layoutAnimations_` and `viewSharedValues_`.
54
- };
55
-
56
- } // namespace reanimated
@@ -1,147 +0,0 @@
1
- #include "MapperRegistry.h"
2
- #include "Mapper.h"
3
-
4
- #include <array>
5
- #include <map>
6
- #include <set>
7
- #include <utility>
8
-
9
- namespace reanimated {
10
-
11
- void MapperRegistry::startMapper(std::shared_ptr<Mapper> mapper) {
12
- mappers[mapper->id] = mapper;
13
- updatedSinceLastExecute = true;
14
- }
15
-
16
- void MapperRegistry::stopMapper(unsigned long id) {
17
- mappers.erase(id);
18
- updatedSinceLastExecute = true;
19
- }
20
-
21
- void MapperRegistry::execute(jsi::Runtime &rt) {
22
- if (updatedSinceLastExecute) {
23
- updateOrder();
24
- updatedSinceLastExecute = false;
25
- }
26
- for (auto &mapper : sortedMappers) {
27
- if (mapper->dirty) {
28
- mapper->execute(rt);
29
- }
30
- }
31
- }
32
-
33
- bool MapperRegistry::needRunOnRender() {
34
- return updatedSinceLastExecute; // TODO: also run if input nodes are dirty
35
- }
36
-
37
- void MapperRegistry::updateOrder() { // Topological sorting
38
- sortedMappers.clear();
39
-
40
- struct NodeID {
41
- std::shared_ptr<Mapper> mapper;
42
- std::shared_ptr<MutableValue> mutableValue;
43
-
44
- explicit NodeID(std::shared_ptr<Mapper> mapper) {
45
- if (mapper == nullptr) {
46
- throw std::runtime_error(
47
- "Graph couldn't be sorted (Mapper cannot be nullptr)");
48
- }
49
- this->mapper = mapper;
50
- }
51
-
52
- explicit NodeID(std::shared_ptr<MutableValue> mutableValue) {
53
- if (mutableValue == nullptr) {
54
- throw std::runtime_error(
55
- "Graph couldn't be sorted (Mutable cannot be nullptr)");
56
- }
57
- this->mutableValue = mutableValue;
58
- }
59
-
60
- bool isMutable() const {
61
- return mutableValue != nullptr;
62
- }
63
-
64
- bool operator<(const NodeID &other) const {
65
- if (isMutable() != other.isMutable())
66
- return isMutable() < other.isMutable();
67
-
68
- if (isMutable()) {
69
- return mutableValue < other.mutableValue;
70
- }
71
-
72
- return mapper < other.mapper;
73
- }
74
- };
75
-
76
- std::map<NodeID, int> deg;
77
-
78
- std::map<std::shared_ptr<MutableValue>, std::vector<std::shared_ptr<Mapper>>>
79
- mappersThatUseSharedValue;
80
-
81
- std::set<std::pair<int, NodeID>> nodes;
82
-
83
- std::function<void(NodeID)> update = [&](NodeID id) {
84
- auto entry = std::make_pair(deg[id], id);
85
- if (nodes.find(entry) == nodes.end())
86
- return;
87
- nodes.erase(entry);
88
- entry.first--;
89
- deg[id]--;
90
- nodes.insert(entry);
91
- };
92
-
93
- for (auto &entry : mappers) {
94
- auto id = NodeID(entry.second);
95
- auto &mapper = entry.second;
96
- deg[id] = mapper->inputs.size();
97
- nodes.insert(std::make_pair(deg[id], id));
98
-
99
- for (auto sharedValue : mapper->inputs) {
100
- auto sharedValueID = NodeID(sharedValue);
101
- mappersThatUseSharedValue[sharedValue].push_back(mapper);
102
- if (deg.count(sharedValueID) == 0) {
103
- deg[sharedValueID] = 0;
104
- }
105
- }
106
-
107
- for (auto sharedValue : mapper->outputs) {
108
- deg[NodeID(sharedValue)]++;
109
- }
110
- }
111
-
112
- for (auto &entry : deg) {
113
- auto id = entry.first;
114
- if (id.isMutable()) {
115
- nodes.insert(std::make_pair(entry.second, id));
116
- }
117
- }
118
-
119
- while (nodes.size() > 0 && nodes.begin()->first == 0) {
120
- auto entry = *nodes.begin();
121
- nodes.erase(entry);
122
-
123
- auto id = entry.second;
124
- std::vector<NodeID> toUpdate;
125
-
126
- if (id.isMutable()) {
127
- for (auto id : mappersThatUseSharedValue[id.mutableValue]) {
128
- toUpdate.push_back(NodeID(id));
129
- }
130
- } else {
131
- for (auto sharedValue : id.mapper->outputs) {
132
- toUpdate.push_back(NodeID(sharedValue));
133
- }
134
-
135
- sortedMappers.push_back(id.mapper);
136
- }
137
-
138
- for (auto &id : toUpdate)
139
- update(id);
140
- }
141
-
142
- if (nodes.size() > 0) {
143
- throw std::runtime_error("Cycle in mappers graph!");
144
- }
145
- }
146
-
147
- } // namespace reanimated
@@ -1,29 +0,0 @@
1
- #pragma once
2
-
3
- #include <jsi/jsi.h>
4
- #include <memory>
5
- #include <unordered_map>
6
- #include <vector>
7
-
8
- using namespace facebook;
9
-
10
- namespace reanimated {
11
-
12
- class Mapper;
13
-
14
- class MapperRegistry {
15
- std::unordered_map<unsigned long, std::shared_ptr<Mapper>> mappers;
16
- std::vector<std::shared_ptr<Mapper>> sortedMappers;
17
- void updateOrder();
18
- bool updatedSinceLastExecute = false;
19
-
20
- public:
21
- void startMapper(std::shared_ptr<Mapper> mapper);
22
- void stopMapper(unsigned long id);
23
-
24
- void execute(jsi::Runtime &rt);
25
-
26
- bool needRunOnRender();
27
- };
28
-
29
- } // namespace reanimated
@@ -1,45 +0,0 @@
1
- #include "WorkletsCache.h"
2
- #include "FrozenObject.h"
3
- #include "ShareableValue.h"
4
-
5
- #include <string>
6
- #include <utility>
7
-
8
- using namespace facebook;
9
-
10
- namespace reanimated {
11
-
12
- jsi::Value eval(jsi::Runtime &rt, const char *code) {
13
- return rt.global().getPropertyAsFunction(rt, "eval").call(rt, code);
14
- }
15
-
16
- jsi::Function function(jsi::Runtime &rt, const std::string &code) {
17
- return eval(rt, ("(" + code + ")").c_str()).getObject(rt).getFunction(rt);
18
- }
19
-
20
- std::shared_ptr<jsi::Function> WorkletsCache::getFunction(
21
- jsi::Runtime &rt,
22
- std::shared_ptr<FrozenObject> frozenObj) {
23
- long long workletHash =
24
- ValueWrapper::asNumber(frozenObj->map["__workletHash"]->valueContainer);
25
- if (worklets.count(workletHash) == 0) {
26
- // We need to add a newline before the closing bracket, because in debug
27
- // builds the last line will be a source map, which is a comment and that
28
- // would make the bracket part of the comment and cause an error due to a
29
- // missing closing bracket.
30
- auto codeBuffer = std::make_shared<const jsi::StringBuffer>(
31
- "(" +
32
- ValueWrapper::asString(frozenObj->map["asString"]->valueContainer) +
33
- "\n)");
34
- auto func = rt.evaluateJavaScript(
35
- codeBuffer,
36
- ValueWrapper::asString(
37
- frozenObj->map["__location"]->valueContainer))
38
- .asObject(rt)
39
- .asFunction(rt);
40
- worklets[workletHash] = std::make_shared<jsi::Function>(std::move(func));
41
- }
42
- return worklets[workletHash];
43
- }
44
-
45
- } // namespace reanimated
@@ -1,24 +0,0 @@
1
- #pragma once
2
-
3
- #include <jsi/jsi.h>
4
- #include <stdio.h>
5
- #include <memory>
6
- #include <unordered_map>
7
-
8
- namespace reanimated {
9
-
10
- using namespace facebook;
11
-
12
- class FrozenObject;
13
-
14
- class WorkletsCache {
15
- private:
16
- std::unordered_map<long long, std::shared_ptr<jsi::Function>> worklets;
17
-
18
- public:
19
- std::shared_ptr<jsi::Function> getFunction(
20
- jsi::Runtime &rt,
21
- std::shared_ptr<reanimated::FrozenObject> frozenObj);
22
- };
23
-
24
- } // namespace reanimated
@@ -1,35 +0,0 @@
1
- #include "FrozenObject.h"
2
- #include "RuntimeManager.h"
3
- #include "ShareableValue.h"
4
- #include "SharedParent.h"
5
-
6
- namespace reanimated {
7
-
8
- FrozenObject::FrozenObject(
9
- jsi::Runtime &rt,
10
- const jsi::Object &object,
11
- RuntimeManager *runtimeManager) {
12
- auto propertyNames = object.getPropertyNames(rt);
13
- const size_t count = propertyNames.size(rt);
14
- namesOrder.reserve(count);
15
- for (size_t i = 0; i < count; i++) {
16
- auto propertyName = propertyNames.getValueAtIndex(rt, i).asString(rt);
17
- namesOrder.push_back(propertyName.utf8(rt));
18
- std::string nameStr = propertyName.utf8(rt);
19
- map[nameStr] = ShareableValue::adapt(
20
- rt, object.getProperty(rt, propertyName), runtimeManager);
21
- this->containsHostFunction |= map[nameStr]->containsHostFunction;
22
- }
23
- }
24
-
25
- jsi::Object FrozenObject::shallowClone(jsi::Runtime &rt) {
26
- jsi::Object object(rt);
27
- for (auto propName : namesOrder) {
28
- auto value = map[propName];
29
- object.setProperty(
30
- rt, jsi::String::createFromUtf8(rt, propName), value->getValue(rt));
31
- }
32
- return object;
33
- }
34
-
35
- } // namespace reanimated
@@ -1,36 +0,0 @@
1
- #pragma once
2
-
3
- #include <jsi/jsi.h>
4
- #include <memory>
5
- #include <string>
6
- #include <unordered_map>
7
- #include <vector>
8
- #include "RuntimeManager.h"
9
- #include "SharedParent.h"
10
- #include "WorkletsCache.h"
11
-
12
- using namespace facebook;
13
-
14
- namespace reanimated {
15
-
16
- class FrozenObject : public jsi::HostObject {
17
- friend WorkletsCache;
18
- friend void extractMutables(
19
- jsi::Runtime &rt,
20
- std::shared_ptr<ShareableValue> sv,
21
- std::vector<std::shared_ptr<MutableValue>> &res);
22
-
23
- private:
24
- std::unordered_map<std::string, std::shared_ptr<ShareableValue>> map;
25
- std::vector<std::string> namesOrder;
26
-
27
- public:
28
- FrozenObject(
29
- jsi::Runtime &rt,
30
- const jsi::Object &object,
31
- RuntimeManager *runtimeManager);
32
- jsi::Object shallowClone(jsi::Runtime &rt);
33
- bool containsHostFunction = false;
34
- };
35
-
36
- } // namespace reanimated
@@ -1,28 +0,0 @@
1
- #pragma once
2
-
3
- #include <jsi/jsi.h>
4
- #include <memory>
5
- #include <string>
6
-
7
- using namespace facebook;
8
-
9
- namespace reanimated {
10
-
11
- struct HostFunctionHandler : jsi::HostObject {
12
- std::shared_ptr<jsi::Function> pureFunction;
13
- std::string functionName;
14
- jsi::Runtime *hostRuntime;
15
- jsi::HostObject a;
16
-
17
- HostFunctionHandler(std::shared_ptr<jsi::Function> f, jsi::Runtime &rt) {
18
- pureFunction = f;
19
- functionName = f->getProperty(rt, "name").asString(rt).utf8(rt);
20
- hostRuntime = &rt;
21
- }
22
-
23
- std::shared_ptr<jsi::Function> getPureFunction() {
24
- return pureFunction;
25
- }
26
- };
27
-
28
- } // namespace reanimated
@@ -1,134 +0,0 @@
1
- #include "MutableValue.h"
2
- #include "RuntimeDecorator.h"
3
- #include "RuntimeManager.h"
4
- #include "ShareableValue.h"
5
- #include "SharedParent.h"
6
-
7
- #include <string>
8
-
9
- namespace reanimated {
10
-
11
- void MutableValue::setValue(jsi::Runtime &rt, const jsi::Value &newValue) {
12
- std::lock_guard<std::mutex> lock(readWriteMutex);
13
- value = ShareableValue::adapt(rt, newValue, runtimeManager);
14
-
15
- std::shared_ptr<MutableValue> thiz = shared_from_this();
16
- auto notifyListeners = [thiz]() {
17
- for (auto listener : thiz->listeners) {
18
- listener.second();
19
- }
20
- };
21
- if (RuntimeDecorator::isUIRuntime(rt)) {
22
- notifyListeners();
23
- } else {
24
- runtimeManager->scheduler->scheduleOnUI(
25
- [notifyListeners] { notifyListeners(); });
26
- }
27
- }
28
-
29
- jsi::Value MutableValue::getValue(jsi::Runtime &rt) {
30
- std::lock_guard<std::mutex> lock(readWriteMutex);
31
- return value->getValue(rt);
32
- }
33
-
34
- void MutableValue::set(
35
- jsi::Runtime &rt,
36
- const jsi::PropNameID &name,
37
- const jsi::Value &newValue) {
38
- auto propName = name.utf8(rt);
39
- if (!runtimeManager->valueSetter) {
40
- throw jsi::JSError(
41
- rt,
42
- "Value-Setter is not yet configured! Make sure the core-functions are installed.");
43
- }
44
-
45
- if (RuntimeDecorator::isUIRuntime(rt)) {
46
- // UI thread
47
- if (propName == "value") {
48
- auto setterProxy = jsi::Object::createFromHostObject(
49
- rt, std::make_shared<MutableValueSetterProxy>(shared_from_this()));
50
- runtimeManager->valueSetter->getValue(rt)
51
- .asObject(rt)
52
- .asFunction(rt)
53
- .callWithThis(rt, setterProxy, newValue);
54
- } else if (propName == "_animation") {
55
- // TODO: assert to allow animation to be set from UI only
56
- if (animation.expired()) {
57
- animation = getWeakRef(rt);
58
- }
59
- *animation.lock() = jsi::Value(rt, newValue);
60
- } else if (propName == "_value") {
61
- auto setter =
62
- std::make_shared<MutableValueSetterProxy>(shared_from_this());
63
- setter->set(rt, jsi::PropNameID::forAscii(rt, "_value"), newValue);
64
- }
65
- } else {
66
- // React-JS Thread or another threaded Runtime.
67
- if (propName == "value") {
68
- auto shareable = ShareableValue::adapt(rt, newValue, runtimeManager);
69
- runtimeManager->scheduler->scheduleOnUI([this, shareable] {
70
- jsi::Runtime &rt = *this->runtimeManager->runtime.get();
71
- auto setterProxy = jsi::Object::createFromHostObject(
72
- rt, std::make_shared<MutableValueSetterProxy>(shared_from_this()));
73
- jsi::Value newValue = shareable->getValue(rt);
74
- runtimeManager->valueSetter->getValue(rt)
75
- .asObject(rt)
76
- .asFunction(rt)
77
- .callWithThis(rt, setterProxy, newValue);
78
- });
79
- }
80
- }
81
- }
82
-
83
- jsi::Value MutableValue::get(jsi::Runtime &rt, const jsi::PropNameID &name) {
84
- auto propName = name.utf8(rt);
85
-
86
- if (propName == "value") {
87
- return getValue(rt);
88
- }
89
-
90
- if (RuntimeDecorator::isUIRuntime(rt)) {
91
- // _value and _animation should be accessed from UI only
92
- if (propName == "_value") {
93
- return getValue(rt);
94
- } else if (propName == "_animation") {
95
- // TODO: assert to allow animation to be read from UI only
96
- if (animation.expired()) {
97
- animation = getWeakRef(rt);
98
- }
99
- return jsi::Value(rt, *(animation.lock()));
100
- }
101
- }
102
-
103
- return jsi::Value::undefined();
104
- }
105
-
106
- std::vector<jsi::PropNameID> MutableValue::getPropertyNames(jsi::Runtime &rt) {
107
- std::vector<jsi::PropNameID> result;
108
- result.push_back(jsi::PropNameID::forUtf8(rt, std::string("value")));
109
- return result;
110
- }
111
-
112
- MutableValue::MutableValue(
113
- jsi::Runtime &rt,
114
- const jsi::Value &initial,
115
- RuntimeManager *runtimeManager,
116
- std::shared_ptr<Scheduler> s)
117
- : StoreUser(s, *runtimeManager),
118
- runtimeManager(runtimeManager),
119
- value(ShareableValue::adapt(rt, initial, runtimeManager)) {}
120
-
121
- unsigned long int MutableValue::addListener(
122
- unsigned long id,
123
- std::function<void()> listener) {
124
- listeners[id] = listener;
125
- return id;
126
- }
127
-
128
- void MutableValue::removeListener(unsigned long listenerId) {
129
- if (listeners.count(listenerId) > 0) {
130
- listeners.erase(listenerId);
131
- }
132
- }
133
-
134
- } // namespace reanimated