@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
|
@@ -1,86 +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
|
|
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
|
package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h
CHANGED
|
@@ -1,47 +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
|
|
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
|
|
@@ -1,68 +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
|
|
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
|
|
@@ -1,68 +1,73 @@
|
|
|
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
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
std::
|
|
63
|
-
std::
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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 clear() {
|
|
21
|
+
map_.clear();
|
|
22
|
+
removableShadowNodes_.clear();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
void update(const ShadowNode::Shared &shadowNode, folly::dynamic &&props);
|
|
26
|
+
|
|
27
|
+
void for_each(std::function<void(
|
|
28
|
+
const ShadowNodeFamily &family,
|
|
29
|
+
const folly::dynamic &props)> callback) const;
|
|
30
|
+
|
|
31
|
+
void remove(const Tag tag);
|
|
32
|
+
|
|
33
|
+
void pauseReanimatedCommits() {
|
|
34
|
+
isPaused_ = true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
bool shouldReanimatedSkipCommit() {
|
|
38
|
+
return isPaused_;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
void unpauseReanimatedCommits() {
|
|
42
|
+
isPaused_ = false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
void pleaseCommitAfterPause() {
|
|
46
|
+
shouldCommitAfterPause_ = true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
bool shouldCommitAfterPause() {
|
|
50
|
+
return shouldCommitAfterPause_.exchange(false);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
bool isEmpty() {
|
|
54
|
+
return map_.empty();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
void markNodeAsRemovable(const ShadowNode::Shared &shadowNode);
|
|
58
|
+
void unmarkNodeAsRemovable(Tag viewTag);
|
|
59
|
+
void handleNodeRemovals(const RootShadowNode &rootShadowNode);
|
|
60
|
+
|
|
61
|
+
private:
|
|
62
|
+
std::unordered_map<Tag, std::pair<ShadowNode::Shared, folly::dynamic>> map_;
|
|
63
|
+
std::unordered_map<Tag, ShadowNode::Shared> removableShadowNodes_;
|
|
64
|
+
|
|
65
|
+
mutable std::mutex mutex_; // Protects `map_`.
|
|
66
|
+
|
|
67
|
+
std::atomic<bool> isPaused_;
|
|
68
|
+
std::atomic<bool> shouldCommitAfterPause_;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
} // namespace reanimated
|
|
72
|
+
|
|
73
|
+
#endif // RCT_NEW_ARCH_ENABLED
|