@react-native-ohos/react-native-reanimated 3.18.2 → 3.18.3

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 (99) hide show
  1. package/LICENSE +21 -21
  2. package/README.OpenSource +10 -10
  3. package/README.md +406 -10
  4. package/harmony/reanimated/BuildProfile.ets +1 -1
  5. package/harmony/reanimated/build-profile.json5 +11 -11
  6. package/harmony/reanimated/oh-package-lock.json5 +29 -0
  7. package/harmony/reanimated/oh-package.json5 +11 -11
  8. package/harmony/reanimated/src/main/cpp/CMakeLists.txt +2 -0
  9. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.cpp +86 -86
  10. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h +47 -47
  11. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.cpp +68 -68
  12. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.h +73 -68
  13. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.cpp +101 -101
  14. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.h +51 -51
  15. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitShadowNode.h +49 -49
  16. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.cpp +96 -96
  17. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.h +33 -33
  18. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.cpp +95 -95
  19. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.h +29 -29
  20. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationType.h +9 -9
  21. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.cpp +232 -232
  22. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.h +90 -90
  23. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp +870 -870
  24. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h +147 -147
  25. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.cpp +91 -91
  26. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +176 -176
  27. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +971 -971
  28. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h +252 -254
  29. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.cpp +231 -231
  30. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.h +109 -109
  31. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.cpp +56 -56
  32. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.h +20 -20
  33. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp +70 -70
  34. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.h +35 -35
  35. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/CollectionUtils.h +14 -14
  36. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.cpp +5 -5
  37. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.h +19 -19
  38. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h +98 -98
  39. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/ReanimatedSystraceSection.h +135 -135
  40. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +47 -47
  41. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +59 -59
  42. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.cpp +27 -27
  43. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.h +25 -25
  44. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +94 -94
  45. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.h +49 -49
  46. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +8 -8
  47. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +39 -39
  48. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.cpp +326 -326
  49. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.h +345 -345
  50. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.cpp +52 -52
  51. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.h +35 -35
  52. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/Defs.h +10 -10
  53. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.cpp +342 -342
  54. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.h +47 -47
  55. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.cpp +16 -16
  56. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.h +20 -20
  57. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.cpp +20 -20
  58. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.h +29 -29
  59. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/PlatformLogger.h +16 -16
  60. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.cpp +26 -26
  61. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.h +199 -199
  62. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.cpp +95 -95
  63. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.h +19 -19
  64. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/SingleInstanceChecker.h +72 -72
  65. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -49
  66. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.cpp +20 -20
  67. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.h +22 -22
  68. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +29 -29
  69. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.h +41 -41
  70. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +16 -16
  71. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +19 -19
  72. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.cpp +112 -112
  73. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.h +127 -127
  74. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.cpp +53 -53
  75. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.h +22 -22
  76. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RuntimeInitialization.md +191 -191
  77. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +173 -173
  78. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +90 -90
  79. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -36
  80. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +189 -189
  81. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +22 -22
  82. package/harmony/reanimated/src/main/cpp/ReanimatedModule.cpp +29 -19
  83. package/harmony/reanimated/src/main/cpp/ReanimatedSensor.cpp +248 -0
  84. package/harmony/reanimated/src/main/cpp/ReanimatedSensor.h +36 -0
  85. package/harmony/reanimated/src/main/cpp/ReanimatedSensorContainer.cpp +36 -0
  86. package/harmony/reanimated/src/main/cpp/ReanimatedSensorContainer.h +23 -0
  87. package/harmony/reanimated/src/main/cpp/WorkletsModule.cpp +60 -60
  88. package/harmony/reanimated/src/main/cpp/patches/AnimatedSensor/AnimatedSensorModule.cpp +89 -89
  89. package/harmony/reanimated/src/main/cpp/patches/NativeModules/ReanimatedModuleProxy.cpp +53 -4
  90. package/harmony/reanimated/src/main/ets/ReanimatedModule.ts +115 -15
  91. package/harmony/reanimated/src/main/module.json5 +12 -12
  92. package/harmony/reanimated/src/main/resources/base/element/color.json +7 -7
  93. package/harmony/reanimated/src/main/resources/base/element/string.json +15 -15
  94. package/harmony/reanimated/src/main/resources/base/profile/main_pages.json +5 -5
  95. package/harmony/reanimated/src/main/resources/en_US/element/string.json +15 -15
  96. package/harmony/reanimated/src/main/resources/zh_CN/element/string.json +15 -15
  97. package/harmony/reanimated/ts.ts +6 -6
  98. package/harmony/reanimated.har +0 -0
  99. package/package.json +51 -50
@@ -1,254 +1,252 @@
1
- #pragma once
2
-
3
- #include <reanimated/AnimatedSensor/AnimatedSensorModule.h>
4
- #include <reanimated/LayoutAnimations/LayoutAnimationsManager.h>
5
- #include <reanimated/NativeModules/ReanimatedModuleProxySpec.h>
6
- #include <reanimated/Tools/PlatformDepMethodsHolder.h>
7
-
8
- #ifdef RCT_NEW_ARCH_ENABLED
9
- #include <reanimated/Fabric/PropsRegistry.h>
10
- #include <reanimated/Fabric/ReanimatedCommitHook.h>
11
- #include <reanimated/Fabric/ReanimatedMountHook.h>
12
- #include <reanimated/LayoutAnimations/LayoutAnimationsProxy.h>
13
- #endif // RCT_NEW_ARCH_ENABLED
14
-
15
- #include <worklets/NativeModules/WorkletsModuleProxy.h>
16
- #include <worklets/Registries/EventHandlerRegistry.h>
17
- #include <worklets/Tools/JSScheduler.h>
18
- #include <worklets/Tools/SingleInstanceChecker.h>
19
- #include <worklets/Tools/UIScheduler.h>
20
-
21
- #ifdef RCT_NEW_ARCH_ENABLED
22
- #include <react/renderer/uimanager/UIManager.h>
23
- #endif // RCT_NEW_ARCH_ENABLED
24
-
25
- #include <memory>
26
- #include <string>
27
- #include <unordered_set>
28
- #include <utility>
29
- #include <vector>
30
-
31
- namespace reanimated {
32
-
33
- using namespace facebook;
34
-
35
- class ReanimatedModuleProxy
36
- : public ReanimatedModuleProxySpec,
37
- public std::enable_shared_from_this<ReanimatedModuleProxy> {
38
- public:
39
- ReanimatedModuleProxy(
40
- const std::shared_ptr<WorkletsModuleProxy> &workletsModuleProxy,
41
- jsi::Runtime &rnRuntime,
42
- const std::shared_ptr<CallInvoker> &jsCallInvoker,
43
- const PlatformDepMethodsHolder &platformDepMethodsHolder,
44
- const bool isBridgeless,
45
- const bool isReducedMotion);
46
-
47
- // We need this init method to initialize callbacks with
48
- // weak_from_this() which is available only after the object
49
- // is fully constructed.
50
- void init(const PlatformDepMethodsHolder &platformDepMethodsHolder);
51
-
52
- void scheduleOnUI(jsi::Runtime &rt, const jsi::Value &worklet) override;
53
- jsi::Value executeOnUIRuntimeSync(jsi::Runtime &rt, const jsi::Value &worklet)
54
- override;
55
-
56
- jsi::Value createWorkletRuntime(
57
- jsi::Runtime &rt,
58
- const jsi::Value &name,
59
- const jsi::Value &initializer) override;
60
- jsi::Value scheduleOnRuntime(
61
- jsi::Runtime &rt,
62
- const jsi::Value &workletRuntimeValue,
63
- const jsi::Value &shareableWorkletValue) override;
64
-
65
- ~ReanimatedModuleProxy();
66
-
67
- void invalidate();
68
-
69
- jsi::Value registerEventHandler(
70
- jsi::Runtime &rt,
71
- const jsi::Value &worklet,
72
- const jsi::Value &eventName,
73
- const jsi::Value &emitterReactTag) override;
74
- void unregisterEventHandler(
75
- jsi::Runtime &rt,
76
- const jsi::Value &registrationId) override;
77
-
78
- jsi::Value getViewProp(
79
- jsi::Runtime &rt,
80
- #ifdef RCT_NEW_ARCH_ENABLED
81
- const jsi::Value &shadowNodeWrapper,
82
- #else
83
- const jsi::Value &viewTag,
84
- #endif
85
- const jsi::Value &propName,
86
- const jsi::Value &callback) override;
87
-
88
- jsi::Value enableLayoutAnimations(jsi::Runtime &rt, const jsi::Value &config)
89
- override;
90
- jsi::Value configureProps(
91
- jsi::Runtime &rt,
92
- const jsi::Value &uiProps,
93
- const jsi::Value &nativeProps) override;
94
- jsi::Value configureLayoutAnimationBatch(
95
- jsi::Runtime &rt,
96
- const jsi::Value &layoutAnimationsBatch) override;
97
- void setShouldAnimateExiting(
98
- jsi::Runtime &rt,
99
- const jsi::Value &viewTag,
100
- const jsi::Value &shouldAnimate) override;
101
-
102
- void onRender(double timestampMs);
103
-
104
- bool isAnyHandlerWaitingForEvent(
105
- const std::string &eventName,
106
- const int emitterReactTag);
107
-
108
- void maybeRequestRender();
109
-
110
- bool handleEvent(
111
- const std::string &eventName,
112
- const int emitterReactTag,
113
- const jsi::Value &payload,
114
- double currentTime);
115
-
116
- inline std::shared_ptr<JSLogger> getJSLogger() const {
117
- return jsLogger_;
118
- }
119
-
120
- #ifdef RCT_NEW_ARCH_ENABLED
121
- bool handleRawEvent(const RawEvent &rawEvent, double currentTime);
122
-
123
- void updateProps(jsi::Runtime &rt, const jsi::Value &operations);
124
-
125
- void removeFromPropsRegistry(jsi::Runtime &rt, const jsi::Value &viewTags);
126
-
127
- void performOperations();
128
-
129
- void markNodeAsRemovable(
130
- jsi::Runtime &rt,
131
- const jsi::Value &shadowNodeWrapper) override;
132
- void unmarkNodeAsRemovable(jsi::Runtime &rt, const jsi::Value &viewTag)
133
- override;
134
-
135
- void dispatchCommand(
136
- jsi::Runtime &rt,
137
- const jsi::Value &shadowNodeValue,
138
- const jsi::Value &commandNameValue,
139
- const jsi::Value &argsValue);
140
-
141
- jsi::String obtainProp(
142
- jsi::Runtime &rt,
143
- const jsi::Value &shadowNodeWrapper,
144
- const jsi::Value &propName);
145
-
146
- jsi::Value measure(jsi::Runtime &rt, const jsi::Value &shadowNodeValue);
147
-
148
- void initializeFabric(const std::shared_ptr<UIManager> &uiManager);
149
-
150
- void initializeLayoutAnimationsProxy();
151
-
152
- std::string obtainPropFromShadowNode(
153
- jsi::Runtime &rt,
154
- const std::string &propName,
155
- const ShadowNode::Shared &shadowNode);
156
-
157
- #ifdef IS_REANIMATED_EXAMPLE_APP
158
- std::function<std::string()> createRegistriesLeakCheck();
159
- #endif // IS_REANIMATED_EXAMPLE_APP
160
- #endif
161
-
162
- jsi::Value registerSensor(
163
- jsi::Runtime &rt,
164
- const jsi::Value &sensorType,
165
- const jsi::Value &interval,
166
- const jsi::Value &iosReferenceFrame,
167
- const jsi::Value &sensorDataContainer) override;
168
- void unregisterSensor(jsi::Runtime &rt, const jsi::Value &sensorId) override;
169
-
170
- void cleanupSensors();
171
-
172
- jsi::Value subscribeForKeyboardEvents(
173
- jsi::Runtime &rt,
174
- const jsi::Value &keyboardEventContainer,
175
- const jsi::Value &isStatusBarTranslucent,
176
- const jsi::Value &isNavigationBarTranslucent) override;
177
- void unsubscribeFromKeyboardEvents(
178
- jsi::Runtime &rt,
179
- const jsi::Value &listenerId) override;
180
-
181
- inline LayoutAnimationsManager &layoutAnimationsManager() {
182
- return *layoutAnimationsManager_;
183
- }
184
-
185
- [[nodiscard]] inline jsi::Runtime &getUIRuntime() const {
186
- return uiWorkletRuntime_->getJSIRuntime();
187
- }
188
-
189
- [[nodiscard]] inline bool isBridgeless() const {
190
- return isBridgeless_;
191
- }
192
-
193
- [[nodiscard]] inline bool isReducedMotion() const {
194
- return isReducedMotion_;
195
- }
196
-
197
- [[nodiscard]] inline std::shared_ptr<WorkletsModuleProxy>
198
- getWorkletsModuleProxy() const {
199
- return workletsModuleProxy_;
200
- }
201
-
202
- private:
203
- void requestAnimationFrame(jsi::Runtime &rt, const jsi::Value &callback);
204
-
205
- #ifdef RCT_NEW_ARCH_ENABLED
206
- jsi::Value filterNonAnimatableProps(
207
- jsi::Runtime &rt,
208
- const jsi::Value &props);
209
- #endif // RCT_NEW_ARCH_ENABLED
210
-
211
- const bool isBridgeless_;
212
- const bool isReducedMotion_;
213
- std::shared_ptr<WorkletsModuleProxy> workletsModuleProxy_;
214
- const std::string valueUnpackerCode_;
215
- std::shared_ptr<WorkletRuntime> uiWorkletRuntime_;
216
-
217
- std::unique_ptr<EventHandlerRegistry> eventHandlerRegistry_;
218
- const RequestRenderFunction requestRender_;
219
- std::vector<std::shared_ptr<jsi::Value>> frameCallbacks_;
220
- volatile bool renderRequested_{false};
221
- std::function<void(const double)> onRenderCallback_;
222
- AnimatedSensorModule animatedSensorModule_;
223
- const std::shared_ptr<JSLogger> jsLogger_;
224
- std::shared_ptr<LayoutAnimationsManager> layoutAnimationsManager_;
225
-
226
- #ifdef RCT_NEW_ARCH_ENABLED
227
- std::unordered_set<std::string>
228
- animatablePropNames_; // filled by configureProps
229
- std::shared_ptr<UIManager> uiManager_;
230
- std::shared_ptr<LayoutAnimationsProxy> layoutAnimationsProxy_;
231
-
232
- std::vector<std::pair<ShadowNode::Shared, std::unique_ptr<jsi::Value>>>
233
- operationsInBatch_; // TODO: refactor std::pair to custom struct
234
-
235
- std::shared_ptr<PropsRegistry> propsRegistry_;
236
- std::shared_ptr<ReanimatedCommitHook> commitHook_;
237
- std::shared_ptr<ReanimatedMountHook> mountHook_;
238
-
239
- std::vector<Tag> tagsToRemove_; // from `propsRegistry_`
240
- #else
241
- const ObtainPropFunction obtainPropFunction_;
242
- const ConfigurePropsFunction configurePropsPlatformFunction_;
243
- const UpdatePropsFunction updatePropsFunction_;
244
- #endif
245
-
246
- const KeyboardEventSubscribeFunction subscribeForKeyboardEventsFunction_;
247
- const KeyboardEventUnsubscribeFunction unsubscribeFromKeyboardEventsFunction_;
248
-
249
- #ifndef NDEBUG
250
- worklets::SingleInstanceChecker<ReanimatedModuleProxy> singleInstanceChecker_;
251
- #endif // NDEBUG
252
- };
253
-
254
- } // namespace reanimated
1
+ #pragma once
2
+
3
+ #include <reanimated/AnimatedSensor/AnimatedSensorModule.h>
4
+ #include <reanimated/LayoutAnimations/LayoutAnimationsManager.h>
5
+ #include <reanimated/NativeModules/ReanimatedModuleProxySpec.h>
6
+ #include <reanimated/Tools/PlatformDepMethodsHolder.h>
7
+
8
+ #ifdef RCT_NEW_ARCH_ENABLED
9
+ #include <reanimated/Fabric/PropsRegistry.h>
10
+ #include <reanimated/Fabric/ReanimatedCommitHook.h>
11
+ #include <reanimated/Fabric/ReanimatedMountHook.h>
12
+ #include <reanimated/LayoutAnimations/LayoutAnimationsProxy.h>
13
+ #endif // RCT_NEW_ARCH_ENABLED
14
+
15
+ #include <worklets/NativeModules/WorkletsModuleProxy.h>
16
+ #include <worklets/Registries/EventHandlerRegistry.h>
17
+ #include <worklets/Tools/JSScheduler.h>
18
+ #include <worklets/Tools/SingleInstanceChecker.h>
19
+ #include <worklets/Tools/UIScheduler.h>
20
+
21
+ #ifdef RCT_NEW_ARCH_ENABLED
22
+ #include <react/renderer/uimanager/UIManager.h>
23
+ #endif // RCT_NEW_ARCH_ENABLED
24
+
25
+ #include <memory>
26
+ #include <string>
27
+ #include <unordered_set>
28
+ #include <utility>
29
+ #include <vector>
30
+
31
+ namespace reanimated {
32
+
33
+ using namespace facebook;
34
+
35
+ class ReanimatedModuleProxy
36
+ : public ReanimatedModuleProxySpec,
37
+ public std::enable_shared_from_this<ReanimatedModuleProxy> {
38
+ public:
39
+ ReanimatedModuleProxy(
40
+ const std::shared_ptr<WorkletsModuleProxy> &workletsModuleProxy,
41
+ jsi::Runtime &rnRuntime,
42
+ const std::shared_ptr<CallInvoker> &jsCallInvoker,
43
+ const PlatformDepMethodsHolder &platformDepMethodsHolder,
44
+ const bool isBridgeless,
45
+ const bool isReducedMotion);
46
+
47
+ // We need this init method to initialize callbacks with
48
+ // weak_from_this() which is available only after the object
49
+ // is fully constructed.
50
+ void init(const PlatformDepMethodsHolder &platformDepMethodsHolder);
51
+
52
+ void scheduleOnUI(jsi::Runtime &rt, const jsi::Value &worklet) override;
53
+ jsi::Value executeOnUIRuntimeSync(jsi::Runtime &rt, const jsi::Value &worklet)
54
+ override;
55
+
56
+ jsi::Value createWorkletRuntime(
57
+ jsi::Runtime &rt,
58
+ const jsi::Value &name,
59
+ const jsi::Value &initializer) override;
60
+ jsi::Value scheduleOnRuntime(
61
+ jsi::Runtime &rt,
62
+ const jsi::Value &workletRuntimeValue,
63
+ const jsi::Value &shareableWorkletValue) override;
64
+
65
+ ~ReanimatedModuleProxy();
66
+
67
+ jsi::Value registerEventHandler(
68
+ jsi::Runtime &rt,
69
+ const jsi::Value &worklet,
70
+ const jsi::Value &eventName,
71
+ const jsi::Value &emitterReactTag) override;
72
+ void unregisterEventHandler(
73
+ jsi::Runtime &rt,
74
+ const jsi::Value &registrationId) override;
75
+
76
+ jsi::Value getViewProp(
77
+ jsi::Runtime &rt,
78
+ #ifdef RCT_NEW_ARCH_ENABLED
79
+ const jsi::Value &shadowNodeWrapper,
80
+ #else
81
+ const jsi::Value &viewTag,
82
+ #endif
83
+ const jsi::Value &propName,
84
+ const jsi::Value &callback) override;
85
+
86
+ jsi::Value enableLayoutAnimations(jsi::Runtime &rt, const jsi::Value &config)
87
+ override;
88
+ jsi::Value configureProps(
89
+ jsi::Runtime &rt,
90
+ const jsi::Value &uiProps,
91
+ const jsi::Value &nativeProps) override;
92
+ jsi::Value configureLayoutAnimationBatch(
93
+ jsi::Runtime &rt,
94
+ const jsi::Value &layoutAnimationsBatch) override;
95
+ void setShouldAnimateExiting(
96
+ jsi::Runtime &rt,
97
+ const jsi::Value &viewTag,
98
+ const jsi::Value &shouldAnimate) override;
99
+
100
+ void onRender(double timestampMs);
101
+
102
+ bool isAnyHandlerWaitingForEvent(
103
+ const std::string &eventName,
104
+ const int emitterReactTag);
105
+
106
+ void maybeRequestRender();
107
+
108
+ bool handleEvent(
109
+ const std::string &eventName,
110
+ const int emitterReactTag,
111
+ const jsi::Value &payload,
112
+ double currentTime);
113
+
114
+ inline std::shared_ptr<JSLogger> getJSLogger() const {
115
+ return jsLogger_;
116
+ }
117
+
118
+ #ifdef RCT_NEW_ARCH_ENABLED
119
+ bool handleRawEvent(const RawEvent &rawEvent, double currentTime);
120
+
121
+ void updateProps(jsi::Runtime &rt, const jsi::Value &operations);
122
+
123
+ void removeFromPropsRegistry(jsi::Runtime &rt, const jsi::Value &viewTags);
124
+
125
+ void performOperations();
126
+
127
+ void markNodeAsRemovable(
128
+ jsi::Runtime &rt,
129
+ const jsi::Value &shadowNodeWrapper) override;
130
+ void unmarkNodeAsRemovable(jsi::Runtime &rt, const jsi::Value &viewTag)
131
+ override;
132
+
133
+ void dispatchCommand(
134
+ jsi::Runtime &rt,
135
+ const jsi::Value &shadowNodeValue,
136
+ const jsi::Value &commandNameValue,
137
+ const jsi::Value &argsValue);
138
+
139
+ jsi::String obtainProp(
140
+ jsi::Runtime &rt,
141
+ const jsi::Value &shadowNodeWrapper,
142
+ const jsi::Value &propName);
143
+
144
+ jsi::Value measure(jsi::Runtime &rt, const jsi::Value &shadowNodeValue);
145
+
146
+ void initializeFabric(const std::shared_ptr<UIManager> &uiManager);
147
+
148
+ void initializeLayoutAnimationsProxy();
149
+
150
+ std::string obtainPropFromShadowNode(
151
+ jsi::Runtime &rt,
152
+ const std::string &propName,
153
+ const ShadowNode::Shared &shadowNode);
154
+
155
+ #ifdef IS_REANIMATED_EXAMPLE_APP
156
+ std::function<std::string()> createRegistriesLeakCheck();
157
+ #endif // IS_REANIMATED_EXAMPLE_APP
158
+ #endif
159
+
160
+ jsi::Value registerSensor(
161
+ jsi::Runtime &rt,
162
+ const jsi::Value &sensorType,
163
+ const jsi::Value &interval,
164
+ const jsi::Value &iosReferenceFrame,
165
+ const jsi::Value &sensorDataContainer) override;
166
+ void unregisterSensor(jsi::Runtime &rt, const jsi::Value &sensorId) override;
167
+
168
+ void cleanupSensors();
169
+
170
+ jsi::Value subscribeForKeyboardEvents(
171
+ jsi::Runtime &rt,
172
+ const jsi::Value &keyboardEventContainer,
173
+ const jsi::Value &isStatusBarTranslucent,
174
+ const jsi::Value &isNavigationBarTranslucent) override;
175
+ void unsubscribeFromKeyboardEvents(
176
+ jsi::Runtime &rt,
177
+ const jsi::Value &listenerId) override;
178
+
179
+ inline LayoutAnimationsManager &layoutAnimationsManager() {
180
+ return *layoutAnimationsManager_;
181
+ }
182
+
183
+ [[nodiscard]] inline jsi::Runtime &getUIRuntime() const {
184
+ return uiWorkletRuntime_->getJSIRuntime();
185
+ }
186
+
187
+ [[nodiscard]] inline bool isBridgeless() const {
188
+ return isBridgeless_;
189
+ }
190
+
191
+ [[nodiscard]] inline bool isReducedMotion() const {
192
+ return isReducedMotion_;
193
+ }
194
+
195
+ [[nodiscard]] inline std::shared_ptr<WorkletsModuleProxy>
196
+ getWorkletsModuleProxy() const {
197
+ return workletsModuleProxy_;
198
+ }
199
+
200
+ private:
201
+ void requestAnimationFrame(jsi::Runtime &rt, const jsi::Value &callback);
202
+
203
+ #ifdef RCT_NEW_ARCH_ENABLED
204
+ jsi::Value filterNonAnimatableProps(
205
+ jsi::Runtime &rt,
206
+ const jsi::Value &props);
207
+ #endif // RCT_NEW_ARCH_ENABLED
208
+
209
+ const bool isBridgeless_;
210
+ const bool isReducedMotion_;
211
+ std::shared_ptr<WorkletsModuleProxy> workletsModuleProxy_;
212
+ const std::string valueUnpackerCode_;
213
+ std::shared_ptr<WorkletRuntime> uiWorkletRuntime_;
214
+
215
+ std::unique_ptr<EventHandlerRegistry> eventHandlerRegistry_;
216
+ const RequestRenderFunction requestRender_;
217
+ std::vector<std::shared_ptr<jsi::Value>> frameCallbacks_;
218
+ volatile bool renderRequested_{false};
219
+ std::function<void(const double)> onRenderCallback_;
220
+ AnimatedSensorModule animatedSensorModule_;
221
+ const std::shared_ptr<JSLogger> jsLogger_;
222
+ std::shared_ptr<LayoutAnimationsManager> layoutAnimationsManager_;
223
+
224
+ #ifdef RCT_NEW_ARCH_ENABLED
225
+ std::unordered_set<std::string>
226
+ animatablePropNames_; // filled by configureProps
227
+ std::shared_ptr<UIManager> uiManager_;
228
+ std::shared_ptr<LayoutAnimationsProxy> layoutAnimationsProxy_;
229
+
230
+ std::vector<std::pair<ShadowNode::Shared, std::unique_ptr<jsi::Value>>>
231
+ operationsInBatch_; // TODO: refactor std::pair to custom struct
232
+
233
+ std::shared_ptr<PropsRegistry> propsRegistry_;
234
+ std::shared_ptr<ReanimatedCommitHook> commitHook_;
235
+ std::shared_ptr<ReanimatedMountHook> mountHook_;
236
+
237
+ std::vector<Tag> tagsToRemove_; // from `propsRegistry_`
238
+ #else
239
+ const ObtainPropFunction obtainPropFunction_;
240
+ const ConfigurePropsFunction configurePropsPlatformFunction_;
241
+ const UpdatePropsFunction updatePropsFunction_;
242
+ #endif
243
+
244
+ const KeyboardEventSubscribeFunction subscribeForKeyboardEventsFunction_;
245
+ const KeyboardEventUnsubscribeFunction unsubscribeFromKeyboardEventsFunction_;
246
+
247
+ #ifndef NDEBUG
248
+ worklets::SingleInstanceChecker<ReanimatedModuleProxy> singleInstanceChecker_;
249
+ #endif // NDEBUG
250
+ };
251
+
252
+ } // namespace reanimated