@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.
- package/LICENSE +21 -21
- package/README.OpenSource +10 -10
- package/README.md +406 -10
- package/harmony/reanimated/BuildProfile.ets +1 -1
- package/harmony/reanimated/build-profile.json5 +11 -11
- package/harmony/reanimated/oh-package-lock.json5 +29 -0
- package/harmony/reanimated/oh-package.json5 +11 -11
- package/harmony/reanimated/src/main/cpp/CMakeLists.txt +2 -0
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.cpp +86 -86
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h +47 -47
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.cpp +68 -68
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.h +73 -68
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.cpp +101 -101
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.h +51 -51
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitShadowNode.h +49 -49
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.cpp +96 -96
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.h +33 -33
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.cpp +95 -95
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.h +29 -29
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationType.h +9 -9
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.cpp +232 -232
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.h +90 -90
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp +870 -870
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h +147 -147
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.cpp +91 -91
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +176 -176
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +971 -971
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h +252 -254
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.cpp +231 -231
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.h +109 -109
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.cpp +56 -56
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.h +20 -20
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp +70 -70
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.h +35 -35
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/CollectionUtils.h +14 -14
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.cpp +5 -5
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.h +19 -19
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h +98 -98
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/ReanimatedSystraceSection.h +135 -135
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +47 -47
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +59 -59
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.cpp +27 -27
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.h +25 -25
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +94 -94
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.h +49 -49
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +8 -8
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +39 -39
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.cpp +326 -326
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.h +345 -345
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.cpp +52 -52
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.h +35 -35
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/Defs.h +10 -10
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.cpp +342 -342
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.h +47 -47
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.cpp +16 -16
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.h +20 -20
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.cpp +20 -20
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.h +29 -29
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/PlatformLogger.h +16 -16
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.cpp +26 -26
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.h +199 -199
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.cpp +95 -95
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.h +19 -19
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/SingleInstanceChecker.h +72 -72
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -49
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.cpp +20 -20
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.h +22 -22
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +29 -29
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.h +41 -41
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +16 -16
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +19 -19
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.cpp +112 -112
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.h +127 -127
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.cpp +53 -53
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.h +22 -22
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RuntimeInitialization.md +191 -191
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +173 -173
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +90 -90
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -36
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +189 -189
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +22 -22
- package/harmony/reanimated/src/main/cpp/ReanimatedModule.cpp +29 -19
- package/harmony/reanimated/src/main/cpp/ReanimatedSensor.cpp +248 -0
- package/harmony/reanimated/src/main/cpp/ReanimatedSensor.h +36 -0
- package/harmony/reanimated/src/main/cpp/ReanimatedSensorContainer.cpp +36 -0
- package/harmony/reanimated/src/main/cpp/ReanimatedSensorContainer.h +23 -0
- package/harmony/reanimated/src/main/cpp/WorkletsModule.cpp +60 -60
- package/harmony/reanimated/src/main/cpp/patches/AnimatedSensor/AnimatedSensorModule.cpp +89 -89
- package/harmony/reanimated/src/main/cpp/patches/NativeModules/ReanimatedModuleProxy.cpp +53 -4
- package/harmony/reanimated/src/main/ets/ReanimatedModule.ts +115 -15
- package/harmony/reanimated/src/main/module.json5 +12 -12
- package/harmony/reanimated/src/main/resources/base/element/color.json +7 -7
- package/harmony/reanimated/src/main/resources/base/element/string.json +15 -15
- package/harmony/reanimated/src/main/resources/base/profile/main_pages.json +5 -5
- package/harmony/reanimated/src/main/resources/en_US/element/string.json +15 -15
- package/harmony/reanimated/src/main/resources/zh_CN/element/string.json +15 -15
- package/harmony/reanimated/ts.ts +6 -6
- package/harmony/reanimated.har +0 -0
- package/package.json +51 -50
|
@@ -0,0 +1,248 @@
|
|
|
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
|
+
#include "ReanimatedSensor.h"
|
|
6
|
+
#include "glog/logging.h"
|
|
7
|
+
#include <memory>
|
|
8
|
+
#include <vector>
|
|
9
|
+
#include <sensors/oh_sensor.h>
|
|
10
|
+
#include <window_manager/oh_display_info.h>
|
|
11
|
+
#include <window_manager/oh_display_manager.h>
|
|
12
|
+
namespace rnoh {
|
|
13
|
+
static std::unordered_map<Sensor_Type, ReanimatedSensor *> g_sensorSubscriberMap_;
|
|
14
|
+
static std::mutex g_subscriberMapMutex_; // 保护映射表的互斥锁
|
|
15
|
+
|
|
16
|
+
void SensorDataCallbackImpl(Sensor_Event *event) {
|
|
17
|
+
if (event == nullptr) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
int64_t timestamp = -1;
|
|
21
|
+
// 获取传感器数据的时间戳。
|
|
22
|
+
int32_t ret = OH_SensorEvent_GetTimestamp(event, ×tamp);
|
|
23
|
+
if (ret != SENSOR_SUCCESS) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
Sensor_Type sensorType;
|
|
27
|
+
// 获取传感器类型。
|
|
28
|
+
ret = OH_SensorEvent_GetType(event, &sensorType);
|
|
29
|
+
if (ret != SENSOR_SUCCESS) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
Sensor_Accuracy accuracy = SENSOR_ACCURACY_UNRELIABLE;
|
|
33
|
+
// 获取传感器数据的精度。
|
|
34
|
+
ret = OH_SensorEvent_GetAccuracy(event, &accuracy);
|
|
35
|
+
if (ret != SENSOR_SUCCESS) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
float *data = nullptr;
|
|
39
|
+
uint32_t length = 0;
|
|
40
|
+
// 获取传感器数据。
|
|
41
|
+
ret = OH_SensorEvent_GetData(event, &data, &length);
|
|
42
|
+
if (ret != SENSOR_SUCCESS || data == nullptr) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
std::lock_guard<std::mutex> lock(g_subscriberMapMutex_);
|
|
47
|
+
auto it = g_sensorSubscriberMap_.find(sensorType);
|
|
48
|
+
if (it == g_sensorSubscriberMap_.end()) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
ReanimatedSensor *sensorInstance = it->second;
|
|
52
|
+
if (sensorInstance == nullptr) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
switch (sensorType) {
|
|
57
|
+
case SENSOR_TYPE_ACCELEROMETER:
|
|
58
|
+
case SENSOR_TYPE_GYROSCOPE:
|
|
59
|
+
case SENSOR_TYPE_GRAVITY:
|
|
60
|
+
case SENSOR_TYPE_MAGNETIC_FIELD: {
|
|
61
|
+
double sendData[] = {
|
|
62
|
+
data[0],
|
|
63
|
+
data[1],
|
|
64
|
+
data[2],
|
|
65
|
+
};
|
|
66
|
+
// 传入 count,由 runSensor 拷贝到堆,避免跨线程 use-after-free
|
|
67
|
+
sensorInstance->runSensor(sendData, 3);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
case SENSOR_TYPE_ROTATION_VECTOR: {
|
|
71
|
+
double sendData[] = {
|
|
72
|
+
data[0], // x
|
|
73
|
+
data[1], // y
|
|
74
|
+
data[2], // z
|
|
75
|
+
data[3], // w
|
|
76
|
+
// ios
|
|
77
|
+
0, // yaw
|
|
78
|
+
0, // pitch
|
|
79
|
+
0 // roll
|
|
80
|
+
};
|
|
81
|
+
sensorInstance->runSensor(sendData, 7);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
default:
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
rnoh::ReanimatedSensor::ReanimatedSensor(int sensorType, int interval, int iosReferenceFrame,
|
|
91
|
+
std::function<void(double *, int)> setter,
|
|
92
|
+
std::function<void(TaskExecutor::Task &&)> runOnTheMainThread)
|
|
93
|
+
: iosReferenceFrame_(iosReferenceFrame), setter_(std::move(setter)),
|
|
94
|
+
runOnTheMainThread_(std::move(runOnTheMainThread)) {
|
|
95
|
+
if (interval == -1) {
|
|
96
|
+
uint32_t refreshRate = 0;
|
|
97
|
+
OH_NativeDisplayManager_GetDefaultDisplayRefreshRate(&refreshRate);
|
|
98
|
+
if (refreshRate > 0) {
|
|
99
|
+
interval_ = refreshRate * 1000000; // 120hz;
|
|
100
|
+
} else {
|
|
101
|
+
interval_ = 200000000;
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
// js unit is milliseconds
|
|
105
|
+
interval_ = interval * 1000000;
|
|
106
|
+
}
|
|
107
|
+
castSensorType(sensorType);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
void rnoh::ReanimatedSensor::castSensorType(int sensorType) {
|
|
112
|
+
if (sensorType == 1) {
|
|
113
|
+
sensorType_ = SENSOR_TYPE_ACCELEROMETER;
|
|
114
|
+
} else if (sensorType == 2) {
|
|
115
|
+
sensorType_ = SENSOR_TYPE_GYROSCOPE;
|
|
116
|
+
} else if (sensorType == 3) {
|
|
117
|
+
sensorType_ = SENSOR_TYPE_GRAVITY;
|
|
118
|
+
} else if (sensorType == 4) {
|
|
119
|
+
sensorType_ = SENSOR_TYPE_MAGNETIC_FIELD;
|
|
120
|
+
} else if (sensorType == 5) {
|
|
121
|
+
sensorType_ = SENSOR_TYPE_ROTATION_VECTOR;
|
|
122
|
+
} else {
|
|
123
|
+
throw std::invalid_argument("[ReanimatedSensor] Unknown sensorType: " + sensorType);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
bool rnoh::ReanimatedSensor::initialize() {
|
|
128
|
+
if (!isSupportSensor()) {
|
|
129
|
+
LOG(ERROR) << "[ReanimatedSensor] is not support, sensorType:" << sensorType_;
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
id_ = OH_Sensor_CreateSubscriptionId();
|
|
133
|
+
if (id_ == nullptr) {
|
|
134
|
+
LOG(ERROR) << "[ReanimatedSensor] create sensor id failed";
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
int32_t res = OH_SensorSubscriptionId_SetType(id_, sensorType_);
|
|
138
|
+
if (res != SENSOR_SUCCESS) {
|
|
139
|
+
LOG(ERROR) << "[ReanimatedSensor] set sensor type failed ,sensorType:" << sensorType_;
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
auto attr = OH_Sensor_CreateSubscriptionAttribute();
|
|
143
|
+
if (attr == nullptr) {
|
|
144
|
+
LOG(ERROR) << "[ReanimatedSensor] create sensor attribute failed";
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
res = OH_SensorSubscriptionAttribute_SetSamplingInterval(attr, interval_);
|
|
149
|
+
if (res != SENSOR_SUCCESS) {
|
|
150
|
+
LOG(ERROR) << "[ReanimatedSensor] set sensor Interval failed, interval_:" << interval_;
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
subSensor_ = OH_Sensor_CreateSubscriber();
|
|
155
|
+
|
|
156
|
+
{
|
|
157
|
+
std::lock_guard<std::mutex> lock(g_subscriberMapMutex_);
|
|
158
|
+
g_sensorSubscriberMap_[sensorType_] = this;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
int32_t ret = OH_SensorSubscriber_SetCallback(subSensor_, SensorDataCallbackImpl);
|
|
162
|
+
if (ret != SENSOR_SUCCESS) {
|
|
163
|
+
LOG(ERROR) << "[ReanimatedSensor] set sensor callback failed";
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
Sensor_Result sensorRes = OH_Sensor_Subscribe(id_, attr, subSensor_);
|
|
167
|
+
if (sensorRes != SENSOR_SUCCESS) {
|
|
168
|
+
LOG(ERROR) << "[ReanimatedSensor] on sensor subscribe failed";
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
bool rnoh::ReanimatedSensor::isSupportSensor() {
|
|
176
|
+
uint32_t count = 0;
|
|
177
|
+
int32_t ret = OH_Sensor_GetInfos(nullptr, &count);
|
|
178
|
+
bool isSupport = false;
|
|
179
|
+
if (count > 0) {
|
|
180
|
+
Sensor_Info **sensors = OH_Sensor_CreateInfos(count);
|
|
181
|
+
ret = OH_Sensor_GetInfos(sensors, &count);
|
|
182
|
+
for (uint32_t i = 0; i < count; ++i) {
|
|
183
|
+
Sensor_Info *sensorInfoTemp = sensors[i];
|
|
184
|
+
Sensor_Type sensorType;
|
|
185
|
+
ret = OH_SensorInfo_GetType(sensorInfoTemp, &sensorType);
|
|
186
|
+
if (sensorType == sensorType_) {
|
|
187
|
+
isSupport = true;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
ret = OH_Sensor_DestroyInfos(sensors, count);
|
|
192
|
+
}
|
|
193
|
+
return isSupport;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
void rnoh::ReanimatedSensor::runSensor(double *value, size_t count) {
|
|
197
|
+
if (value && setter_ && runOnTheMainThread_ && count > 0) {
|
|
198
|
+
// 跨线程传递必须拷贝到堆:传感器回调运行在传感器线程,
|
|
199
|
+
// 而 setter_ 在主线程异步执行,栈上数据此时已释放(use-after-free)。
|
|
200
|
+
auto dataPtr = std::make_shared<std::vector<double>>(value, value + count);
|
|
201
|
+
runOnTheMainThread_([weakSelf = weak_from_this(), dataPtr]() {
|
|
202
|
+
auto self = weakSelf.lock();
|
|
203
|
+
if (!self) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
self->setter_(dataPtr->data(), self->getInterfaceOrientation());
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
int rnoh::ReanimatedSensor::getInterfaceOrientation() {
|
|
212
|
+
NativeDisplayManager_Rotation rotation;
|
|
213
|
+
auto ret = OH_NativeDisplayManager_GetDefaultDisplayRotation(&rotation);
|
|
214
|
+
if (ret == DISPLAY_MANAGER_OK) {
|
|
215
|
+
switch (rotation) {
|
|
216
|
+
case DISPLAY_MANAGER_ROTATION_270:
|
|
217
|
+
return 270;
|
|
218
|
+
case DISPLAY_MANAGER_ROTATION_90:
|
|
219
|
+
return 90;
|
|
220
|
+
case DISPLAY_MANAGER_ROTATION_180:
|
|
221
|
+
return 180;
|
|
222
|
+
default:
|
|
223
|
+
return 0;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return 0;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
void rnoh::ReanimatedSensor::cancel() { destroySensor(); }
|
|
231
|
+
|
|
232
|
+
void rnoh::ReanimatedSensor::destroySensor() {
|
|
233
|
+
std::lock_guard<std::mutex> lock(g_subscriberMapMutex_);
|
|
234
|
+
for (auto it = g_sensorSubscriberMap_.begin(); it != g_sensorSubscriberMap_.end();) {
|
|
235
|
+
if (it->second == this) {
|
|
236
|
+
OH_Sensor_Unsubscribe(it->second->id_, it->second->subSensor_);
|
|
237
|
+
OH_Sensor_DestroySubscriptionId(it->second->id_);
|
|
238
|
+
OH_Sensor_DestroySubscriber(it->second->subSensor_);
|
|
239
|
+
it->second->subSensor_ = nullptr;
|
|
240
|
+
it = g_sensorSubscriberMap_.erase(it);
|
|
241
|
+
} else {
|
|
242
|
+
++it;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
rnoh::ReanimatedSensor::~ReanimatedSensor() { destroySensor(); }
|
|
248
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
#ifndef HARMONY_REANIMATEDSENSOR_H
|
|
6
|
+
#define HARMONY_REANIMATEDSENSOR_H
|
|
7
|
+
#include <functional>
|
|
8
|
+
#include <mutex>
|
|
9
|
+
#include <sensors/oh_sensor_type.h>
|
|
10
|
+
#include "RNOH/TaskExecutor/TaskExecutor.h"
|
|
11
|
+
|
|
12
|
+
namespace rnoh {
|
|
13
|
+
class ReanimatedSensor : public std::enable_shared_from_this<ReanimatedSensor> {
|
|
14
|
+
public:
|
|
15
|
+
ReanimatedSensor(int sensorType, int interval, int iosReferenceFrame, std::function<void(double[], int)> setter,
|
|
16
|
+
std::function<void(TaskExecutor::Task &&)> runOnTheMainThread);
|
|
17
|
+
~ReanimatedSensor();
|
|
18
|
+
bool initialize();
|
|
19
|
+
void cancel();
|
|
20
|
+
void castSensorType(int sensorType);
|
|
21
|
+
void runSensor(double *value, size_t count);
|
|
22
|
+
std::function<void(double[], int)> setter_;
|
|
23
|
+
Sensor_Type sensorType_{SENSOR_TYPE_ACCELEROMETER};
|
|
24
|
+
|
|
25
|
+
private:
|
|
26
|
+
void destroySensor();
|
|
27
|
+
bool isSupportSensor();
|
|
28
|
+
int getInterfaceOrientation();
|
|
29
|
+
int interval_{-1};
|
|
30
|
+
int iosReferenceFrame_{-1};
|
|
31
|
+
Sensor_Subscriber *subSensor_{nullptr};
|
|
32
|
+
Sensor_SubscriptionId *id_{nullptr};
|
|
33
|
+
std::function<void(TaskExecutor::Task &&)> runOnTheMainThread_;
|
|
34
|
+
};
|
|
35
|
+
} // namespace rnoh
|
|
36
|
+
#endif // HARMONY_REANIMATEDSENSOR_H
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
#include "ReanimatedSensorContainer.h"
|
|
6
|
+
#include "glog/logging.h"
|
|
7
|
+
namespace rnoh {
|
|
8
|
+
|
|
9
|
+
rnoh::ReanimatedSensorContainer::ReanimatedSensorContainer() {}
|
|
10
|
+
|
|
11
|
+
int rnoh::ReanimatedSensorContainer::registerSensor(int sensorType, int interval, int iosReferenceFrame,
|
|
12
|
+
std::function<void(double *, int)> setter,
|
|
13
|
+
std::function<void(TaskExecutor::Task &&)> runOnTheMainThread) {
|
|
14
|
+
auto sensor =
|
|
15
|
+
std::make_shared<ReanimatedSensor>(sensorType, interval, iosReferenceFrame, setter, runOnTheMainThread);
|
|
16
|
+
int sensorId = -1;
|
|
17
|
+
if (sensor->initialize()) {
|
|
18
|
+
sensorId = nextSensorId;
|
|
19
|
+
nextSensorId++;
|
|
20
|
+
sensorMap_[sensorId] = sensor;
|
|
21
|
+
}
|
|
22
|
+
return sensorId;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
void rnoh::ReanimatedSensorContainer::unregisterSensor(int sensorId) {
|
|
26
|
+
auto it = sensorMap_.find(sensorId);
|
|
27
|
+
if (it == sensorMap_.end()) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
auto sensor = it->second;
|
|
31
|
+
if (sensor != nullptr) {
|
|
32
|
+
sensor->cancel();
|
|
33
|
+
sensorMap_.erase(it);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
#ifndef HARMONY_REANIMATEDSENSORCONTAINER_H
|
|
6
|
+
#define HARMONY_REANIMATEDSENSORCONTAINER_H
|
|
7
|
+
#include "ReanimatedSensor.h"
|
|
8
|
+
#include <functional>
|
|
9
|
+
namespace rnoh {
|
|
10
|
+
class ReanimatedSensorContainer {
|
|
11
|
+
public:
|
|
12
|
+
ReanimatedSensorContainer();
|
|
13
|
+
~ReanimatedSensorContainer() noexcept = default;
|
|
14
|
+
int registerSensor(int sensorType, int interval, int iosReferenceFrame, std::function<void(double[], int)> setter,
|
|
15
|
+
std::function<void(TaskExecutor::Task &&)> runOnTheMainThread);
|
|
16
|
+
void unregisterSensor(int sensorId);
|
|
17
|
+
|
|
18
|
+
private:
|
|
19
|
+
std::unordered_map<int, std::shared_ptr<ReanimatedSensor>> sensorMap_;
|
|
20
|
+
int nextSensorId{0};
|
|
21
|
+
};
|
|
22
|
+
} // namespace rnoh
|
|
23
|
+
#endif // HARMONY_REANIMATEDSENSORCONTAINER_H
|
|
@@ -1,61 +1,61 @@
|
|
|
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
|
-
#include "RNOH/ArkTSTurboModule.h"
|
|
6
|
-
#include "ReanimatedUIScheduler.h"
|
|
7
|
-
#include "WorkletsModule.h"
|
|
8
|
-
#include "RNRuntimeWorkletDecorator.h"
|
|
9
|
-
#include "PlatformLogger.h"
|
|
10
|
-
|
|
11
|
-
using namespace facebook;
|
|
12
|
-
namespace worklets {
|
|
13
|
-
jsi::Value installTurboModule(facebook::jsi::Runtime &rt, react::TurboModule &turboModule,
|
|
14
|
-
const facebook::jsi::Value *args, size_t count)
|
|
15
|
-
{
|
|
16
|
-
auto self = static_cast<WorkletsModule *>(&turboModule);
|
|
17
|
-
if (count < 1) {
|
|
18
|
-
LOG(ERROR) << "WorkletsModule: Missing required argument";
|
|
19
|
-
return facebook::jsi::Value(false);
|
|
20
|
-
}
|
|
21
|
-
if (!args[0].isString()) {
|
|
22
|
-
LOG(ERROR) << "WorkletsModule: First argument must be a string";
|
|
23
|
-
return facebook::jsi::Value(false);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
std::string valueUnpackerCode = args[0].getString(rt).utf8(rt);
|
|
27
|
-
if (self == nullptr) {
|
|
28
|
-
return facebook::jsi::Value::undefined();
|
|
29
|
-
}
|
|
30
|
-
self->installTurboModule(rt, valueUnpackerCode);
|
|
31
|
-
return facebook::jsi::Value(true);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
WorkletsModule::WorkletsModule(const ArkTSTurboModule::Context ctx, const std::string name)
|
|
35
|
-
: ArkTSTurboModule(ctx, name)
|
|
36
|
-
{
|
|
37
|
-
methodMap_ = { { "installTurboModule", { 0, worklets::installTurboModule } } };
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
WorkletsModule::~WorkletsModule()
|
|
41
|
-
{
|
|
42
|
-
LOG(INFO) << "WorkletsModule::~WorkletsModule";
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
void WorkletsModule::installTurboModule(facebook::jsi::Runtime &runtime, std::string valueUnpackerCode)
|
|
46
|
-
{
|
|
47
|
-
if (workletsModuleProxy_) {
|
|
48
|
-
LOG(WARNING) << "WorkletsModuleProxy already initialized";
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
workletsModuleProxy_ = std::make_shared<WorkletsModuleProxy>(valueUnpackerCode, m_ctx.jsQueue, jsInvoker_,
|
|
53
|
-
std::make_shared<worklets::JSScheduler>(runtime, jsInvoker_),
|
|
54
|
-
std::make_shared<rnoh::ReanimatedUIScheduler>(m_ctx.taskExecutor));
|
|
55
|
-
RNRuntimeWorkletDecorator::decorate(runtime, workletsModuleProxy_);
|
|
56
|
-
}
|
|
57
|
-
std::shared_ptr<worklets::WorkletsModuleProxy> WorkletsModule::getWorkletsModuleProxy()
|
|
58
|
-
{
|
|
59
|
-
return workletsModuleProxy_;
|
|
60
|
-
}
|
|
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
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
6
|
+
#include "ReanimatedUIScheduler.h"
|
|
7
|
+
#include "WorkletsModule.h"
|
|
8
|
+
#include "RNRuntimeWorkletDecorator.h"
|
|
9
|
+
#include "PlatformLogger.h"
|
|
10
|
+
|
|
11
|
+
using namespace facebook;
|
|
12
|
+
namespace worklets {
|
|
13
|
+
jsi::Value installTurboModule(facebook::jsi::Runtime &rt, react::TurboModule &turboModule,
|
|
14
|
+
const facebook::jsi::Value *args, size_t count)
|
|
15
|
+
{
|
|
16
|
+
auto self = static_cast<WorkletsModule *>(&turboModule);
|
|
17
|
+
if (count < 1) {
|
|
18
|
+
LOG(ERROR) << "WorkletsModule: Missing required argument";
|
|
19
|
+
return facebook::jsi::Value(false);
|
|
20
|
+
}
|
|
21
|
+
if (!args[0].isString()) {
|
|
22
|
+
LOG(ERROR) << "WorkletsModule: First argument must be a string";
|
|
23
|
+
return facebook::jsi::Value(false);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
std::string valueUnpackerCode = args[0].getString(rt).utf8(rt);
|
|
27
|
+
if (self == nullptr) {
|
|
28
|
+
return facebook::jsi::Value::undefined();
|
|
29
|
+
}
|
|
30
|
+
self->installTurboModule(rt, valueUnpackerCode);
|
|
31
|
+
return facebook::jsi::Value(true);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
WorkletsModule::WorkletsModule(const ArkTSTurboModule::Context ctx, const std::string name)
|
|
35
|
+
: ArkTSTurboModule(ctx, name)
|
|
36
|
+
{
|
|
37
|
+
methodMap_ = { { "installTurboModule", { 0, worklets::installTurboModule } } };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
WorkletsModule::~WorkletsModule()
|
|
41
|
+
{
|
|
42
|
+
LOG(INFO) << "WorkletsModule::~WorkletsModule";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
void WorkletsModule::installTurboModule(facebook::jsi::Runtime &runtime, std::string valueUnpackerCode)
|
|
46
|
+
{
|
|
47
|
+
if (workletsModuleProxy_) {
|
|
48
|
+
LOG(WARNING) << "WorkletsModuleProxy already initialized";
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
workletsModuleProxy_ = std::make_shared<WorkletsModuleProxy>(valueUnpackerCode, m_ctx.jsQueue, jsInvoker_,
|
|
53
|
+
std::make_shared<worklets::JSScheduler>(runtime, jsInvoker_),
|
|
54
|
+
std::make_shared<rnoh::ReanimatedUIScheduler>(m_ctx.taskExecutor));
|
|
55
|
+
RNRuntimeWorkletDecorator::decorate(runtime, workletsModuleProxy_);
|
|
56
|
+
}
|
|
57
|
+
std::shared_ptr<worklets::WorkletsModuleProxy> WorkletsModule::getWorkletsModuleProxy()
|
|
58
|
+
{
|
|
59
|
+
return workletsModuleProxy_;
|
|
60
|
+
}
|
|
61
61
|
} // namespace worklets
|
|
@@ -1,89 +1,89 @@
|
|
|
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
|
-
if (!sensorId.isNumber()) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
sensorsIds_.erase(sensorId.getNumber());
|
|
79
|
-
platformUnregisterSensorFunction_(sensorId.asNumber());
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
void AnimatedSensorModule::unregisterAllSensors() {
|
|
83
|
-
for (auto sensorId : sensorsIds_) {
|
|
84
|
-
platformUnregisterSensorFunction_(sensorId);
|
|
85
|
-
}
|
|
86
|
-
sensorsIds_.clear();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
} // namespace reanimated
|
|
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
|
+
if (!sensorId.isNumber()) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
sensorsIds_.erase(sensorId.getNumber());
|
|
79
|
+
platformUnregisterSensorFunction_(sensorId.asNumber());
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
void AnimatedSensorModule::unregisterAllSensors() {
|
|
83
|
+
for (auto sensorId : sensorsIds_) {
|
|
84
|
+
platformUnregisterSensorFunction_(sensorId);
|
|
85
|
+
}
|
|
86
|
+
sensorsIds_.clear();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
} // namespace reanimated
|