@react-native-ohos/react-native-reanimated 3.18.1-rc.6 → 3.18.2-rc.2
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 +10 -10
- package/harmony/reanimated/BuildProfile.ets +16 -16
- package/harmony/reanimated/build-profile.json5 +11 -11
- package/harmony/reanimated/oh-package.json5 +11 -11
- 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 +68 -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 -87
- 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 -252
- 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 -155
- 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 -182
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +22 -22
- 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/ets/ReanimatedModule.ts +7 -0
- 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 +50 -50
|
@@ -1,199 +1,199 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <jsi/jsi.h>
|
|
4
|
-
#include <sstream>
|
|
5
|
-
#include <string>
|
|
6
|
-
#include <tuple>
|
|
7
|
-
#include <utility>
|
|
8
|
-
|
|
9
|
-
using namespace facebook;
|
|
10
|
-
|
|
11
|
-
namespace worklets::jsi_utils {
|
|
12
|
-
|
|
13
|
-
// `get` functions take a pointer to `jsi::Value` and
|
|
14
|
-
// call an appropriate method to cast to the native type
|
|
15
|
-
template <typename T>
|
|
16
|
-
inline T get(jsi::Runtime &rt, const jsi::Value *value);
|
|
17
|
-
|
|
18
|
-
template <>
|
|
19
|
-
inline double get<double>(jsi::Runtime &, const jsi::Value *value) {
|
|
20
|
-
return value->asNumber();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
template <>
|
|
24
|
-
inline int get<int>(jsi::Runtime &, const jsi::Value *value) {
|
|
25
|
-
return value->asNumber();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
template <>
|
|
29
|
-
inline bool get<bool>(jsi::Runtime &, const jsi::Value *value) {
|
|
30
|
-
if (!value->isBool()) {
|
|
31
|
-
throw jsi::JSINativeException("[Reanimated] Expected a boolean.");
|
|
32
|
-
}
|
|
33
|
-
return value->getBool();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
template <>
|
|
37
|
-
inline jsi::Object get<jsi::Object>(jsi::Runtime &rt, const jsi::Value *value) {
|
|
38
|
-
return value->asObject(rt);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
template <>
|
|
42
|
-
inline jsi::Value const &get<jsi::Value const &>(
|
|
43
|
-
jsi::Runtime &,
|
|
44
|
-
const jsi::Value *value) {
|
|
45
|
-
return *value;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// `convertArgs` functions take a variadic template parameter of target (C++)
|
|
49
|
-
// argument types `Targs` and a `jsi::Value` array `args`, and converts `args`
|
|
50
|
-
// to a tuple of typed C++ arguments to be passed to the native implementation.
|
|
51
|
-
// This is accomplished by dispatching (at compile time) to the correct
|
|
52
|
-
// implementation based on the first type of `Targs`, using SFINAE to select the
|
|
53
|
-
// correct specialization, and concatenating with the result of recursion on the
|
|
54
|
-
// rest of `Targs`
|
|
55
|
-
|
|
56
|
-
// BEGIN implementations for `convertArgs` specializations.
|
|
57
|
-
// specialization for empty `Targs` - returns an empty tuple
|
|
58
|
-
template <typename... Args>
|
|
59
|
-
inline std::enable_if_t<(sizeof...(Args) == 0), std::tuple<>> convertArgs(
|
|
60
|
-
jsi::Runtime &,
|
|
61
|
-
const jsi::Value *) {
|
|
62
|
-
return std::make_tuple();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// calls `get<First>` on the first argument to retrieve the native type,
|
|
66
|
-
// then calls recursively on the rest of `args`
|
|
67
|
-
// and returns the concatenation of results
|
|
68
|
-
template <typename T, typename... Rest>
|
|
69
|
-
inline std::tuple<T, Rest...> convertArgs(
|
|
70
|
-
jsi::Runtime &rt,
|
|
71
|
-
const jsi::Value *args) {
|
|
72
|
-
auto arg = std::tuple<T>(get<T>(rt, args));
|
|
73
|
-
auto rest = convertArgs<Rest...>(rt, std::next(args));
|
|
74
|
-
return std::tuple_cat(std::move(arg), std::move(rest));
|
|
75
|
-
}
|
|
76
|
-
// END implementations for `convertArgs` specializations.
|
|
77
|
-
|
|
78
|
-
// returns a tuple with the result of casting `args` to appropriate
|
|
79
|
-
// native C++ types needed to call `function`
|
|
80
|
-
template <typename Ret, typename... Args>
|
|
81
|
-
std::tuple<Args...> getArgsForFunction(
|
|
82
|
-
std::function<Ret(Args...)>,
|
|
83
|
-
jsi::Runtime &rt,
|
|
84
|
-
const jsi::Value *args,
|
|
85
|
-
const size_t count) {
|
|
86
|
-
assert(sizeof...(Args) == count);
|
|
87
|
-
return convertArgs<Args...>(rt, args);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// returns a tuple with the result of casting `args` to appropriate
|
|
91
|
-
// native C++ types needed to call `function`,
|
|
92
|
-
// passing `rt` as the first argument
|
|
93
|
-
template <typename Ret, typename... Args>
|
|
94
|
-
std::tuple<jsi::Runtime &, Args...> getArgsForFunction(
|
|
95
|
-
std::function<Ret(jsi::Runtime &, Args...)>,
|
|
96
|
-
jsi::Runtime &rt,
|
|
97
|
-
const jsi::Value *args,
|
|
98
|
-
const size_t count) {
|
|
99
|
-
assert(sizeof...(Args) == count);
|
|
100
|
-
return std::tuple_cat(std::tie(rt), convertArgs<Args...>(rt, args));
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// calls `function` with `args`
|
|
104
|
-
template <typename Ret, typename... Args>
|
|
105
|
-
inline jsi::Value apply(
|
|
106
|
-
std::function<Ret(Args...)> function,
|
|
107
|
-
std::tuple<Args...> args) {
|
|
108
|
-
return std::apply(function, std::move(args));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// calls string-returning `function` with `args`,
|
|
112
|
-
// and returns the string
|
|
113
|
-
template <typename... Args>
|
|
114
|
-
inline jsi::Value apply(
|
|
115
|
-
jsi::Runtime &rt,
|
|
116
|
-
std::function<std::string(Args...)> function,
|
|
117
|
-
std::tuple<Args...> args) {
|
|
118
|
-
return jsi::String::createFromUtf8(rt, std::apply(function, std::move(args)));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// calls void-returning `function` with `args`,
|
|
122
|
-
// and returns `undefined`
|
|
123
|
-
template <typename... Args>
|
|
124
|
-
inline jsi::Value apply(
|
|
125
|
-
std::function<void(Args...)> function,
|
|
126
|
-
std::tuple<Args...> args) {
|
|
127
|
-
std::apply(function, std::move(args));
|
|
128
|
-
return jsi::Value::undefined();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// returns a function with JSI calling convention
|
|
132
|
-
// from a native function `function`
|
|
133
|
-
template <typename Fun>
|
|
134
|
-
jsi::HostFunctionType createHostFunction(Fun function) {
|
|
135
|
-
return [function](
|
|
136
|
-
jsi::Runtime &rt,
|
|
137
|
-
const jsi::Value &,
|
|
138
|
-
const jsi::Value *args,
|
|
139
|
-
const size_t count) {
|
|
140
|
-
auto argz = getArgsForFunction(function, rt, args, count);
|
|
141
|
-
return apply(function, std::move(argz));
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// returns a function with JSI calling convention
|
|
146
|
-
// from a native function `function` returning a string
|
|
147
|
-
template <typename... Args>
|
|
148
|
-
jsi::HostFunctionType createHostFunction(
|
|
149
|
-
std::function<std::string(Args...)> function) {
|
|
150
|
-
return [function](
|
|
151
|
-
jsi::Runtime &rt,
|
|
152
|
-
const jsi::Value &,
|
|
153
|
-
const jsi::Value *args,
|
|
154
|
-
const size_t count) {
|
|
155
|
-
auto argz = getArgsForFunction(function, rt, args, count);
|
|
156
|
-
return apply(rt, function, std::move(argz));
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// used to determine if `function<Ret(Args...)>`
|
|
161
|
-
// takes `Runtime &` as its first argument
|
|
162
|
-
template <typename... Args>
|
|
163
|
-
struct takes_runtime {
|
|
164
|
-
static constexpr size_t value = 0;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
// specialization for `function<Ret(Runtime &, Rest...)`
|
|
168
|
-
template <typename... Rest>
|
|
169
|
-
struct takes_runtime<jsi::Runtime &, Rest...> {
|
|
170
|
-
static constexpr size_t value = 1;
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
// creates a JSI compatible function from `function`
|
|
174
|
-
// and installs it as a global function named `name`
|
|
175
|
-
// in the `rt` JS runtime
|
|
176
|
-
template <typename Ret, typename... Args>
|
|
177
|
-
void installJsiFunction(
|
|
178
|
-
jsi::Runtime &rt,
|
|
179
|
-
std::string_view name,
|
|
180
|
-
std::function<Ret(Args...)> function) {
|
|
181
|
-
auto clb = createHostFunction(function);
|
|
182
|
-
auto argsCount = sizeof...(Args) - takes_runtime<Args...>::value;
|
|
183
|
-
jsi::Value jsiFunction = jsi::Function::createFromHostFunction(
|
|
184
|
-
rt, jsi::PropNameID::forAscii(rt, name.data()), argsCount, clb);
|
|
185
|
-
rt.global().setProperty(rt, name.data(), jsiFunction);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// this should take care of passing types convertible to `function`
|
|
189
|
-
template <typename Fun>
|
|
190
|
-
void installJsiFunction(jsi::Runtime &rt, std::string_view name, Fun function) {
|
|
191
|
-
installJsiFunction(rt, name, std::function(std::forward<Fun>(function)));
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
jsi::Array convertStringToArray(
|
|
195
|
-
jsi::Runtime &rt,
|
|
196
|
-
const std::string &value,
|
|
197
|
-
const unsigned int expectedSize);
|
|
198
|
-
|
|
199
|
-
} // namespace worklets::jsi_utils
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <sstream>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <tuple>
|
|
7
|
+
#include <utility>
|
|
8
|
+
|
|
9
|
+
using namespace facebook;
|
|
10
|
+
|
|
11
|
+
namespace worklets::jsi_utils {
|
|
12
|
+
|
|
13
|
+
// `get` functions take a pointer to `jsi::Value` and
|
|
14
|
+
// call an appropriate method to cast to the native type
|
|
15
|
+
template <typename T>
|
|
16
|
+
inline T get(jsi::Runtime &rt, const jsi::Value *value);
|
|
17
|
+
|
|
18
|
+
template <>
|
|
19
|
+
inline double get<double>(jsi::Runtime &, const jsi::Value *value) {
|
|
20
|
+
return value->asNumber();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
template <>
|
|
24
|
+
inline int get<int>(jsi::Runtime &, const jsi::Value *value) {
|
|
25
|
+
return value->asNumber();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
template <>
|
|
29
|
+
inline bool get<bool>(jsi::Runtime &, const jsi::Value *value) {
|
|
30
|
+
if (!value->isBool()) {
|
|
31
|
+
throw jsi::JSINativeException("[Reanimated] Expected a boolean.");
|
|
32
|
+
}
|
|
33
|
+
return value->getBool();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
template <>
|
|
37
|
+
inline jsi::Object get<jsi::Object>(jsi::Runtime &rt, const jsi::Value *value) {
|
|
38
|
+
return value->asObject(rt);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
template <>
|
|
42
|
+
inline jsi::Value const &get<jsi::Value const &>(
|
|
43
|
+
jsi::Runtime &,
|
|
44
|
+
const jsi::Value *value) {
|
|
45
|
+
return *value;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// `convertArgs` functions take a variadic template parameter of target (C++)
|
|
49
|
+
// argument types `Targs` and a `jsi::Value` array `args`, and converts `args`
|
|
50
|
+
// to a tuple of typed C++ arguments to be passed to the native implementation.
|
|
51
|
+
// This is accomplished by dispatching (at compile time) to the correct
|
|
52
|
+
// implementation based on the first type of `Targs`, using SFINAE to select the
|
|
53
|
+
// correct specialization, and concatenating with the result of recursion on the
|
|
54
|
+
// rest of `Targs`
|
|
55
|
+
|
|
56
|
+
// BEGIN implementations for `convertArgs` specializations.
|
|
57
|
+
// specialization for empty `Targs` - returns an empty tuple
|
|
58
|
+
template <typename... Args>
|
|
59
|
+
inline std::enable_if_t<(sizeof...(Args) == 0), std::tuple<>> convertArgs(
|
|
60
|
+
jsi::Runtime &,
|
|
61
|
+
const jsi::Value *) {
|
|
62
|
+
return std::make_tuple();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// calls `get<First>` on the first argument to retrieve the native type,
|
|
66
|
+
// then calls recursively on the rest of `args`
|
|
67
|
+
// and returns the concatenation of results
|
|
68
|
+
template <typename T, typename... Rest>
|
|
69
|
+
inline std::tuple<T, Rest...> convertArgs(
|
|
70
|
+
jsi::Runtime &rt,
|
|
71
|
+
const jsi::Value *args) {
|
|
72
|
+
auto arg = std::tuple<T>(get<T>(rt, args));
|
|
73
|
+
auto rest = convertArgs<Rest...>(rt, std::next(args));
|
|
74
|
+
return std::tuple_cat(std::move(arg), std::move(rest));
|
|
75
|
+
}
|
|
76
|
+
// END implementations for `convertArgs` specializations.
|
|
77
|
+
|
|
78
|
+
// returns a tuple with the result of casting `args` to appropriate
|
|
79
|
+
// native C++ types needed to call `function`
|
|
80
|
+
template <typename Ret, typename... Args>
|
|
81
|
+
std::tuple<Args...> getArgsForFunction(
|
|
82
|
+
std::function<Ret(Args...)>,
|
|
83
|
+
jsi::Runtime &rt,
|
|
84
|
+
const jsi::Value *args,
|
|
85
|
+
const size_t count) {
|
|
86
|
+
assert(sizeof...(Args) == count);
|
|
87
|
+
return convertArgs<Args...>(rt, args);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// returns a tuple with the result of casting `args` to appropriate
|
|
91
|
+
// native C++ types needed to call `function`,
|
|
92
|
+
// passing `rt` as the first argument
|
|
93
|
+
template <typename Ret, typename... Args>
|
|
94
|
+
std::tuple<jsi::Runtime &, Args...> getArgsForFunction(
|
|
95
|
+
std::function<Ret(jsi::Runtime &, Args...)>,
|
|
96
|
+
jsi::Runtime &rt,
|
|
97
|
+
const jsi::Value *args,
|
|
98
|
+
const size_t count) {
|
|
99
|
+
assert(sizeof...(Args) == count);
|
|
100
|
+
return std::tuple_cat(std::tie(rt), convertArgs<Args...>(rt, args));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// calls `function` with `args`
|
|
104
|
+
template <typename Ret, typename... Args>
|
|
105
|
+
inline jsi::Value apply(
|
|
106
|
+
std::function<Ret(Args...)> function,
|
|
107
|
+
std::tuple<Args...> args) {
|
|
108
|
+
return std::apply(function, std::move(args));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// calls string-returning `function` with `args`,
|
|
112
|
+
// and returns the string
|
|
113
|
+
template <typename... Args>
|
|
114
|
+
inline jsi::Value apply(
|
|
115
|
+
jsi::Runtime &rt,
|
|
116
|
+
std::function<std::string(Args...)> function,
|
|
117
|
+
std::tuple<Args...> args) {
|
|
118
|
+
return jsi::String::createFromUtf8(rt, std::apply(function, std::move(args)));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// calls void-returning `function` with `args`,
|
|
122
|
+
// and returns `undefined`
|
|
123
|
+
template <typename... Args>
|
|
124
|
+
inline jsi::Value apply(
|
|
125
|
+
std::function<void(Args...)> function,
|
|
126
|
+
std::tuple<Args...> args) {
|
|
127
|
+
std::apply(function, std::move(args));
|
|
128
|
+
return jsi::Value::undefined();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// returns a function with JSI calling convention
|
|
132
|
+
// from a native function `function`
|
|
133
|
+
template <typename Fun>
|
|
134
|
+
jsi::HostFunctionType createHostFunction(Fun function) {
|
|
135
|
+
return [function](
|
|
136
|
+
jsi::Runtime &rt,
|
|
137
|
+
const jsi::Value &,
|
|
138
|
+
const jsi::Value *args,
|
|
139
|
+
const size_t count) {
|
|
140
|
+
auto argz = getArgsForFunction(function, rt, args, count);
|
|
141
|
+
return apply(function, std::move(argz));
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// returns a function with JSI calling convention
|
|
146
|
+
// from a native function `function` returning a string
|
|
147
|
+
template <typename... Args>
|
|
148
|
+
jsi::HostFunctionType createHostFunction(
|
|
149
|
+
std::function<std::string(Args...)> function) {
|
|
150
|
+
return [function](
|
|
151
|
+
jsi::Runtime &rt,
|
|
152
|
+
const jsi::Value &,
|
|
153
|
+
const jsi::Value *args,
|
|
154
|
+
const size_t count) {
|
|
155
|
+
auto argz = getArgsForFunction(function, rt, args, count);
|
|
156
|
+
return apply(rt, function, std::move(argz));
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// used to determine if `function<Ret(Args...)>`
|
|
161
|
+
// takes `Runtime &` as its first argument
|
|
162
|
+
template <typename... Args>
|
|
163
|
+
struct takes_runtime {
|
|
164
|
+
static constexpr size_t value = 0;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// specialization for `function<Ret(Runtime &, Rest...)`
|
|
168
|
+
template <typename... Rest>
|
|
169
|
+
struct takes_runtime<jsi::Runtime &, Rest...> {
|
|
170
|
+
static constexpr size_t value = 1;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// creates a JSI compatible function from `function`
|
|
174
|
+
// and installs it as a global function named `name`
|
|
175
|
+
// in the `rt` JS runtime
|
|
176
|
+
template <typename Ret, typename... Args>
|
|
177
|
+
void installJsiFunction(
|
|
178
|
+
jsi::Runtime &rt,
|
|
179
|
+
std::string_view name,
|
|
180
|
+
std::function<Ret(Args...)> function) {
|
|
181
|
+
auto clb = createHostFunction(function);
|
|
182
|
+
auto argsCount = sizeof...(Args) - takes_runtime<Args...>::value;
|
|
183
|
+
jsi::Value jsiFunction = jsi::Function::createFromHostFunction(
|
|
184
|
+
rt, jsi::PropNameID::forAscii(rt, name.data()), argsCount, clb);
|
|
185
|
+
rt.global().setProperty(rt, name.data(), jsiFunction);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// this should take care of passing types convertible to `function`
|
|
189
|
+
template <typename Fun>
|
|
190
|
+
void installJsiFunction(jsi::Runtime &rt, std::string_view name, Fun function) {
|
|
191
|
+
installJsiFunction(rt, name, std::function(std::forward<Fun>(function)));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
jsi::Array convertStringToArray(
|
|
195
|
+
jsi::Runtime &rt,
|
|
196
|
+
const std::string &value,
|
|
197
|
+
const unsigned int expectedSize);
|
|
198
|
+
|
|
199
|
+
} // namespace worklets::jsi_utils
|
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
#include <worklets/Tools/JSLogger.h>
|
|
2
|
-
#include <worklets/Tools/ReanimatedVersion.h>
|
|
3
|
-
|
|
4
|
-
#include <memory>
|
|
5
|
-
#include <regex>
|
|
6
|
-
#include <string>
|
|
7
|
-
|
|
8
|
-
#ifdef REANIMATED_VERSION
|
|
9
|
-
#define STRINGIZE(x) #x
|
|
10
|
-
#define STRINGIZE2(x) STRINGIZE(x)
|
|
11
|
-
#define REANIMATED_VERSION_STRING STRINGIZE2(REANIMATED_VERSION)
|
|
12
|
-
#endif // REANIMATED_VERSION
|
|
13
|
-
|
|
14
|
-
using namespace facebook;
|
|
15
|
-
|
|
16
|
-
namespace worklets {
|
|
17
|
-
|
|
18
|
-
std::string getReanimatedCppVersion() {
|
|
19
|
-
return std::string(REANIMATED_VERSION_STRING);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
void injectReanimatedCppVersion(jsi::Runtime &rnRuntime) {
|
|
23
|
-
auto version = getReanimatedCppVersion();
|
|
24
|
-
rnRuntime.global().setProperty(
|
|
25
|
-
rnRuntime,
|
|
26
|
-
"_REANIMATED_VERSION_CPP",
|
|
27
|
-
jsi::String::createFromUtf8(rnRuntime, version));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
#ifndef NDEBUG
|
|
31
|
-
// This function is pretty much a copy of
|
|
32
|
-
// `src/reanimated2/platform-specific/checkVersion.ts`.
|
|
33
|
-
bool matchVersion(const std::string &version1, const std::string &version2) {
|
|
34
|
-
std::regex pattern("^\\d+\\.\\d+\\.\\d+$");
|
|
35
|
-
if (std::regex_match(version1, pattern) &&
|
|
36
|
-
std::regex_match(version2, pattern)) {
|
|
37
|
-
auto majorPattern = std::regex("^\\d+");
|
|
38
|
-
auto major1 = std::regex_search(version1, majorPattern);
|
|
39
|
-
auto major2 = std::regex_search(version2, majorPattern);
|
|
40
|
-
if (major1 != major2) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
auto minorPattern = std::regex("\\.\\d+\\.");
|
|
44
|
-
auto minor1 = std::regex_search(version1, minorPattern);
|
|
45
|
-
auto minor2 = std::regex_search(version2, minorPattern);
|
|
46
|
-
if (minor1 != minor2) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
return true;
|
|
50
|
-
} else {
|
|
51
|
-
return version1 == version2;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
void checkJSVersion(
|
|
56
|
-
jsi::Runtime &rnRuntime,
|
|
57
|
-
const std::shared_ptr<JSLogger> &jsLogger) {
|
|
58
|
-
auto cppVersion = getReanimatedCppVersion();
|
|
59
|
-
|
|
60
|
-
auto maybeJSVersion =
|
|
61
|
-
rnRuntime.global().getProperty(rnRuntime, "_REANIMATED_VERSION_JS");
|
|
62
|
-
if (maybeJSVersion.isUndefined()) {
|
|
63
|
-
jsLogger->warnOnJS(
|
|
64
|
-
std::string(
|
|
65
|
-
"[Reanimated] C++ side failed to resolve JavaScript code version\n") +
|
|
66
|
-
"See `https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#c-side-failed-to-resolve-javascript-code-version` for more details.");
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
auto jsVersion = maybeJSVersion.asString(rnRuntime).utf8(rnRuntime);
|
|
71
|
-
|
|
72
|
-
if (!matchVersion(cppVersion, jsVersion)) {
|
|
73
|
-
jsLogger->warnOnJS(
|
|
74
|
-
std::string(
|
|
75
|
-
"[Reanimated] Mismatch between C++ code version and JavaScript code version (") +
|
|
76
|
-
cppVersion + " vs. " + jsVersion + " respectively).\n" +
|
|
77
|
-
"See `https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#mismatch-between-c-code-version-and-javascript-code-version` for more details.");
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
#else
|
|
82
|
-
void checkJSVersion(
|
|
83
|
-
jsi::Runtime &rnRuntime,
|
|
84
|
-
const std::shared_ptr<worklets::JSLogger> &jsLogger) {
|
|
85
|
-
// In release builds we don't check the version, hence
|
|
86
|
-
// this function is a NOOP.
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
bool matchVersion(const std::string &version1, const std::string &version2) {
|
|
90
|
-
// Stub implementation for release builds.
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
#endif // NDEBUG
|
|
94
|
-
|
|
95
|
-
}; // namespace worklets
|
|
1
|
+
#include <worklets/Tools/JSLogger.h>
|
|
2
|
+
#include <worklets/Tools/ReanimatedVersion.h>
|
|
3
|
+
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <regex>
|
|
6
|
+
#include <string>
|
|
7
|
+
|
|
8
|
+
#ifdef REANIMATED_VERSION
|
|
9
|
+
#define STRINGIZE(x) #x
|
|
10
|
+
#define STRINGIZE2(x) STRINGIZE(x)
|
|
11
|
+
#define REANIMATED_VERSION_STRING STRINGIZE2(REANIMATED_VERSION)
|
|
12
|
+
#endif // REANIMATED_VERSION
|
|
13
|
+
|
|
14
|
+
using namespace facebook;
|
|
15
|
+
|
|
16
|
+
namespace worklets {
|
|
17
|
+
|
|
18
|
+
std::string getReanimatedCppVersion() {
|
|
19
|
+
return std::string(REANIMATED_VERSION_STRING);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
void injectReanimatedCppVersion(jsi::Runtime &rnRuntime) {
|
|
23
|
+
auto version = getReanimatedCppVersion();
|
|
24
|
+
rnRuntime.global().setProperty(
|
|
25
|
+
rnRuntime,
|
|
26
|
+
"_REANIMATED_VERSION_CPP",
|
|
27
|
+
jsi::String::createFromUtf8(rnRuntime, version));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
#ifndef NDEBUG
|
|
31
|
+
// This function is pretty much a copy of
|
|
32
|
+
// `src/reanimated2/platform-specific/checkVersion.ts`.
|
|
33
|
+
bool matchVersion(const std::string &version1, const std::string &version2) {
|
|
34
|
+
std::regex pattern("^\\d+\\.\\d+\\.\\d+$");
|
|
35
|
+
if (std::regex_match(version1, pattern) &&
|
|
36
|
+
std::regex_match(version2, pattern)) {
|
|
37
|
+
auto majorPattern = std::regex("^\\d+");
|
|
38
|
+
auto major1 = std::regex_search(version1, majorPattern);
|
|
39
|
+
auto major2 = std::regex_search(version2, majorPattern);
|
|
40
|
+
if (major1 != major2) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
auto minorPattern = std::regex("\\.\\d+\\.");
|
|
44
|
+
auto minor1 = std::regex_search(version1, minorPattern);
|
|
45
|
+
auto minor2 = std::regex_search(version2, minorPattern);
|
|
46
|
+
if (minor1 != minor2) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
} else {
|
|
51
|
+
return version1 == version2;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
void checkJSVersion(
|
|
56
|
+
jsi::Runtime &rnRuntime,
|
|
57
|
+
const std::shared_ptr<JSLogger> &jsLogger) {
|
|
58
|
+
auto cppVersion = getReanimatedCppVersion();
|
|
59
|
+
|
|
60
|
+
auto maybeJSVersion =
|
|
61
|
+
rnRuntime.global().getProperty(rnRuntime, "_REANIMATED_VERSION_JS");
|
|
62
|
+
if (maybeJSVersion.isUndefined()) {
|
|
63
|
+
jsLogger->warnOnJS(
|
|
64
|
+
std::string(
|
|
65
|
+
"[Reanimated] C++ side failed to resolve JavaScript code version\n") +
|
|
66
|
+
"See `https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#c-side-failed-to-resolve-javascript-code-version` for more details.");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
auto jsVersion = maybeJSVersion.asString(rnRuntime).utf8(rnRuntime);
|
|
71
|
+
|
|
72
|
+
if (!matchVersion(cppVersion, jsVersion)) {
|
|
73
|
+
jsLogger->warnOnJS(
|
|
74
|
+
std::string(
|
|
75
|
+
"[Reanimated] Mismatch between C++ code version and JavaScript code version (") +
|
|
76
|
+
cppVersion + " vs. " + jsVersion + " respectively).\n" +
|
|
77
|
+
"See `https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#mismatch-between-c-code-version-and-javascript-code-version` for more details.");
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
#else
|
|
82
|
+
void checkJSVersion(
|
|
83
|
+
jsi::Runtime &rnRuntime,
|
|
84
|
+
const std::shared_ptr<worklets::JSLogger> &jsLogger) {
|
|
85
|
+
// In release builds we don't check the version, hence
|
|
86
|
+
// this function is a NOOP.
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
bool matchVersion(const std::string &version1, const std::string &version2) {
|
|
90
|
+
// Stub implementation for release builds.
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
#endif // NDEBUG
|
|
94
|
+
|
|
95
|
+
}; // namespace worklets
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <worklets/Tools/JSLogger.h>
|
|
4
|
-
|
|
5
|
-
#include <jsi/jsi.h>
|
|
6
|
-
|
|
7
|
-
#include <memory>
|
|
8
|
-
#include <string>
|
|
9
|
-
|
|
10
|
-
using namespace facebook;
|
|
11
|
-
|
|
12
|
-
namespace worklets {
|
|
13
|
-
|
|
14
|
-
std::string getReanimatedCppVersion();
|
|
15
|
-
void injectReanimatedCppVersion(jsi::Runtime &);
|
|
16
|
-
bool matchVersion(const std::string &, const std::string &);
|
|
17
|
-
void checkJSVersion(jsi::Runtime &, const std::shared_ptr<JSLogger> &);
|
|
18
|
-
|
|
19
|
-
}; // namespace worklets
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <worklets/Tools/JSLogger.h>
|
|
4
|
+
|
|
5
|
+
#include <jsi/jsi.h>
|
|
6
|
+
|
|
7
|
+
#include <memory>
|
|
8
|
+
#include <string>
|
|
9
|
+
|
|
10
|
+
using namespace facebook;
|
|
11
|
+
|
|
12
|
+
namespace worklets {
|
|
13
|
+
|
|
14
|
+
std::string getReanimatedCppVersion();
|
|
15
|
+
void injectReanimatedCppVersion(jsi::Runtime &);
|
|
16
|
+
bool matchVersion(const std::string &, const std::string &);
|
|
17
|
+
void checkJSVersion(jsi::Runtime &, const std::shared_ptr<JSLogger> &);
|
|
18
|
+
|
|
19
|
+
}; // namespace worklets
|