@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,17 @@
1
+ /**
2
+ * Use these variables when you tailor your ArkTS code. They must be of the const type.
3
+ */
4
+ export const HAR_VERSION = '3.18.1-rc.1';
5
+ export const BUILD_MODE_NAME = 'debug';
6
+ export const DEBUG = true;
7
+ export const TARGET_NAME = 'default';
8
+
9
+ /**
10
+ * BuildProfile Class is used only for compatibility purposes.
11
+ */
12
+ export default class BuildProfile {
13
+ static readonly HAR_VERSION = HAR_VERSION;
14
+ static readonly BUILD_MODE_NAME = BUILD_MODE_NAME;
15
+ static readonly DEBUG = DEBUG;
16
+ static readonly TARGET_NAME = TARGET_NAME;
17
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "apiType": 'stageMode',
3
+ "targets": [
4
+ {
5
+ "name": "default",
6
+ "runtimeOS": "HarmonyOS"
7
+ },
8
+ {
9
+ "name": "ohosTest",
10
+ }
11
+ ]
12
+ }
@@ -0,0 +1,5 @@
1
+ // Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
2
+ // Use of this source code is governed by a MIT license that can be
3
+ // found in the LICENSE file.
4
+
5
+ export { harTasks } from '@ohos/hvigor-ohos-plugin';
@@ -0,0 +1,5 @@
1
+ // Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
2
+ // Use of this source code is governed by a MIT license that can be
3
+ // found in the LICENSE file.
4
+
5
+ export * from './ts'
@@ -0,0 +1,12 @@
1
+ {
2
+ name: '@react-native-ohos/react-native-reanimated',
3
+ version: '3.18.1-rc.1',
4
+ description: "",
5
+ type: 'module',
6
+ main: 'index.ets',
7
+ author: '',
8
+ license: '',
9
+ dependencies: {
10
+ "@rnoh/react-native-openharmony": "file:../react_native_openharmony.har",
11
+ },
12
+ }
@@ -0,0 +1,72 @@
1
+ cmake_minimum_required(VERSION 3.4.1)
2
+ set(CMAKE_VERBOSE_MAKEFILE on)
3
+
4
+ add_compile_definitions(REANIMATED_VERSION=3.18.0)
5
+ add_compile_definitions(JS_RUNTIME_HERMES=1)
6
+ add_compile_definitions(RCT_NEW_ARCH_ENABLED=1)
7
+ add_compile_definitions(HERMES_ENABLE_DEBUGGER=1)
8
+
9
+ set(REANIMATED_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Common")
10
+ set(PATCHES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/patches")
11
+
12
+ file(GLOB rnoh_reanimated_SRC CONFIGURE_DEPENDS *.cpp)
13
+
14
+ add_library(rnoh_reanimated SHARED ${rnoh_reanimated_SRC})
15
+
16
+ target_include_directories(
17
+ rnoh_reanimated
18
+ PRIVATE
19
+ "${REANIMATED_SRC_DIR}/cpp/reanimated/AnimatedSensor"
20
+ "${REANIMATED_SRC_DIR}/cpp/reanimated/Fabric"
21
+ "${REANIMATED_SRC_DIR}/cpp/reanimated/hidden_headers"
22
+ "${REANIMATED_SRC_DIR}/cpp/reanimated/LayoutAnimations"
23
+ "${REANIMATED_SRC_DIR}/cpp/reanimated/NativeModules"
24
+ "${REANIMATED_SRC_DIR}/cpp/reanimated/ReanimatedRuntime"
25
+ "${REANIMATED_SRC_DIR}/cpp/worklets/Registries"
26
+ "${REANIMATED_SRC_DIR}/cpp/worklets/SharedItems"
27
+ "${REANIMATED_SRC_DIR}/cpp/reanimated/Tools"
28
+ "${REANIMATED_SRC_DIR}/cpp/worklets/Tools"
29
+ "${REANIMATED_SRC_DIR}/cpp"
30
+ "${REANIMATED_SRC_DIR}/cpp/worklets/WorkletRuntime"
31
+ "${REANIMATED_SRC_DIR}/cpp/reanimated/RuntimeDecorators"
32
+ )
33
+ target_sources(rnoh_reanimated
34
+ PRIVATE
35
+ # BEGIN: patches
36
+ "${PATCHES_DIR}/Fabric/ShadowTreeCloner.cpp"
37
+ "${PATCHES_DIR}/NativeModules/ReanimatedModuleProxy.cpp"
38
+ "${PATCHES_DIR}/AnimatedSensor/AnimatedSensorModule.cpp"
39
+ # END: patches
40
+ "${REANIMATED_SRC_DIR}/cpp/reanimated/Fabric/PropsRegistry.cpp"
41
+ "${REANIMATED_SRC_DIR}/cpp/reanimated/Fabric/ReanimatedCommitHook.cpp"
42
+ "${REANIMATED_SRC_DIR}/cpp/reanimated/Fabric/ReanimatedMountHook.cpp"
43
+ "${REANIMATED_SRC_DIR}/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.cpp"
44
+ "${REANIMATED_SRC_DIR}/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp"
45
+ "${REANIMATED_SRC_DIR}/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.cpp"
46
+ "${REANIMATED_SRC_DIR}/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.cpp"
47
+ "${REANIMATED_SRC_DIR}/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.cpp"
48
+ "${REANIMATED_SRC_DIR}/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.cpp"
49
+ "${REANIMATED_SRC_DIR}/cpp/worklets/WorkletRuntime/ReanimatedRuntime.cpp"
50
+ "${REANIMATED_SRC_DIR}/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp"
51
+ "${REANIMATED_SRC_DIR}/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp"
52
+ "${REANIMATED_SRC_DIR}/cpp/worklets/Registries/EventHandlerRegistry.cpp"
53
+ "${REANIMATED_SRC_DIR}/cpp/worklets/SharedItems/Shareables.cpp"
54
+ "${REANIMATED_SRC_DIR}/cpp/worklets/Tools/AsyncQueue.cpp"
55
+ "${REANIMATED_SRC_DIR}/cpp/reanimated/Tools/FeaturesConfig.cpp"
56
+ "${REANIMATED_SRC_DIR}/cpp/worklets/Tools/JSISerializer.cpp"
57
+ "${REANIMATED_SRC_DIR}/cpp/worklets/Tools/JSLogger.cpp"
58
+ "${REANIMATED_SRC_DIR}/cpp/worklets/Tools/JSScheduler.cpp"
59
+ "${REANIMATED_SRC_DIR}/cpp/worklets/Tools/ReanimatedJSIUtils.cpp"
60
+ "${REANIMATED_SRC_DIR}/cpp/worklets/Tools/ReanimatedVersion.cpp"
61
+ "${REANIMATED_SRC_DIR}/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp"
62
+ "${REANIMATED_SRC_DIR}/cpp/worklets/Tools/UIScheduler.cpp"
63
+ "${REANIMATED_SRC_DIR}/cpp/worklets/Tools/WorkletEventHandler.cpp"
64
+ "${REANIMATED_SRC_DIR}/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp"
65
+ "${REANIMATED_SRC_DIR}/cpp/worklets/NativeModules/WorkletsModuleProxySpec.cpp"
66
+ "${REANIMATED_SRC_DIR}/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp"
67
+ "${REANIMATED_SRC_DIR}/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp"
68
+ )
69
+
70
+ target_include_directories(rnoh_reanimated PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
71
+ target_link_libraries(rnoh_reanimated PUBLIC rnoh)
72
+
@@ -0,0 +1,86 @@
1
+ #include <reanimated/AnimatedSensor/AnimatedSensorModule.h>
2
+
3
+ #include <utility>
4
+
5
+ namespace reanimated {
6
+
7
+ AnimatedSensorModule::AnimatedSensorModule(
8
+ const PlatformDepMethodsHolder &platformDepMethodsHolder)
9
+ : platformRegisterSensorFunction_(platformDepMethodsHolder.registerSensor),
10
+ platformUnregisterSensorFunction_(
11
+ platformDepMethodsHolder.unregisterSensor) {}
12
+
13
+ AnimatedSensorModule::~AnimatedSensorModule() {
14
+ assert(sensorsIds_.empty());
15
+ }
16
+
17
+ jsi::Value AnimatedSensorModule::registerSensor(
18
+ jsi::Runtime &rt,
19
+ const std::shared_ptr<WorkletRuntime> &uiWorkletRuntime,
20
+ const jsi::Value &sensorTypeValue,
21
+ const jsi::Value &interval,
22
+ const jsi::Value &iosReferenceFrame,
23
+ const jsi::Value &sensorDataHandler) {
24
+ SensorType sensorType = static_cast<SensorType>(sensorTypeValue.asNumber());
25
+
26
+ auto shareableHandler = extractShareableOrThrow<ShareableWorklet>(
27
+ rt,
28
+ sensorDataHandler,
29
+ "[Reanimated] Sensor event handler must be a worklet.");
30
+
31
+ int sensorId = platformRegisterSensorFunction_(
32
+ sensorType,
33
+ interval.asNumber(),
34
+ iosReferenceFrame.asNumber(),
35
+ [sensorType,
36
+ shareableHandler,
37
+ weakUiWorkletRuntime = std::weak_ptr<WorkletRuntime>(uiWorkletRuntime)](
38
+ double newValues[], int orientationDegrees) {
39
+ auto uiWorkletRuntime = weakUiWorkletRuntime.lock();
40
+ if (uiWorkletRuntime == nullptr) {
41
+ return;
42
+ }
43
+
44
+ jsi::Runtime &uiRuntime = uiWorkletRuntime->getJSIRuntime();
45
+ jsi::Object value(uiRuntime);
46
+ if (sensorType == SensorType::ROTATION_VECTOR) {
47
+ // TODO: timestamp should be provided by the platform implementation
48
+ // such that the native side has a chance of providing a true event
49
+ // timestamp
50
+ value.setProperty(uiRuntime, "qx", newValues[0]);
51
+ value.setProperty(uiRuntime, "qy", newValues[1]);
52
+ value.setProperty(uiRuntime, "qz", newValues[2]);
53
+ value.setProperty(uiRuntime, "qw", newValues[3]);
54
+ value.setProperty(uiRuntime, "yaw", newValues[4]);
55
+ value.setProperty(uiRuntime, "pitch", newValues[5]);
56
+ value.setProperty(uiRuntime, "roll", newValues[6]);
57
+ } else {
58
+ value.setProperty(uiRuntime, "x", newValues[0]);
59
+ value.setProperty(uiRuntime, "y", newValues[1]);
60
+ value.setProperty(uiRuntime, "z", newValues[2]);
61
+ }
62
+ value.setProperty(
63
+ uiRuntime, "interfaceOrientation", orientationDegrees);
64
+
65
+ uiWorkletRuntime->runGuarded(shareableHandler, value);
66
+ });
67
+ if (sensorId != -1) {
68
+ sensorsIds_.insert(sensorId);
69
+ }
70
+ return jsi::Value(sensorId);
71
+ }
72
+
73
+ void AnimatedSensorModule::unregisterSensor(const jsi::Value &sensorId) {
74
+ // It is called during sensor hook unmounting
75
+ sensorsIds_.erase(sensorId.getNumber());
76
+ platformUnregisterSensorFunction_(sensorId.asNumber());
77
+ }
78
+
79
+ void AnimatedSensorModule::unregisterAllSensors() {
80
+ for (auto sensorId : sensorsIds_) {
81
+ platformUnregisterSensorFunction_(sensorId);
82
+ }
83
+ sensorsIds_.clear();
84
+ }
85
+
86
+ } // namespace reanimated
@@ -0,0 +1,47 @@
1
+ #pragma once
2
+
3
+ #include <reanimated/Tools/PlatformDepMethodsHolder.h>
4
+
5
+ #include <worklets/SharedItems/Shareables.h>
6
+ #include <worklets/WorkletRuntime/WorkletRuntime.h>
7
+
8
+ #include <jsi/jsi.h>
9
+
10
+ #include <memory>
11
+ #include <unordered_set>
12
+
13
+ namespace reanimated {
14
+
15
+ using namespace facebook;
16
+ using namespace worklets;
17
+
18
+ enum SensorType {
19
+ ACCELEROMETER = 1,
20
+ GYROSCOPE = 2,
21
+ GRAVITY = 3,
22
+ MAGNETIC_FIELD = 4,
23
+ ROTATION_VECTOR = 5,
24
+ };
25
+
26
+ class AnimatedSensorModule {
27
+ std::unordered_set<int> sensorsIds_;
28
+ RegisterSensorFunction platformRegisterSensorFunction_;
29
+ UnregisterSensorFunction platformUnregisterSensorFunction_;
30
+
31
+ public:
32
+ AnimatedSensorModule(
33
+ const PlatformDepMethodsHolder &platformDepMethodsHolder);
34
+ ~AnimatedSensorModule();
35
+
36
+ jsi::Value registerSensor(
37
+ jsi::Runtime &rt,
38
+ const std::shared_ptr<WorkletRuntime> &uiWorkletRuntime,
39
+ const jsi::Value &sensorType,
40
+ const jsi::Value &interval,
41
+ const jsi::Value &iosReferenceFrame,
42
+ const jsi::Value &sensorDataContainer);
43
+ void unregisterSensor(const jsi::Value &sensorId);
44
+ void unregisterAllSensors();
45
+ };
46
+
47
+ } // namespace reanimated
@@ -0,0 +1,68 @@
1
+ #ifdef RCT_NEW_ARCH_ENABLED
2
+
3
+ #include <reanimated/Fabric/PropsRegistry.h>
4
+
5
+ namespace reanimated {
6
+
7
+ std::lock_guard<std::mutex> PropsRegistry::createLock() const {
8
+ return std::lock_guard<std::mutex>(mutex_);
9
+ }
10
+
11
+ void PropsRegistry::update(
12
+ const ShadowNode::Shared &shadowNode,
13
+ folly::dynamic &&props) {
14
+ const auto tag = shadowNode->getTag();
15
+ const auto it = map_.find(tag);
16
+ if (it == map_.cend()) {
17
+ // we need to store ShadowNode because `ShadowNode::getFamily`
18
+ // returns `ShadowNodeFamily const &` which is non-owning
19
+ map_[tag] = std::make_pair(shadowNode, props);
20
+ } else {
21
+ // no need to update `.first` because ShadowNode's family never changes
22
+ // merge new props with old props
23
+ it->second.second.update(props);
24
+ }
25
+ }
26
+
27
+ void PropsRegistry::for_each(std::function<void(
28
+ const ShadowNodeFamily &family,
29
+ const folly::dynamic &props)> callback) const {
30
+ for (const auto &[_, value] : map_) {
31
+ callback(value.first->getFamily(), value.second);
32
+ }
33
+ }
34
+
35
+ void PropsRegistry::markNodeAsRemovable(const ShadowNode::Shared &shadowNode) {
36
+ removableShadowNodes_[shadowNode->getTag()] = shadowNode;
37
+ }
38
+
39
+ void PropsRegistry::unmarkNodeAsRemovable(Tag viewTag) {
40
+ removableShadowNodes_.erase(viewTag);
41
+ }
42
+
43
+ void PropsRegistry::handleNodeRemovals(const RootShadowNode &rootShadowNode) {
44
+ for (auto it = removableShadowNodes_.begin();
45
+ it != removableShadowNodes_.end();) {
46
+ const auto &shadowNode = it->second;
47
+ const auto &family = shadowNode->getFamily();
48
+ const auto &ancestors = family.getAncestors(rootShadowNode);
49
+
50
+ // Skip if the node hasn't been removed
51
+ if (!ancestors.empty()) {
52
+ ++it;
53
+ continue;
54
+ }
55
+
56
+ const auto tag = shadowNode->getTag();
57
+ map_.erase(tag);
58
+ it = removableShadowNodes_.erase(it);
59
+ }
60
+ }
61
+
62
+ void PropsRegistry::remove(const Tag tag) {
63
+ map_.erase(tag);
64
+ }
65
+
66
+ } // namespace reanimated
67
+
68
+ #endif // RCT_NEW_ARCH_ENABLED
@@ -0,0 +1,68 @@
1
+ #pragma once
2
+ #ifdef RCT_NEW_ARCH_ENABLED
3
+
4
+ #include <react/renderer/components/root/RootShadowNode.h>
5
+ #include <react/renderer/core/ShadowNode.h>
6
+
7
+ #include <unordered_map>
8
+ #include <utility>
9
+
10
+ using namespace facebook;
11
+ using namespace react;
12
+
13
+ namespace reanimated {
14
+
15
+ class PropsRegistry {
16
+ public:
17
+ std::lock_guard<std::mutex> createLock() const;
18
+ // returns a lock you need to hold when calling any of the methods below
19
+
20
+ void update(const ShadowNode::Shared &shadowNode, folly::dynamic &&props);
21
+
22
+ void for_each(std::function<void(
23
+ const ShadowNodeFamily &family,
24
+ const folly::dynamic &props)> callback) const;
25
+
26
+ void remove(const Tag tag);
27
+
28
+ void pauseReanimatedCommits() {
29
+ isPaused_ = true;
30
+ }
31
+
32
+ bool shouldReanimatedSkipCommit() {
33
+ return isPaused_;
34
+ }
35
+
36
+ void unpauseReanimatedCommits() {
37
+ isPaused_ = false;
38
+ }
39
+
40
+ void pleaseCommitAfterPause() {
41
+ shouldCommitAfterPause_ = true;
42
+ }
43
+
44
+ bool shouldCommitAfterPause() {
45
+ return shouldCommitAfterPause_.exchange(false);
46
+ }
47
+
48
+ bool isEmpty() {
49
+ return map_.empty();
50
+ }
51
+
52
+ void markNodeAsRemovable(const ShadowNode::Shared &shadowNode);
53
+ void unmarkNodeAsRemovable(Tag viewTag);
54
+ void handleNodeRemovals(const RootShadowNode &rootShadowNode);
55
+
56
+ private:
57
+ std::unordered_map<Tag, std::pair<ShadowNode::Shared, folly::dynamic>> map_;
58
+ std::unordered_map<Tag, ShadowNode::Shared> removableShadowNodes_;
59
+
60
+ mutable std::mutex mutex_; // Protects `map_`.
61
+
62
+ std::atomic<bool> isPaused_;
63
+ std::atomic<bool> shouldCommitAfterPause_;
64
+ };
65
+
66
+ } // namespace reanimated
67
+
68
+ #endif // RCT_NEW_ARCH_ENABLED
@@ -0,0 +1,101 @@
1
+ #ifdef RCT_NEW_ARCH_ENABLED
2
+
3
+ #include <reanimated/Fabric/ReanimatedCommitHook.h>
4
+ #include <reanimated/Fabric/ReanimatedCommitShadowNode.h>
5
+ #include <reanimated/Fabric/ShadowTreeCloner.h>
6
+
7
+ #include <react/renderer/core/ComponentDescriptor.h>
8
+
9
+ #include <unordered_map>
10
+ #include <vector>
11
+
12
+ using namespace facebook::react;
13
+
14
+ namespace reanimated {
15
+
16
+ ReanimatedCommitHook::ReanimatedCommitHook(
17
+ const std::shared_ptr<PropsRegistry> &propsRegistry,
18
+ const std::shared_ptr<UIManager> &uiManager,
19
+ const std::shared_ptr<LayoutAnimationsProxy> &layoutAnimationsProxy)
20
+ : propsRegistry_(propsRegistry),
21
+ uiManager_(uiManager),
22
+ layoutAnimationsProxy_(layoutAnimationsProxy) {
23
+ uiManager_->registerCommitHook(*this);
24
+ }
25
+
26
+ ReanimatedCommitHook::~ReanimatedCommitHook() noexcept {
27
+ uiManager_->unregisterCommitHook(*this);
28
+ }
29
+
30
+ void ReanimatedCommitHook::maybeInitializeLayoutAnimations(
31
+ SurfaceId surfaceId) {
32
+ auto lock = std::unique_lock<std::mutex>(mutex_);
33
+ if (surfaceId > currentMaxSurfaceId_) {
34
+ // when a new surfaceId is observed we call setMountingOverrideDelegate
35
+ // for all yet unseen surfaces
36
+ uiManager_->getShadowTreeRegistry().enumerate(
37
+ [strongThis = shared_from_this()](
38
+ const ShadowTree &shadowTree, bool &stop) {
39
+ // Executed synchronously.
40
+ if (shadowTree.getSurfaceId() <= strongThis->currentMaxSurfaceId_) {
41
+ // the set function actually adds our delegate to a list, so we
42
+ // shouldn't invoke it twice for the same surface
43
+ return;
44
+ }
45
+ shadowTree.getMountingCoordinator()->setMountingOverrideDelegate(
46
+ strongThis->layoutAnimationsProxy_);
47
+ });
48
+ currentMaxSurfaceId_ = surfaceId;
49
+ }
50
+ }
51
+
52
+ RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit(
53
+ ShadowTree const &,
54
+ RootShadowNode::Shared const &,
55
+ RootShadowNode::Unshared const &newRootShadowNode) noexcept {
56
+ maybeInitializeLayoutAnimations(newRootShadowNode->getSurfaceId());
57
+
58
+ auto reaShadowNode =
59
+ std::reinterpret_pointer_cast<ReanimatedCommitShadowNode>(
60
+ newRootShadowNode);
61
+
62
+ if (reaShadowNode->hasReanimatedCommitTrait()) {
63
+ // ShadowTree commited by Reanimated, no need to apply updates from
64
+ // PropsRegistry
65
+ reaShadowNode->unsetReanimatedCommitTrait();
66
+ reaShadowNode->setReanimatedMountTrait();
67
+ return newRootShadowNode;
68
+ }
69
+
70
+ // ShadowTree not commited by Reanimated, apply updates from PropsRegistry
71
+ reaShadowNode->unsetReanimatedMountTrait();
72
+ RootShadowNode::Unshared rootNode = newRootShadowNode;
73
+ PropsMap propsMap;
74
+
75
+ {
76
+ auto lock = propsRegistry_->createLock();
77
+
78
+ propsRegistry_->for_each(
79
+ [&](const ShadowNodeFamily &family, const folly::dynamic &props) {
80
+ propsMap[&family].emplace_back(props);
81
+ });
82
+
83
+ rootNode = cloneShadowTreeWithNewProps(*rootNode, propsMap);
84
+
85
+ // If the commit comes from React Native then pause commits from
86
+ // Reanimated since the ShadowTree to be committed by Reanimated may not
87
+ // include the new changes from React Native yet and all changes of animated
88
+ // props will be applied in ReanimatedCommitHook by iterating over
89
+ // PropsRegistry.
90
+ // This is very important, since if we didn't pause Reanimated commits,
91
+ // it could lead to RN commits being delayed until the animation is finished
92
+ // (very bad).
93
+ propsRegistry_->pauseReanimatedCommits();
94
+ }
95
+
96
+ return rootNode;
97
+ }
98
+
99
+ } // namespace reanimated
100
+
101
+ #endif // RCT_NEW_ARCH_ENABLED
@@ -0,0 +1,51 @@
1
+ #pragma once
2
+ #ifdef RCT_NEW_ARCH_ENABLED
3
+
4
+ #include <reanimated/Fabric/PropsRegistry.h>
5
+ #include <reanimated/LayoutAnimations/LayoutAnimationsProxy.h>
6
+
7
+ #include <react/renderer/uimanager/UIManagerCommitHook.h>
8
+
9
+ #include <memory>
10
+
11
+ using namespace facebook::react;
12
+
13
+ namespace reanimated {
14
+
15
+ class ReanimatedCommitHook
16
+ : public UIManagerCommitHook,
17
+ public std::enable_shared_from_this<ReanimatedCommitHook> {
18
+ public:
19
+ ReanimatedCommitHook(
20
+ const std::shared_ptr<PropsRegistry> &propsRegistry,
21
+ const std::shared_ptr<UIManager> &uiManager,
22
+ const std::shared_ptr<LayoutAnimationsProxy> &layoutAnimationsProxy);
23
+
24
+ ~ReanimatedCommitHook() noexcept override;
25
+
26
+ void commitHookWasRegistered(UIManager const &) noexcept override {}
27
+
28
+ void commitHookWasUnregistered(UIManager const &) noexcept override {}
29
+
30
+ void maybeInitializeLayoutAnimations(SurfaceId surfaceId);
31
+
32
+ RootShadowNode::Unshared shadowTreeWillCommit(
33
+ ShadowTree const &shadowTree,
34
+ RootShadowNode::Shared const &oldRootShadowNode,
35
+ RootShadowNode::Unshared const &newRootShadowNode) noexcept override;
36
+
37
+ private:
38
+ std::shared_ptr<PropsRegistry> propsRegistry_;
39
+
40
+ std::shared_ptr<UIManager> uiManager_;
41
+
42
+ std::shared_ptr<LayoutAnimationsProxy> layoutAnimationsProxy_;
43
+
44
+ SurfaceId currentMaxSurfaceId_ = -1;
45
+
46
+ std::mutex mutex_; // Protects `currentMaxSurfaceId_`.
47
+ };
48
+
49
+ } // namespace reanimated
50
+
51
+ #endif // RCT_NEW_ARCH_ENABLED
@@ -0,0 +1,49 @@
1
+ #pragma once
2
+ #ifdef RCT_NEW_ARCH_ENABLED
3
+
4
+ #include <react/renderer/core/ShadowNode.h>
5
+
6
+ using namespace facebook::react;
7
+
8
+ namespace reanimated {
9
+
10
+ // We use this trait to mark that a commit was created by Reanimated.
11
+ // Traits are copied when nodes are cloned, so this information
12
+ // won't be lost unless someone explicitly overrides it.
13
+ // We need this information to skip unnecessary updates in
14
+ // the commit hook.
15
+ // Currently RN traits go up to 10, so hopefully
16
+ // the arbitrarily chosen numbers 27 and 28 will be safe :)
17
+
18
+ // We have to use 2 traits, because we want to distinguish reanimated
19
+ // commits both in the commit hook and mount hook. If we only had one trait
20
+ // and didn't remove it in the commit hook, then any node that would clone
21
+ // this node would also have our commit trait, rendering this trait useless.
22
+ constexpr ShadowNodeTraits::Trait ReanimatedCommitTrait{1 << 27};
23
+ constexpr ShadowNodeTraits::Trait ReanimatedMountTrait{1 << 28};
24
+
25
+ class ReanimatedCommitShadowNode : public ShadowNode {
26
+ public:
27
+ inline void setReanimatedCommitTrait() {
28
+ traits_.set(ReanimatedCommitTrait);
29
+ }
30
+ inline void unsetReanimatedCommitTrait() {
31
+ traits_.unset(ReanimatedCommitTrait);
32
+ }
33
+ inline bool hasReanimatedCommitTrait() {
34
+ return traits_.check(ReanimatedCommitTrait);
35
+ }
36
+ inline void setReanimatedMountTrait() {
37
+ traits_.set(ReanimatedMountTrait);
38
+ }
39
+ inline void unsetReanimatedMountTrait() {
40
+ traits_.unset(ReanimatedMountTrait);
41
+ }
42
+ inline bool hasReanimatedMountTrait() {
43
+ return traits_.check(ReanimatedMountTrait);
44
+ }
45
+ };
46
+
47
+ } // namespace reanimated
48
+
49
+ #endif // RCT_NEW_ARCH_ENABLED