1*af2ec015STomasz Sapeta #include "NativeReanimatedModuleSpec.h"
2*af2ec015STomasz Sapeta 
3*af2ec015STomasz Sapeta #include <utility>
4*af2ec015STomasz Sapeta 
5*af2ec015STomasz Sapeta #define SPEC_PREFIX(FN_NAME) __hostFunction_NativeReanimatedModuleSpec_##FN_NAME
6*af2ec015STomasz Sapeta 
7*af2ec015STomasz Sapeta namespace ABI49_0_0reanimated {
8*af2ec015STomasz Sapeta 
SPEC_PREFIX(installCoreFunctions)9*af2ec015STomasz Sapeta static jsi::Value SPEC_PREFIX(installCoreFunctions)(
10*af2ec015STomasz Sapeta     jsi::Runtime &rt,
11*af2ec015STomasz Sapeta     TurboModule &turboModule,
12*af2ec015STomasz Sapeta     const jsi::Value *args,
13*af2ec015STomasz Sapeta     size_t count) {
14*af2ec015STomasz Sapeta   static_cast<NativeReanimatedModuleSpec *>(&turboModule)
15*af2ec015STomasz Sapeta       ->installCoreFunctions(rt, std::move(args[0]), std::move(args[1]));
16*af2ec015STomasz Sapeta   return jsi::Value::undefined();
17*af2ec015STomasz Sapeta }
18*af2ec015STomasz Sapeta 
19*af2ec015STomasz Sapeta // SharedValue
20*af2ec015STomasz Sapeta 
SPEC_PREFIX(makeShareableClone)21*af2ec015STomasz Sapeta static jsi::Value SPEC_PREFIX(makeShareableClone)(
22*af2ec015STomasz Sapeta     jsi::Runtime &rt,
23*af2ec015STomasz Sapeta     TurboModule &turboModule,
24*af2ec015STomasz Sapeta     const jsi::Value *args,
25*af2ec015STomasz Sapeta     size_t count) {
26*af2ec015STomasz Sapeta   return static_cast<NativeReanimatedModuleSpec *>(&turboModule)
27*af2ec015STomasz Sapeta       ->makeShareableClone(rt, std::move(args[0]), std::move(args[1]));
28*af2ec015STomasz Sapeta }
29*af2ec015STomasz Sapeta 
30*af2ec015STomasz Sapeta // Sync methods
31*af2ec015STomasz Sapeta 
SPEC_PREFIX(makeSynchronizedDataHolder)32*af2ec015STomasz Sapeta static jsi::Value SPEC_PREFIX(makeSynchronizedDataHolder)(
33*af2ec015STomasz Sapeta     jsi::Runtime &rt,
34*af2ec015STomasz Sapeta     TurboModule &turboModule,
35*af2ec015STomasz Sapeta     const jsi::Value *args,
36*af2ec015STomasz Sapeta     size_t count) {
37*af2ec015STomasz Sapeta   return static_cast<NativeReanimatedModuleSpec *>(&turboModule)
38*af2ec015STomasz Sapeta       ->makeSynchronizedDataHolder(rt, std::move(args[0]));
39*af2ec015STomasz Sapeta }
40*af2ec015STomasz Sapeta 
SPEC_PREFIX(getDataSynchronously)41*af2ec015STomasz Sapeta static jsi::Value SPEC_PREFIX(getDataSynchronously)(
42*af2ec015STomasz Sapeta     jsi::Runtime &rt,
43*af2ec015STomasz Sapeta     TurboModule &turboModule,
44*af2ec015STomasz Sapeta     const jsi::Value *args,
45*af2ec015STomasz Sapeta     size_t count) {
46*af2ec015STomasz Sapeta   return static_cast<NativeReanimatedModuleSpec *>(&turboModule)
47*af2ec015STomasz Sapeta       ->getDataSynchronously(rt, std::move(args[0]));
48*af2ec015STomasz Sapeta }
49*af2ec015STomasz Sapeta 
50*af2ec015STomasz Sapeta // scheduler
51*af2ec015STomasz Sapeta 
SPEC_PREFIX(scheduleOnUI)52*af2ec015STomasz Sapeta static jsi::Value SPEC_PREFIX(scheduleOnUI)(
53*af2ec015STomasz Sapeta     jsi::Runtime &rt,
54*af2ec015STomasz Sapeta     TurboModule &turboModule,
55*af2ec015STomasz Sapeta     const jsi::Value *args,
56*af2ec015STomasz Sapeta     size_t count) {
57*af2ec015STomasz Sapeta   static_cast<NativeReanimatedModuleSpec *>(&turboModule)
58*af2ec015STomasz Sapeta       ->scheduleOnUI(rt, std::move(args[0]));
59*af2ec015STomasz Sapeta   return jsi::Value::undefined();
60*af2ec015STomasz Sapeta }
61*af2ec015STomasz Sapeta 
SPEC_PREFIX(registerEventHandler)62*af2ec015STomasz Sapeta static jsi::Value SPEC_PREFIX(registerEventHandler)(
63*af2ec015STomasz Sapeta     jsi::Runtime &rt,
64*af2ec015STomasz Sapeta     TurboModule &turboModule,
65*af2ec015STomasz Sapeta     const jsi::Value *args,
66*af2ec015STomasz Sapeta     size_t count) {
67*af2ec015STomasz Sapeta   return static_cast<NativeReanimatedModuleSpec *>(&turboModule)
68*af2ec015STomasz Sapeta       ->registerEventHandler(rt, std::move(args[0]), std::move(args[1]));
69*af2ec015STomasz Sapeta }
70*af2ec015STomasz Sapeta 
SPEC_PREFIX(unregisterEventHandler)71*af2ec015STomasz Sapeta static jsi::Value SPEC_PREFIX(unregisterEventHandler)(
72*af2ec015STomasz Sapeta     jsi::Runtime &rt,
73*af2ec015STomasz Sapeta     TurboModule &turboModule,
74*af2ec015STomasz Sapeta     const jsi::Value *args,
75*af2ec015STomasz Sapeta     size_t count) {
76*af2ec015STomasz Sapeta   static_cast<NativeReanimatedModuleSpec *>(&turboModule)
77*af2ec015STomasz Sapeta       ->unregisterEventHandler(rt, std::move(args[0]));
78*af2ec015STomasz Sapeta   return jsi::Value::undefined();
79*af2ec015STomasz Sapeta }
80*af2ec015STomasz Sapeta 
SPEC_PREFIX(getViewProp)81*af2ec015STomasz Sapeta static jsi::Value SPEC_PREFIX(getViewProp)(
82*af2ec015STomasz Sapeta     jsi::Runtime &rt,
83*af2ec015STomasz Sapeta     TurboModule &turboModule,
84*af2ec015STomasz Sapeta     const jsi::Value *args,
85*af2ec015STomasz Sapeta     size_t count) {
86*af2ec015STomasz Sapeta   static_cast<NativeReanimatedModuleSpec *>(&turboModule)
87*af2ec015STomasz Sapeta       ->getViewProp(
88*af2ec015STomasz Sapeta           rt, std::move(args[0]), std::move(args[1]), std::move(args[2]));
89*af2ec015STomasz Sapeta   return jsi::Value::undefined();
90*af2ec015STomasz Sapeta }
91*af2ec015STomasz Sapeta 
SPEC_PREFIX(enableLayoutAnimations)92*af2ec015STomasz Sapeta static jsi::Value SPEC_PREFIX(enableLayoutAnimations)(
93*af2ec015STomasz Sapeta     jsi::Runtime &rt,
94*af2ec015STomasz Sapeta     TurboModule &turboModule,
95*af2ec015STomasz Sapeta     const jsi::Value *args,
96*af2ec015STomasz Sapeta     size_t count) {
97*af2ec015STomasz Sapeta   static_cast<NativeReanimatedModuleSpec *>(&turboModule)
98*af2ec015STomasz Sapeta       ->enableLayoutAnimations(rt, std::move(args[0]));
99*af2ec015STomasz Sapeta   return jsi::Value::undefined();
100*af2ec015STomasz Sapeta }
101*af2ec015STomasz Sapeta 
SPEC_PREFIX(registerSensor)102*af2ec015STomasz Sapeta static jsi::Value SPEC_PREFIX(registerSensor)(
103*af2ec015STomasz Sapeta     jsi::Runtime &rt,
104*af2ec015STomasz Sapeta     TurboModule &turboModule,
105*af2ec015STomasz Sapeta     const jsi::Value *args,
106*af2ec015STomasz Sapeta     size_t count) {
107*af2ec015STomasz Sapeta   return static_cast<NativeReanimatedModuleSpec *>(&turboModule)
108*af2ec015STomasz Sapeta       ->registerSensor(
109*af2ec015STomasz Sapeta           rt,
110*af2ec015STomasz Sapeta           std::move(args[0]),
111*af2ec015STomasz Sapeta           std::move(args[1]),
112*af2ec015STomasz Sapeta           std::move(args[2]),
113*af2ec015STomasz Sapeta           std::move(args[3]));
114*af2ec015STomasz Sapeta }
115*af2ec015STomasz Sapeta 
SPEC_PREFIX(unregisterSensor)116*af2ec015STomasz Sapeta static jsi::Value SPEC_PREFIX(unregisterSensor)(
117*af2ec015STomasz Sapeta     jsi::Runtime &rt,
118*af2ec015STomasz Sapeta     TurboModule &turboModule,
119*af2ec015STomasz Sapeta     const jsi::Value *args,
120*af2ec015STomasz Sapeta     size_t count) {
121*af2ec015STomasz Sapeta   static_cast<NativeReanimatedModuleSpec *>(&turboModule)
122*af2ec015STomasz Sapeta       ->unregisterSensor(rt, std::move(args[0]));
123*af2ec015STomasz Sapeta   return jsi::Value::undefined();
124*af2ec015STomasz Sapeta }
125*af2ec015STomasz Sapeta 
SPEC_PREFIX(configureProps)126*af2ec015STomasz Sapeta static jsi::Value SPEC_PREFIX(configureProps)(
127*af2ec015STomasz Sapeta     jsi::Runtime &rt,
128*af2ec015STomasz Sapeta     TurboModule &turboModule,
129*af2ec015STomasz Sapeta     const jsi::Value *args,
130*af2ec015STomasz Sapeta     size_t count) {
131*af2ec015STomasz Sapeta   static_cast<NativeReanimatedModuleSpec *>(&turboModule)
132*af2ec015STomasz Sapeta       ->configureProps(rt, std::move(args[0]), std::move(args[1]));
133*af2ec015STomasz Sapeta   return jsi::Value::undefined();
134*af2ec015STomasz Sapeta }
135*af2ec015STomasz Sapeta 
SPEC_PREFIX(subscribeForKeyboardEvents)136*af2ec015STomasz Sapeta static jsi::Value SPEC_PREFIX(subscribeForKeyboardEvents)(
137*af2ec015STomasz Sapeta     jsi::Runtime &rt,
138*af2ec015STomasz Sapeta     TurboModule &turboModule,
139*af2ec015STomasz Sapeta     const jsi::Value *args,
140*af2ec015STomasz Sapeta     size_t count) {
141*af2ec015STomasz Sapeta   return static_cast<NativeReanimatedModuleSpec *>(&turboModule)
142*af2ec015STomasz Sapeta       ->subscribeForKeyboardEvents(rt, std::move(args[0]), std::move(args[1]));
143*af2ec015STomasz Sapeta }
144*af2ec015STomasz Sapeta 
SPEC_PREFIX(unsubscribeFromKeyboardEvents)145*af2ec015STomasz Sapeta static jsi::Value SPEC_PREFIX(unsubscribeFromKeyboardEvents)(
146*af2ec015STomasz Sapeta     jsi::Runtime &rt,
147*af2ec015STomasz Sapeta     TurboModule &turboModule,
148*af2ec015STomasz Sapeta     const jsi::Value *args,
149*af2ec015STomasz Sapeta     size_t count) {
150*af2ec015STomasz Sapeta   static_cast<NativeReanimatedModuleSpec *>(&turboModule)
151*af2ec015STomasz Sapeta       ->unsubscribeFromKeyboardEvents(rt, std::move(args[0]));
152*af2ec015STomasz Sapeta   return jsi::Value::undefined();
153*af2ec015STomasz Sapeta }
154*af2ec015STomasz Sapeta 
SPEC_PREFIX(configureLayoutAnimation)155*af2ec015STomasz Sapeta static jsi::Value SPEC_PREFIX(configureLayoutAnimation)(
156*af2ec015STomasz Sapeta     jsi::Runtime &rt,
157*af2ec015STomasz Sapeta     TurboModule &turboModule,
158*af2ec015STomasz Sapeta     const jsi::Value *args,
159*af2ec015STomasz Sapeta     size_t count) {
160*af2ec015STomasz Sapeta   return static_cast<NativeReanimatedModuleSpec *>(&turboModule)
161*af2ec015STomasz Sapeta       ->configureLayoutAnimation(
162*af2ec015STomasz Sapeta           rt,
163*af2ec015STomasz Sapeta           std::move(args[0]),
164*af2ec015STomasz Sapeta           std::move(args[1]),
165*af2ec015STomasz Sapeta           std::move(args[2]),
166*af2ec015STomasz Sapeta           std::move(args[3]));
167*af2ec015STomasz Sapeta }
168*af2ec015STomasz Sapeta 
NativeReanimatedModuleSpec(std::shared_ptr<CallInvoker> jsInvoker)169*af2ec015STomasz Sapeta NativeReanimatedModuleSpec::NativeReanimatedModuleSpec(
170*af2ec015STomasz Sapeta     std::shared_ptr<CallInvoker> jsInvoker)
171*af2ec015STomasz Sapeta     : TurboModule("NativeReanimated", jsInvoker) {
172*af2ec015STomasz Sapeta   methodMap_["installCoreFunctions"] =
173*af2ec015STomasz Sapeta       MethodMetadata{2, SPEC_PREFIX(installCoreFunctions)};
174*af2ec015STomasz Sapeta 
175*af2ec015STomasz Sapeta   methodMap_["makeShareableClone"] =
176*af2ec015STomasz Sapeta       MethodMetadata{2, SPEC_PREFIX(makeShareableClone)};
177*af2ec015STomasz Sapeta 
178*af2ec015STomasz Sapeta   methodMap_["makeSynchronizedDataHolder"] =
179*af2ec015STomasz Sapeta       MethodMetadata{1, SPEC_PREFIX(makeSynchronizedDataHolder)};
180*af2ec015STomasz Sapeta   methodMap_["getDataSynchronously"] =
181*af2ec015STomasz Sapeta       MethodMetadata{1, SPEC_PREFIX(getDataSynchronously)};
182*af2ec015STomasz Sapeta 
183*af2ec015STomasz Sapeta   methodMap_["scheduleOnUI"] = MethodMetadata{1, SPEC_PREFIX(scheduleOnUI)};
184*af2ec015STomasz Sapeta 
185*af2ec015STomasz Sapeta   methodMap_["registerEventHandler"] =
186*af2ec015STomasz Sapeta       MethodMetadata{2, SPEC_PREFIX(registerEventHandler)};
187*af2ec015STomasz Sapeta   methodMap_["unregisterEventHandler"] =
188*af2ec015STomasz Sapeta       MethodMetadata{1, SPEC_PREFIX(unregisterEventHandler)};
189*af2ec015STomasz Sapeta 
190*af2ec015STomasz Sapeta   methodMap_["getViewProp"] = MethodMetadata{3, SPEC_PREFIX(getViewProp)};
191*af2ec015STomasz Sapeta   methodMap_["enableLayoutAnimations"] =
192*af2ec015STomasz Sapeta       MethodMetadata{2, SPEC_PREFIX(enableLayoutAnimations)};
193*af2ec015STomasz Sapeta   methodMap_["registerSensor"] = MethodMetadata{4, SPEC_PREFIX(registerSensor)};
194*af2ec015STomasz Sapeta   methodMap_["unregisterSensor"] =
195*af2ec015STomasz Sapeta       MethodMetadata{1, SPEC_PREFIX(unregisterSensor)};
196*af2ec015STomasz Sapeta   methodMap_["configureProps"] = MethodMetadata{2, SPEC_PREFIX(configureProps)};
197*af2ec015STomasz Sapeta   methodMap_["subscribeForKeyboardEvents"] =
198*af2ec015STomasz Sapeta       MethodMetadata{2, SPEC_PREFIX(subscribeForKeyboardEvents)};
199*af2ec015STomasz Sapeta   methodMap_["unsubscribeFromKeyboardEvents"] =
200*af2ec015STomasz Sapeta       MethodMetadata{1, SPEC_PREFIX(unsubscribeFromKeyboardEvents)};
201*af2ec015STomasz Sapeta 
202*af2ec015STomasz Sapeta   methodMap_["configureLayoutAnimation"] =
203*af2ec015STomasz Sapeta       MethodMetadata{4, SPEC_PREFIX(configureLayoutAnimation)};
204*af2ec015STomasz Sapeta }
205*af2ec015STomasz Sapeta } // namespace reanimated
206