@react-native-ohos/react-native-reanimated 3.18.1-rc.1

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 (113) hide show
  1. package/harmony/reanimated/BuildProfile.ets +17 -0
  2. package/harmony/reanimated/build-profile.json5 +12 -0
  3. package/harmony/reanimated/hvigorfile.ts +5 -0
  4. package/harmony/reanimated/index.ets +5 -0
  5. package/harmony/reanimated/oh-package.json5 +12 -0
  6. package/harmony/reanimated/src/main/cpp/CMakeLists.txt +72 -0
  7. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.cpp +86 -0
  8. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h +47 -0
  9. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.cpp +68 -0
  10. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.h +68 -0
  11. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.cpp +101 -0
  12. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.h +51 -0
  13. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitShadowNode.h +49 -0
  14. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.cpp +87 -0
  15. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.h +33 -0
  16. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.cpp +95 -0
  17. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.h +29 -0
  18. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationType.h +9 -0
  19. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.cpp +232 -0
  20. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.h +90 -0
  21. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp +870 -0
  22. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h +147 -0
  23. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.cpp +91 -0
  24. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +176 -0
  25. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +971 -0
  26. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h +252 -0
  27. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.cpp +231 -0
  28. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.h +109 -0
  29. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.cpp +56 -0
  30. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.h +20 -0
  31. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp +70 -0
  32. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.h +35 -0
  33. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/CollectionUtils.h +14 -0
  34. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.cpp +5 -0
  35. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.h +19 -0
  36. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h +98 -0
  37. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/ReanimatedSystraceSection.h +135 -0
  38. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +47 -0
  39. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +59 -0
  40. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.cpp +27 -0
  41. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.h +25 -0
  42. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +94 -0
  43. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.h +49 -0
  44. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +8 -0
  45. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +39 -0
  46. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.cpp +326 -0
  47. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.h +345 -0
  48. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.cpp +52 -0
  49. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.h +35 -0
  50. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/Defs.h +10 -0
  51. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.cpp +342 -0
  52. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.h +47 -0
  53. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.cpp +16 -0
  54. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.h +20 -0
  55. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.cpp +20 -0
  56. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.h +29 -0
  57. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/PlatformLogger.h +16 -0
  58. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.cpp +26 -0
  59. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.h +199 -0
  60. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.cpp +95 -0
  61. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.h +19 -0
  62. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/SingleInstanceChecker.h +72 -0
  63. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -0
  64. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.cpp +20 -0
  65. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.h +22 -0
  66. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +29 -0
  67. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.h +41 -0
  68. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +16 -0
  69. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +19 -0
  70. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.cpp +112 -0
  71. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.h +127 -0
  72. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.cpp +53 -0
  73. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.h +22 -0
  74. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RuntimeInitialization.md +191 -0
  75. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +155 -0
  76. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +90 -0
  77. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -0
  78. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +182 -0
  79. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +22 -0
  80. package/harmony/reanimated/src/main/cpp/ReanimatedLogger.cpp +33 -0
  81. package/harmony/reanimated/src/main/cpp/ReanimatedModule.cpp +222 -0
  82. package/harmony/reanimated/src/main/cpp/ReanimatedModule.h +24 -0
  83. package/harmony/reanimated/src/main/cpp/ReanimatedNodesManager.cpp +56 -0
  84. package/harmony/reanimated/src/main/cpp/ReanimatedNodesManager.h +31 -0
  85. package/harmony/reanimated/src/main/cpp/ReanimatedPackage.cpp +47 -0
  86. package/harmony/reanimated/src/main/cpp/ReanimatedPackage.h +16 -0
  87. package/harmony/reanimated/src/main/cpp/ReanimatedUIScheduler.cpp +23 -0
  88. package/harmony/reanimated/src/main/cpp/ReanimatedUIScheduler.h +20 -0
  89. package/harmony/reanimated/src/main/cpp/TransformParser.h +94 -0
  90. package/harmony/reanimated/src/main/cpp/WorkletsModule.cpp +58 -0
  91. package/harmony/reanimated/src/main/cpp/WorkletsModule.h +22 -0
  92. package/harmony/reanimated/src/main/cpp/patches/AnimatedSensor/AnimatedSensorModule.cpp +89 -0
  93. package/harmony/reanimated/src/main/cpp/patches/Fabric/ShadowTreeCloner.cpp +95 -0
  94. package/harmony/reanimated/src/main/cpp/patches/NativeModules/ReanimatedModuleProxy.cpp +961 -0
  95. package/harmony/reanimated/src/main/ets/AnimationManager.ts +61 -0
  96. package/harmony/reanimated/src/main/ets/ReanimatedModule.ts +41 -0
  97. package/harmony/reanimated/src/main/ets/ReanimatedPackage.ts +29 -0
  98. package/harmony/reanimated/src/main/ets/WorkletsModule.ts +15 -0
  99. package/harmony/reanimated/src/main/module.json5 +13 -0
  100. package/harmony/reanimated/src/main/resources/base/element/color.json +8 -0
  101. package/harmony/reanimated/src/main/resources/base/element/string.json +16 -0
  102. package/harmony/reanimated/src/main/resources/base/media/icon.png +0 -0
  103. package/harmony/reanimated/src/main/resources/base/media/startIcon.png +0 -0
  104. package/harmony/reanimated/src/main/resources/base/profile/main_pages.json +5 -0
  105. package/harmony/reanimated/src/main/resources/en_US/element/string.json +16 -0
  106. package/harmony/reanimated/src/main/resources/zh_CN/element/string.json +16 -0
  107. package/harmony/reanimated/ts.ts +6 -0
  108. package/harmony/reanimated.har +0 -0
  109. package/lib/index.d.ts +4 -0
  110. package/lib/index.d.ts.map +1 -0
  111. package/lib/index.js +7 -0
  112. package/package.json +50 -0
  113. package/src/index.ts +10 -0
@@ -0,0 +1,70 @@
1
+ #include <reanimated/RuntimeDecorators/UIRuntimeDecorator.h>
2
+ #include <worklets/Tools/ReanimatedJSIUtils.h>
3
+
4
+ namespace reanimated {
5
+
6
+ using namespace worklets;
7
+
8
+ void UIRuntimeDecorator::decorate(
9
+ jsi::Runtime &uiRuntime,
10
+ #ifdef RCT_NEW_ARCH_ENABLED
11
+ // nothing
12
+ #else
13
+ const ScrollToFunction scrollTo,
14
+ #endif
15
+ const ObtainPropFunction obtainPropFunction,
16
+ const UpdatePropsFunction updateProps,
17
+ const MeasureFunction measure,
18
+ const DispatchCommandFunction dispatchCommand,
19
+ const RequestAnimationFrameFunction requestAnimationFrame,
20
+ const GetAnimationTimestampFunction getAnimationTimestamp,
21
+ const SetGestureStateFunction setGestureState,
22
+ const ProgressLayoutAnimationFunction progressLayoutAnimation,
23
+ const EndLayoutAnimationFunction endLayoutAnimation,
24
+ const MaybeFlushUIUpdatesQueueFunction maybeFlushUIUpdatesQueue) {
25
+ uiRuntime.global().setProperty(uiRuntime, "_UI", true);
26
+
27
+ #ifdef RCT_NEW_ARCH_ENABLED
28
+ jsi_utils::installJsiFunction(uiRuntime, "_updatePropsFabric", updateProps);
29
+ jsi_utils::installJsiFunction(
30
+ uiRuntime, "_dispatchCommandFabric", dispatchCommand);
31
+ jsi_utils::installJsiFunction(uiRuntime, "_measureFabric", measure);
32
+ #else
33
+ jsi_utils::installJsiFunction(uiRuntime, "_updatePropsPaper", updateProps);
34
+ jsi_utils::installJsiFunction(
35
+ uiRuntime, "_dispatchCommandPaper", dispatchCommand);
36
+ jsi_utils::installJsiFunction(uiRuntime, "_scrollToPaper", scrollTo);
37
+ jsi_utils::installJsiFunction(
38
+ uiRuntime,
39
+ "_measurePaper",
40
+ [measure](jsi::Runtime &rt, int viewTag) -> jsi::Value {
41
+ auto result = measure(viewTag);
42
+ jsi::Object resultObject(rt);
43
+ for (const auto &item : result) {
44
+ resultObject.setProperty(rt, item.first.c_str(), item.second);
45
+ }
46
+ return resultObject;
47
+ });
48
+ jsi_utils::installJsiFunction(
49
+ uiRuntime, "_obtainPropPaper", obtainPropFunction);
50
+ #endif // RCT_NEW_ARCH_ENABLED
51
+
52
+ jsi_utils::installJsiFunction(
53
+ uiRuntime, "requestAnimationFrame", requestAnimationFrame);
54
+ jsi_utils::installJsiFunction(
55
+ uiRuntime, "_getAnimationTimestamp", getAnimationTimestamp);
56
+
57
+ jsi_utils::installJsiFunction(
58
+ uiRuntime, "_notifyAboutProgress", progressLayoutAnimation);
59
+ jsi_utils::installJsiFunction(
60
+ uiRuntime, "_notifyAboutEnd", endLayoutAnimation);
61
+
62
+ jsi_utils::installJsiFunction(uiRuntime, "_setGestureState", setGestureState);
63
+ jsi_utils::installJsiFunction(
64
+ uiRuntime, "_maybeFlushUIUpdatesQueue", maybeFlushUIUpdatesQueue);
65
+
66
+ jsi_utils::installJsiFunction(
67
+ uiRuntime, "_obtainPropFabric", obtainPropFunction);
68
+ }
69
+
70
+ } // namespace reanimated
@@ -0,0 +1,35 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+
5
+ #include <reanimated/Tools/PlatformDepMethodsHolder.h>
6
+
7
+ using namespace facebook;
8
+
9
+ namespace reanimated {
10
+
11
+ using RequestAnimationFrameFunction =
12
+ std::function<void(jsi::Runtime &, const jsi::Value &)>;
13
+
14
+ class UIRuntimeDecorator {
15
+ public:
16
+ static void decorate(
17
+ jsi::Runtime &uiRuntime,
18
+ #ifdef RCT_NEW_ARCH_ENABLED
19
+ // nothing
20
+ #else
21
+ const ScrollToFunction scrollTo,
22
+ #endif
23
+ const ObtainPropFunction obtainPropFunction,
24
+ const UpdatePropsFunction updateProps,
25
+ const MeasureFunction measure,
26
+ const DispatchCommandFunction dispatchCommand,
27
+ const RequestAnimationFrameFunction requestAnimationFrame,
28
+ const GetAnimationTimestampFunction getAnimationTimestamp,
29
+ const SetGestureStateFunction setGestureState,
30
+ const ProgressLayoutAnimationFunction progressLayoutAnimation,
31
+ const EndLayoutAnimationFunction endLayoutAnimation,
32
+ const MaybeFlushUIUpdatesQueueFunction maybeFlushUIUpdatesQueue);
33
+ };
34
+
35
+ } // namespace reanimated
@@ -0,0 +1,14 @@
1
+ #pragma once
2
+
3
+ #include <algorithm>
4
+
5
+ namespace reanimated {
6
+ namespace collection {
7
+
8
+ template <class CollectionType, class ValueType>
9
+ inline bool contains(const CollectionType &collection, const ValueType &value) {
10
+ return collection.find(value) != collection.end();
11
+ }
12
+
13
+ } // namespace collection
14
+ } // namespace reanimated
@@ -0,0 +1,5 @@
1
+ #include <reanimated/Tools/FeaturesConfig.h>
2
+
3
+ namespace reanimated {
4
+ bool FeaturesConfig::_isLayoutAnimationEnabled = false;
5
+ }
@@ -0,0 +1,19 @@
1
+ #pragma once
2
+ #include <string>
3
+
4
+ namespace reanimated {
5
+
6
+ class FeaturesConfig {
7
+ public:
8
+ static inline bool isLayoutAnimationEnabled() {
9
+ return _isLayoutAnimationEnabled;
10
+ }
11
+ static inline void setLayoutAnimationEnabled(bool isLayoutAnimationEnabled) {
12
+ _isLayoutAnimationEnabled = isLayoutAnimationEnabled;
13
+ }
14
+
15
+ private:
16
+ static bool _isLayoutAnimationEnabled;
17
+ };
18
+
19
+ } // namespace reanimated
@@ -0,0 +1,98 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+
5
+ #ifdef RCT_NEW_ARCH_ENABLED
6
+ #include <react/renderer/core/ReactPrimitives.h>
7
+ #endif
8
+
9
+ #include <string>
10
+ #include <utility>
11
+ #include <vector>
12
+
13
+ using namespace facebook;
14
+
15
+ #ifdef RCT_NEW_ARCH_ENABLED
16
+ using namespace react;
17
+ #endif
18
+
19
+ namespace reanimated {
20
+
21
+ #ifdef RCT_NEW_ARCH_ENABLED
22
+
23
+ using UpdatePropsFunction =
24
+ std::function<void(jsi::Runtime &rt, const jsi::Value &operations)>;
25
+ using ObtainPropFunction = std::function<jsi::Value(
26
+ jsi::Runtime &rt,
27
+ const jsi::Value &shadowNodeWrapper,
28
+ const jsi::Value &propName)>;
29
+ using DispatchCommandFunction = std::function<void(
30
+ jsi::Runtime &rt,
31
+ const jsi::Value &shadowNodeValue,
32
+ const jsi::Value &commandNameValue,
33
+ const jsi::Value &argsValue)>;
34
+ using MeasureFunction = std::function<
35
+ jsi::Value(jsi::Runtime &rt, const jsi::Value &shadowNodeValue)>;
36
+
37
+ #else
38
+
39
+ using UpdatePropsFunction =
40
+ std::function<void(jsi::Runtime &rt, const jsi::Value &operations)>;
41
+ using ScrollToFunction = std::function<void(int, double, double, bool)>;
42
+ using DispatchCommandFunction = std::function<void(
43
+ jsi::Runtime &rt,
44
+ const int viewTag,
45
+ const jsi::Value &commandNameValue,
46
+ const jsi::Value &argsValue)>;
47
+ using MeasureFunction =
48
+ std::function<std::vector<std::pair<std::string, double>>(int)>;
49
+ using ObtainPropFunction =
50
+ std::function<jsi::Value(jsi::Runtime &, const int, const jsi::Value &)>;
51
+
52
+ #endif // RCT_NEW_ARCH_ENABLED
53
+
54
+ using RequestRenderFunction =
55
+ std::function<void(std::function<void(const double)>)>;
56
+ using GetAnimationTimestampFunction = std::function<double(void)>;
57
+
58
+ using ProgressLayoutAnimationFunction =
59
+ std::function<void(jsi::Runtime &, int, jsi::Object, bool)>;
60
+ using EndLayoutAnimationFunction = std::function<void(int, bool)>;
61
+
62
+ using RegisterSensorFunction =
63
+ std::function<int(int, int, int, std::function<void(double[], int)>)>;
64
+ using UnregisterSensorFunction = std::function<void(int)>;
65
+ using SetGestureStateFunction = std::function<void(int, int)>;
66
+ using ConfigurePropsFunction = std::function<void(
67
+ jsi::Runtime &rt,
68
+ const jsi::Value &uiProps,
69
+ const jsi::Value &nativeProps)>;
70
+ using KeyboardEventSubscribeFunction =
71
+ std::function<int(std::function<void(int, int)>, bool, bool)>;
72
+ using KeyboardEventUnsubscribeFunction = std::function<void(int)>;
73
+ using MaybeFlushUIUpdatesQueueFunction = std::function<void()>;
74
+
75
+ struct PlatformDepMethodsHolder {
76
+ RequestRenderFunction requestRender;
77
+ #ifdef RCT_NEW_ARCH_ENABLED
78
+ // nothing
79
+ #else
80
+ UpdatePropsFunction updatePropsFunction;
81
+ ScrollToFunction scrollToFunction;
82
+ DispatchCommandFunction dispatchCommandFunction;
83
+ MeasureFunction measureFunction;
84
+ ConfigurePropsFunction configurePropsFunction;
85
+ ObtainPropFunction obtainPropFunction;
86
+ #endif
87
+ GetAnimationTimestampFunction getAnimationTimestamp;
88
+ ProgressLayoutAnimationFunction progressLayoutAnimation;
89
+ EndLayoutAnimationFunction endLayoutAnimation;
90
+ RegisterSensorFunction registerSensor;
91
+ UnregisterSensorFunction unregisterSensor;
92
+ SetGestureStateFunction setGestureStateFunction;
93
+ KeyboardEventSubscribeFunction subscribeForKeyboardEvents;
94
+ KeyboardEventUnsubscribeFunction unsubscribeFromKeyboardEvents;
95
+ MaybeFlushUIUpdatesQueueFunction maybeFlushUIUpdatesQueueFunction;
96
+ };
97
+
98
+ } // namespace reanimated
@@ -0,0 +1,135 @@
1
+ #pragma once
2
+ #include <string>
3
+ #include <vector>
4
+
5
+ #ifdef REANIMATED_PROFILING
6
+
7
+ #if defined(__APPLE__)
8
+ #include <os/trace_base.h>
9
+
10
+ #if OS_LOG_TARGET_HAS_10_15_FEATURES
11
+ #include <os/log.h>
12
+ #include <os/signpost.h>
13
+ #include <sstream>
14
+ #endif // OS_LOG_TARGET_HAS_10_15_FEATURES
15
+
16
+ #elif defined(ANDROID)
17
+
18
+ #include <android/trace.h>
19
+
20
+ #endif // defined(ANDROID)
21
+
22
+ #endif // REANIMATED_PROFILING
23
+
24
+ namespace reanimated {
25
+
26
+ #if defined(ANDROID) && defined(REANIMATED_PROFILING)
27
+
28
+ struct ReanimatedSystraceSection {
29
+ public:
30
+ template <typename... ConvertsToStringPiece>
31
+ explicit ReanimatedSystraceSection(
32
+ const char *name,
33
+ ConvertsToStringPiece &&...args) {
34
+ ATrace_beginSection(name);
35
+ }
36
+
37
+ ~ReanimatedSystraceSection() {
38
+ ATrace_endSection();
39
+ }
40
+ };
41
+
42
+ // The apple part is copied from React Native
43
+ // from
44
+ // https://github.com/facebook/react-native/blob/5697d923a05119314b4cfcd556cb243986637764/packages/react-native/ReactCommon/cxxreact/SystraceSection.h
45
+ #elif defined(__APPLE__) && OS_LOG_TARGET_HAS_10_15_FEATURES && \
46
+ defined(REANIMATED_PROFILING)
47
+
48
+ template <typename T, typename = void>
49
+ struct renderer {
50
+ static std::string render(const T &t) {
51
+ std::ostringstream oss;
52
+ oss << t;
53
+ return oss.str();
54
+ }
55
+ };
56
+
57
+ template <typename T>
58
+ static auto render(const T &t)
59
+ -> decltype(renderer<T>::render(std::declval<const T &>())) {
60
+ return renderer<T>::render(t);
61
+ }
62
+
63
+ inline os_log_t instrumentsLogHandle = nullptr;
64
+
65
+ static inline os_log_t getOrCreateInstrumentsLogHandle() {
66
+ if (!instrumentsLogHandle) {
67
+ instrumentsLogHandle = os_log_create(
68
+ "dev.reanimated.instruments", OS_LOG_CATEGORY_POINTS_OF_INTEREST);
69
+ }
70
+ return instrumentsLogHandle;
71
+ }
72
+
73
+ struct ReanimatedSystraceSection {
74
+ public:
75
+ template <typename... ConvertsToStringPiece>
76
+ explicit ReanimatedSystraceSection(
77
+ const char *name,
78
+ ConvertsToStringPiece &&...args) {
79
+ os_log_t instrumentsLogHandle =
80
+ reanimated::getOrCreateInstrumentsLogHandle();
81
+
82
+ // If the log isn't enabled, we don't want the performance overhead of the
83
+ // rest of the code below.
84
+ if (!os_signpost_enabled(instrumentsLogHandle)) {
85
+ return;
86
+ }
87
+
88
+ name_ = name;
89
+
90
+ const auto argsVector =
91
+ std::vector<std::string>{reanimated::render(args)...};
92
+ std::string argsString = "";
93
+ for (size_t i = 0; i < argsVector.size(); i += 2) {
94
+ argsString += argsVector[i] + "=" + argsVector[i + 1] + ";";
95
+ }
96
+
97
+ signpostID_ = os_signpost_id_make_with_pointer(instrumentsLogHandle, this);
98
+
99
+ os_signpost_interval_begin(
100
+ instrumentsLogHandle,
101
+ signpostID_,
102
+ "Reanimated",
103
+ "%s begin: %s",
104
+ name,
105
+ argsString.c_str());
106
+ }
107
+
108
+ ~ReanimatedSystraceSection() {
109
+ os_signpost_interval_end(
110
+ reanimated::instrumentsLogHandle,
111
+ signpostID_,
112
+ "Reanimated",
113
+ "%s end",
114
+ name_.data());
115
+ }
116
+
117
+ private:
118
+ os_signpost_id_t signpostID_ = OS_SIGNPOST_ID_INVALID;
119
+ std::string_view name_;
120
+ };
121
+
122
+ #else
123
+
124
+ struct ReanimatedSystraceSection {
125
+ public:
126
+ template <typename... ConvertsToStringPiece>
127
+ explicit ReanimatedSystraceSection(
128
+ const char *name,
129
+ ConvertsToStringPiece &&...args) {}
130
+ };
131
+
132
+ #endif // defined(__APPLE__) && OS_LOG_TARGET_HAS_10_15_FEATURES &&
133
+ // defined(REANIMATED_PROFILING)
134
+
135
+ } // namespace reanimated
@@ -0,0 +1,47 @@
1
+ #include <string>
2
+
3
+ #ifdef RCT_NEW_ARCH_ENABLED
4
+ #include <react/renderer/uimanager/UIManagerBinding.h>
5
+ #include <react/renderer/uimanager/primitives.h>
6
+ #endif // RCT_NEW_ARCH_ENABLED
7
+
8
+ #include <worklets/NativeModules/WorkletsModuleProxy.h>
9
+ #include <worklets/SharedItems/Shareables.h>
10
+ #include <worklets/Tools/Defs.h>
11
+
12
+ #ifdef __ANDROID__
13
+ #include <fbjni/fbjni.h>
14
+ #endif // __ANDROID__
15
+
16
+ #include <jsi/jsi.h>
17
+
18
+ using namespace facebook;
19
+
20
+ namespace worklets {
21
+
22
+ WorkletsModuleProxy::WorkletsModuleProxy(
23
+ const std::string &valueUnpackerCode,
24
+ const std::shared_ptr<MessageQueueThread> &jsQueue,
25
+ const std::shared_ptr<CallInvoker> &jsCallInvoker,
26
+ const std::shared_ptr<JSScheduler> &jsScheduler,
27
+ const std::shared_ptr<UIScheduler> &uiScheduler)
28
+ : WorkletsModuleProxySpec(jsCallInvoker),
29
+ valueUnpackerCode_(valueUnpackerCode),
30
+ jsQueue_(jsQueue),
31
+ jsScheduler_(jsScheduler),
32
+ uiScheduler_(uiScheduler) {}
33
+
34
+ WorkletsModuleProxy::~WorkletsModuleProxy() {}
35
+
36
+ jsi::Value WorkletsModuleProxy::makeShareableClone(
37
+ jsi::Runtime &rt,
38
+ const jsi::Value &value,
39
+ const jsi::Value &shouldRetainRemote,
40
+ const jsi::Value &nativeStateSource) {
41
+ // TODO: It might be a good idea to rename one of these methods to avoid
42
+ // confusion.
43
+ return worklets::makeShareableClone(
44
+ rt, value, shouldRetainRemote, nativeStateSource);
45
+ }
46
+
47
+ } // namespace worklets
@@ -0,0 +1,59 @@
1
+ #pragma once
2
+
3
+ #include <cxxreact/MessageQueueThread.h>
4
+ #include <worklets/NativeModules/WorkletsModuleProxySpec.h>
5
+ #include <worklets/Tools/JSScheduler.h>
6
+ #include <worklets/Tools/SingleInstanceChecker.h>
7
+ #include <worklets/Tools/UIScheduler.h>
8
+ #include <worklets/WorkletRuntime/WorkletRuntime.h>
9
+ #include <memory>
10
+ #include <string>
11
+
12
+ namespace worklets {
13
+
14
+ class WorkletsModuleProxy
15
+ : public WorkletsModuleProxySpec,
16
+ public std::enable_shared_from_this<WorkletsModuleProxy> {
17
+ public:
18
+ explicit WorkletsModuleProxy(
19
+ const std::string &valueUnpackerCode,
20
+ const std::shared_ptr<MessageQueueThread> &jsQueue,
21
+ const std::shared_ptr<CallInvoker> &jsCallInvoker,
22
+ const std::shared_ptr<JSScheduler> &jsScheduler,
23
+ const std::shared_ptr<UIScheduler> &uiScheduler);
24
+
25
+ ~WorkletsModuleProxy();
26
+
27
+ jsi::Value makeShareableClone(
28
+ jsi::Runtime &rt,
29
+ const jsi::Value &value,
30
+ const jsi::Value &shouldRetainRemote,
31
+ const jsi::Value &nativeStateSource) override;
32
+
33
+ [[nodiscard]] inline std::string getValueUnpackerCode() const {
34
+ return valueUnpackerCode_;
35
+ }
36
+
37
+ [[nodiscard]] inline std::shared_ptr<MessageQueueThread> getJSQueue() const {
38
+ return jsQueue_;
39
+ }
40
+
41
+ [[nodiscard]] inline std::shared_ptr<JSScheduler> getJSScheduler() const {
42
+ return jsScheduler_;
43
+ }
44
+
45
+ [[nodiscard]] inline std::shared_ptr<UIScheduler> getUIScheduler() const {
46
+ return uiScheduler_;
47
+ }
48
+
49
+ private:
50
+ const std::string valueUnpackerCode_;
51
+ const std::shared_ptr<MessageQueueThread> jsQueue_;
52
+ const std::shared_ptr<JSScheduler> jsScheduler_;
53
+ const std::shared_ptr<UIScheduler> uiScheduler_;
54
+ #ifndef NDEBUG
55
+ SingleInstanceChecker<WorkletsModuleProxy> singleInstanceChecker_;
56
+ #endif // NDEBUG
57
+ };
58
+
59
+ } // namespace worklets
@@ -0,0 +1,27 @@
1
+ #include <worklets/NativeModules/WorkletsModuleProxySpec.h>
2
+
3
+ #include <utility>
4
+
5
+ #define WORKLETS_SPEC_PREFIX(FN_NAME) \
6
+ __hostFunction_WorkletsModuleProxySpec_##FN_NAME
7
+
8
+ namespace worklets {
9
+
10
+ static jsi::Value WORKLETS_SPEC_PREFIX(makeShareableClone)(
11
+ jsi::Runtime &rt,
12
+ TurboModule &turboModule,
13
+ const jsi::Value *args,
14
+ size_t) {
15
+ return static_cast<WorkletsModuleProxySpec *>(&turboModule)
16
+ ->makeShareableClone(
17
+ rt, std::move(args[0]), std::move(args[1]), std::move(args[2]));
18
+ }
19
+
20
+ WorkletsModuleProxySpec::WorkletsModuleProxySpec(
21
+ const std::shared_ptr<CallInvoker> jsInvoker)
22
+ : TurboModule("NativeWorklets", jsInvoker) {
23
+ methodMap_["makeShareableClone"] =
24
+ MethodMetadata{2, WORKLETS_SPEC_PREFIX(makeShareableClone)};
25
+ }
26
+
27
+ } // namespace worklets
@@ -0,0 +1,25 @@
1
+ #pragma once
2
+
3
+ #include <ReactCommon/CallInvoker.h>
4
+ #include <ReactCommon/TurboModule.h>
5
+ #include <memory>
6
+
7
+ using namespace facebook;
8
+ using namespace react;
9
+
10
+ namespace worklets {
11
+
12
+ class JSI_EXPORT WorkletsModuleProxySpec : public TurboModule {
13
+ protected:
14
+ explicit WorkletsModuleProxySpec(
15
+ const std::shared_ptr<CallInvoker> jsInvoker);
16
+
17
+ public:
18
+ virtual jsi::Value makeShareableClone(
19
+ jsi::Runtime &rt,
20
+ const jsi::Value &value,
21
+ const jsi::Value &shouldRetainRemote,
22
+ const jsi::Value &nativeStateSource) = 0;
23
+ };
24
+
25
+ } // namespace worklets
@@ -0,0 +1,94 @@
1
+ #include <worklets/Registries/EventHandlerRegistry.h>
2
+ #include <worklets/Tools/WorkletEventHandler.h>
3
+
4
+ #include <utility>
5
+ #include <vector>
6
+
7
+ namespace worklets {
8
+
9
+ void EventHandlerRegistry::registerEventHandler(
10
+ const std::shared_ptr<WorkletEventHandler> &eventHandler) {
11
+ const std::lock_guard<std::mutex> lock(instanceMutex);
12
+ const auto &eventName = eventHandler->getEventName();
13
+ auto handlerId = eventHandler->getHandlerId();
14
+
15
+ if (eventHandler->shouldIgnoreEmitterReactTag()) {
16
+ eventMappingsWithoutTag[eventName][handlerId] = eventHandler;
17
+ } else {
18
+ const auto emitterReactTag = eventHandler->getEmitterReactTag();
19
+ const auto eventHash = std::make_pair(emitterReactTag, eventName);
20
+ eventMappingsWithTag[eventHash][handlerId] = eventHandler;
21
+ }
22
+ eventHandlers[handlerId] = eventHandler;
23
+ }
24
+
25
+ void EventHandlerRegistry::unregisterEventHandler(const uint64_t id) {
26
+ const std::lock_guard<std::mutex> lock(instanceMutex);
27
+ auto handlerIt = eventHandlers.find(id);
28
+ if (handlerIt != eventHandlers.end()) {
29
+ const auto &eventHandler = handlerIt->second;
30
+ const auto &eventName = eventHandler->getEventName();
31
+
32
+ if (eventHandler->shouldIgnoreEmitterReactTag()) {
33
+ const auto eventMappingIt = eventMappingsWithoutTag.find(eventName);
34
+ auto &handlersMap = eventMappingIt->second;
35
+ handlersMap.erase(id);
36
+ if (handlersMap.empty()) {
37
+ eventMappingsWithoutTag.erase(eventMappingIt);
38
+ }
39
+ } else {
40
+ const auto emitterReactTag = eventHandler->getEmitterReactTag();
41
+ const auto eventHash = std::make_pair(emitterReactTag, eventName);
42
+ const auto eventMappingIt = eventMappingsWithTag.find(eventHash);
43
+ auto &handlersMap = eventMappingIt->second;
44
+ handlersMap.erase(id);
45
+ if (handlersMap.empty()) {
46
+ eventMappingsWithTag.erase(eventMappingIt);
47
+ }
48
+ }
49
+ eventHandlers.erase(handlerIt);
50
+ }
51
+ }
52
+
53
+ void EventHandlerRegistry::processEvent(
54
+ const std::shared_ptr<WorkletRuntime> &uiWorkletRuntime,
55
+ const double eventTimestamp,
56
+ const std::string &eventName,
57
+ const int emitterReactTag,
58
+ const jsi::Value &eventPayload) {
59
+ std::vector<std::shared_ptr<WorkletEventHandler>> handlersForEvent;
60
+ {
61
+ const std::lock_guard<std::mutex> lock(instanceMutex);
62
+ auto handlersIt = eventMappingsWithoutTag.find(eventName);
63
+ if (handlersIt != eventMappingsWithoutTag.end()) {
64
+ for (auto handler : handlersIt->second) {
65
+ handlersForEvent.push_back(handler.second);
66
+ }
67
+ }
68
+ const auto eventHash = std::make_pair(emitterReactTag, eventName);
69
+ auto handlersWithTagIt = eventMappingsWithTag.find(eventHash);
70
+ if (handlersWithTagIt != eventMappingsWithTag.end()) {
71
+ for (auto handler : handlersWithTagIt->second) {
72
+ handlersForEvent.push_back(handler.second);
73
+ }
74
+ }
75
+ }
76
+
77
+ jsi::Runtime &rt = uiWorkletRuntime->getJSIRuntime();
78
+ eventPayload.asObject(rt).setProperty(
79
+ rt, "eventName", jsi::String::createFromUtf8(rt, eventName));
80
+ for (auto handler : handlersForEvent) {
81
+ handler->process(uiWorkletRuntime, eventTimestamp, eventPayload);
82
+ }
83
+ }
84
+
85
+ bool EventHandlerRegistry::isAnyHandlerWaitingForEvent(
86
+ const std::string &eventName,
87
+ const int emitterReactTag) {
88
+ const std::lock_guard<std::mutex> lock(instanceMutex);
89
+ const auto eventHash = std::make_pair(emitterReactTag, eventName);
90
+ auto it = eventMappingsWithTag.find(eventHash);
91
+ return it != eventMappingsWithTag.end() && !it->second.empty();
92
+ }
93
+
94
+ } // namespace worklets
@@ -0,0 +1,49 @@
1
+ #pragma once
2
+
3
+ #include <worklets/WorkletRuntime/WorkletRuntime.h>
4
+
5
+ #include <jsi/jsi.h>
6
+
7
+ #include <map>
8
+ #include <memory>
9
+ #include <mutex>
10
+ #include <string>
11
+ #include <unordered_map>
12
+ #include <utility>
13
+
14
+ using namespace facebook;
15
+
16
+ namespace worklets {
17
+
18
+ class WorkletEventHandler;
19
+
20
+ class EventHandlerRegistry {
21
+ std::map<
22
+ std::pair<int, std::string>,
23
+ std::unordered_map<uint64_t, std::shared_ptr<WorkletEventHandler>>>
24
+ eventMappingsWithTag;
25
+ std::map<
26
+ std::string,
27
+ std::unordered_map<uint64_t, std::shared_ptr<WorkletEventHandler>>>
28
+ eventMappingsWithoutTag;
29
+ std::map<uint64_t, std::shared_ptr<WorkletEventHandler>> eventHandlers;
30
+ std::mutex instanceMutex;
31
+
32
+ public:
33
+ void registerEventHandler(
34
+ const std::shared_ptr<WorkletEventHandler> &eventHandler);
35
+ void unregisterEventHandler(const uint64_t id);
36
+
37
+ void processEvent(
38
+ const std::shared_ptr<WorkletRuntime> &uiWorkletRuntime,
39
+ const double eventTimestamp,
40
+ const std::string &eventName,
41
+ const int emitterReactTag,
42
+ const jsi::Value &eventPayload);
43
+
44
+ bool isAnyHandlerWaitingForEvent(
45
+ const std::string &eventName,
46
+ const int emitterReactTag);
47
+ };
48
+
49
+ } // namespace worklets