• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_image_animator_bridge.h"
16 
17 #include "base/geometry/dimension.h"
18 #include "base/geometry/ng/offset_t.h"
19 #include "base/memory/referenced.h"
20 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
21 #include "bridge/declarative_frontend/jsview/js_image_animator.h"
22 #include "core/components/declaration/image/image_animator_declaration.h"
23 
24 namespace OHOS::Ace::NG {
25 constexpr int32_t DEFAULT_DURATION = 1000; // ms
26 
27 constexpr int NUM_0 = 0;
28 constexpr int NUM_1 = 1;
29 constexpr int NUM_2 = 2;
30 constexpr int NUM_3 = 3;
31 constexpr int NUM_4 = 4;
32 constexpr int NUM_5 = 5;
33 constexpr int NUM_6 = 6;
34 constexpr int NUM_7 = 7;
35 constexpr int32_t IMAGESIZE = 4;
36 constexpr FillMode DEFAULT_FILL_MODE = FillMode::FORWARDS;
SetState(ArkUIRuntimeCallInfo * runtimeCallInfo)37 ArkUINativeModuleValue ImageAnimatorBridge::SetState(ArkUIRuntimeCallInfo* runtimeCallInfo)
38 {
39     EcmaVM* vm = runtimeCallInfo->GetVM();
40     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
41     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
42     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
43     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
44     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
45     int32_t state = static_cast<int32_t>(Animator::Status::IDLE);
46     auto nodeModifiers = GetArkUINodeModifiers();
47     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
48     if (secondArg->IsNumber()) {
49         state = secondArg->Int32Value(vm);
50         if (state < static_cast<int32_t>(Animator::Status::IDLE) ||
51             state > static_cast<int32_t>(Animator::Status::STOPPED)) {
52             state = static_cast<int32_t>(Animator::Status::IDLE);
53         }
54         nodeModifiers->getImageAnimatorModifier()->setState(nativeNode, state);
55     } else {
56         nodeModifiers->getImageAnimatorModifier()->resetState(nativeNode);
57     }
58 
59     return panda::JSValueRef::Undefined(vm);
60 }
61 
ResetState(ArkUIRuntimeCallInfo * runtimeCallInfo)62 ArkUINativeModuleValue ImageAnimatorBridge::ResetState(ArkUIRuntimeCallInfo* runtimeCallInfo)
63 {
64     EcmaVM* vm = runtimeCallInfo->GetVM();
65     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
66     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
67     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
68     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
69     auto nodeModifiers = GetArkUINodeModifiers();
70     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
71     nodeModifiers->getImageAnimatorModifier()->resetState(nativeNode);
72     return panda::JSValueRef::Undefined(vm);
73 }
74 
SetDuration(ArkUIRuntimeCallInfo * runtimeCallInfo)75 ArkUINativeModuleValue ImageAnimatorBridge::SetDuration(ArkUIRuntimeCallInfo* runtimeCallInfo)
76 {
77     EcmaVM* vm = runtimeCallInfo->GetVM();
78     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
79     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
80     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
81     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
82     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
83     int32_t duration = DEFAULT_DURATION;
84     if (secondArg->IsNumber()) {
85         duration = secondArg->Int32Value(vm);
86         if (duration < 0) {
87             duration = DEFAULT_DURATION;
88         }
89     }
90     auto nodeModifiers = GetArkUINodeModifiers();
91     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
92     nodeModifiers->getImageAnimatorModifier()->setDuration(nativeNode, duration);
93     return panda::JSValueRef::Undefined(vm);
94 }
95 
ResetDuration(ArkUIRuntimeCallInfo * runtimeCallInfo)96 ArkUINativeModuleValue ImageAnimatorBridge::ResetDuration(ArkUIRuntimeCallInfo* runtimeCallInfo)
97 {
98     EcmaVM* vm = runtimeCallInfo->GetVM();
99     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
100     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
101     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
102     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
103     int32_t duration = DEFAULT_DURATION;
104     auto nodeModifiers = GetArkUINodeModifiers();
105     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
106     nodeModifiers->getImageAnimatorModifier()->setDuration(nativeNode, duration);
107     return panda::JSValueRef::Undefined(vm);
108 }
109 
SetFixedSize(ArkUIRuntimeCallInfo * runtimeCallInfo)110 ArkUINativeModuleValue ImageAnimatorBridge::SetFixedSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
111 {
112     EcmaVM* vm = runtimeCallInfo->GetVM();
113     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
114     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
115     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
116     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
117     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
118 
119     uint32_t fixedSize = 1;
120     auto nodeModifiers = GetArkUINodeModifiers();
121     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
122     if (secondArg->IsBoolean()) {
123         fixedSize = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
124         nodeModifiers->getImageAnimatorModifier()->setFixedSize(nativeNode, fixedSize);
125     } else {
126         nodeModifiers->getImageAnimatorModifier()->resetFixedSize(nativeNode);
127     }
128 
129     return panda::JSValueRef::Undefined(vm);
130 }
131 
ResetFixedSize(ArkUIRuntimeCallInfo * runtimeCallInfo)132 ArkUINativeModuleValue ImageAnimatorBridge::ResetFixedSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
133 {
134     EcmaVM* vm = runtimeCallInfo->GetVM();
135     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
136     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
137     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
138     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
139     auto nodeModifiers = GetArkUINodeModifiers();
140     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
141     nodeModifiers->getImageAnimatorModifier()->resetFixedSize(nativeNode);
142     return panda::JSValueRef::Undefined(vm);
143 }
144 
SetFillMode(ArkUIRuntimeCallInfo * runtimeCallInfo)145 ArkUINativeModuleValue ImageAnimatorBridge::SetFillMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
146 {
147     EcmaVM* vm = runtimeCallInfo->GetVM();
148     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
149     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
150     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
151     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
152     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
153 
154     auto nodeModifiers = GetArkUINodeModifiers();
155     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
156     if (secondArg->IsNumber()) {
157         int32_t fillMode = secondArg->Int32Value(vm);
158         if (fillMode < static_cast<int32_t>(FillMode::NONE) || fillMode > static_cast<int32_t>(FillMode::BOTH)) {
159             fillMode = static_cast<int32_t>(DEFAULT_FILL_MODE);
160         }
161         nodeModifiers->getImageAnimatorModifier()->setFillMode(nativeNode, fillMode);
162     } else {
163         nodeModifiers->getImageAnimatorModifier()->resetFillMode(nativeNode);
164     }
165     return panda::JSValueRef::Undefined(vm);
166 }
167 
ResetFillMode(ArkUIRuntimeCallInfo * runtimeCallInfo)168 ArkUINativeModuleValue ImageAnimatorBridge::ResetFillMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
169 {
170     EcmaVM* vm = runtimeCallInfo->GetVM();
171     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
172     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
173     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
174     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
175     auto nodeModifiers = GetArkUINodeModifiers();
176     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
177     nodeModifiers->getImageAnimatorModifier()->resetFillMode(nativeNode);
178     return panda::JSValueRef::Undefined(vm);
179 }
180 
SetReverse(ArkUIRuntimeCallInfo * runtimeCallInfo)181 ArkUINativeModuleValue ImageAnimatorBridge::SetReverse(ArkUIRuntimeCallInfo* runtimeCallInfo)
182 {
183     EcmaVM* vm = runtimeCallInfo->GetVM();
184     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
185     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
186     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
187     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
188     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
189 
190     auto nodeModifiers = GetArkUINodeModifiers();
191     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
192     if (secondArg->IsBoolean()) {
193         uint32_t value = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
194         nodeModifiers->getImageAnimatorModifier()->setReverse(nativeNode, value);
195     } else {
196         nodeModifiers->getImageAnimatorModifier()->resetReverse(nativeNode);
197     }
198 
199     return panda::JSValueRef::Undefined(vm);
200 }
201 
ResetReverse(ArkUIRuntimeCallInfo * runtimeCallInfo)202 ArkUINativeModuleValue ImageAnimatorBridge::ResetReverse(ArkUIRuntimeCallInfo* runtimeCallInfo)
203 {
204     EcmaVM* vm = runtimeCallInfo->GetVM();
205     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
206     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
207     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
208     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
209     auto nodeModifiers = GetArkUINodeModifiers();
210     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
211     nodeModifiers->getImageAnimatorModifier()->resetReverse(nativeNode);
212     return panda::JSValueRef::Undefined(vm);
213 }
214 
SetImages(ArkUIRuntimeCallInfo * runtimeCallInfo)215 ArkUINativeModuleValue ImageAnimatorBridge::SetImages(ArkUIRuntimeCallInfo* runtimeCallInfo)
216 {
217     EcmaVM* vm = runtimeCallInfo->GetVM();
218     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
219     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
220     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
221     Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
222     Local<JSValueRef> fourthArg = runtimeCallInfo->GetCallArgRef(NUM_3);
223     Local<JSValueRef> fifthArg = runtimeCallInfo->GetCallArgRef(NUM_4);
224     Local<JSValueRef> sixthArg = runtimeCallInfo->GetCallArgRef(NUM_5);
225     Local<JSValueRef> seventhArg = runtimeCallInfo->GetCallArgRef(NUM_6);
226     Local<JSValueRef> eighthArg = runtimeCallInfo->GetCallArgRef(NUM_7);
227     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
228     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
229 
230     if (!eighthArg->IsNumber() || eighthArg->Int32Value(vm) <= 0) {
231         return panda::JSValueRef::Undefined(vm);
232     }
233     int32_t arrayLength = eighthArg->Int32Value(vm);
234 
235     if (secondArg->IsNull() || !secondArg->IsArray(vm) || thirdArg->IsNull() || !thirdArg->IsArray(vm) ||
236         fourthArg->IsNull() || !fourthArg->IsArray(vm) || fifthArg->IsNull() || !fifthArg->IsArray(vm) ||
237         sixthArg->IsNull() || !sixthArg->IsArray(vm) || seventhArg->IsNull() || !seventhArg->IsArray(vm)) {
238         return panda::JSValueRef::Undefined(vm);
239     }
240     auto parseDimensionStruct = [](const EcmaVM* vm, const Local<JSValueRef>& arg) {
241         CalcDimension val(0.0, DimensionUnit::VP);
242         ArkTSUtils::ParseJsDimensionVp(vm, arg, val);
243         return val;
244     };
245     auto parseInt32 = [](const EcmaVM* vm, const Local<JSValueRef>& arg) {
246         if (arg->IsNumber()) {
247             return arg->Int32Value(vm);
248         }
249         return 0;
250     };
251     auto srcArray = std::make_unique<std::string[]>(arrayLength);
252     auto calcDimension = std::make_unique<CalcDimension[]>(arrayLength * 4);
253     auto durationArray = std::make_unique<int32_t[]>(arrayLength);
254     if (!ArkTSUtils::ParseStringArray(vm, secondArg, srcArray.get(), arrayLength) ||
255         !ArkTSUtils::ParseArray<CalcDimension>(
256             vm, thirdArg, calcDimension.get() + arrayLength * NUM_0, arrayLength, parseDimensionStruct) ||
257         !ArkTSUtils::ParseArray<CalcDimension>(
258             vm, fourthArg, calcDimension.get() + arrayLength * NUM_1, arrayLength, parseDimensionStruct) ||
259         !ArkTSUtils::ParseArray<CalcDimension>(
260             vm, fifthArg, calcDimension.get() + arrayLength * NUM_2, arrayLength, parseDimensionStruct) ||
261         !ArkTSUtils::ParseArray<CalcDimension>(
262             vm, sixthArg, calcDimension.get() + arrayLength * NUM_3, arrayLength, parseDimensionStruct) ||
263         !ArkTSUtils::ParseArray<int32_t>(vm, seventhArg, durationArray.get(), arrayLength, parseInt32)) {
264         return panda::JSValueRef::Undefined(vm);
265     }
266     auto images = std::make_unique<ArkUIImagePropertiesStruct[]>(arrayLength);
267     for (int32_t i = 0; i < arrayLength; i++) {
268         images[i].src = srcArray[i].c_str();
269         for (int32_t j = 0; j < IMAGESIZE; j++) {
270             images[i].number[j] = calcDimension[arrayLength * j + i].Value();
271             images[i].unit[j] = static_cast<int8_t>(calcDimension[arrayLength * j + i].Unit());
272             images[i].calc[j] = const_cast<char*>(calcDimension[arrayLength * j + i].CalcValue().c_str());
273         }
274         images[i].duration = *(durationArray.get() + i);
275     }
276     auto nodeModifiers = GetArkUINodeModifiers();
277     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
278     nodeModifiers->getImageAnimatorModifier()->setImages(nativeNode, images.get(), arrayLength);
279     return panda::JSValueRef::Undefined(vm);
280 }
281 
ResetImages(ArkUIRuntimeCallInfo * runtimeCallInfo)282 ArkUINativeModuleValue ImageAnimatorBridge::ResetImages(ArkUIRuntimeCallInfo* runtimeCallInfo)
283 {
284     EcmaVM* vm = runtimeCallInfo->GetVM();
285     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
286     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
287     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
288     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
289     auto nodeModifiers = GetArkUINodeModifiers();
290     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
291     nodeModifiers->getImageAnimatorModifier()->resetImages(nativeNode);
292     return panda::JSValueRef::Undefined(vm);
293 }
294 
SetIteration(ArkUIRuntimeCallInfo * runtimeCallInfo)295 ArkUINativeModuleValue ImageAnimatorBridge::SetIteration(ArkUIRuntimeCallInfo* runtimeCallInfo)
296 {
297     EcmaVM* vm = runtimeCallInfo->GetVM();
298     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
299     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
300     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
301     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
302     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
303     int32_t value ;
304     if (secondArg->IsNumber()) {
305         value = secondArg->Int32Value(vm);
306     } else {
307         return panda::JSValueRef::Undefined(vm);
308     }
309 
310     auto nodeModifiers = GetArkUINodeModifiers();
311     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
312     nodeModifiers->getImageAnimatorModifier()->setImageAnimatorIteration(nativeNode, value);
313     return panda::JSValueRef::Undefined(vm);
314 }
315 
ResetIteration(ArkUIRuntimeCallInfo * runtimeCallInfo)316 ArkUINativeModuleValue ImageAnimatorBridge::ResetIteration(ArkUIRuntimeCallInfo* runtimeCallInfo)
317 {
318     EcmaVM* vm = runtimeCallInfo->GetVM();
319     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
320     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
321     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
322     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
323     auto nodeModifiers = GetArkUINodeModifiers();
324     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
325     nodeModifiers->getImageAnimatorModifier()->resetImageAnimatorIteration(nativeNode);
326     return panda::JSValueRef::Undefined(vm);
327 }
328 
SetAutoMonitorInvisibleArea(ArkUIRuntimeCallInfo * runtimeCallInfo)329 ArkUINativeModuleValue ImageAnimatorBridge::SetAutoMonitorInvisibleArea(ArkUIRuntimeCallInfo* runtimeCallInfo)
330 {
331     EcmaVM* vm = runtimeCallInfo->GetVM();
332     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
333     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
334     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
335     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
336     bool value = false;
337     if (secondArg->IsBoolean()) {
338         value = secondArg->ToBoolean(vm)->BooleaValue(vm);
339     }
340 
341     GetArkUINodeModifiers()->getImageAnimatorModifier()->setAutoMonitorInvisibleArea(nativeNode, value);
342     return panda::JSValueRef::Undefined(vm);
343 }
344 
SetImageAnimatorOnStart(ArkUIRuntimeCallInfo * runtimeCallInfo)345 ArkUINativeModuleValue ImageAnimatorBridge::SetImageAnimatorOnStart(ArkUIRuntimeCallInfo* runtimeCallInfo)
346 {
347     EcmaVM* vm = runtimeCallInfo->GetVM();
348     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
349     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
350     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(1);
351     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
352     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
353         GetArkUINodeModifiers()->getImageAnimatorModifier()->resetImageAnimatorOnStart(nativeNode);
354         return panda::JSValueRef::Undefined(vm);
355     }
356     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
357     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
358     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
359     std::function<void()> callback = [vm, frameNode, func = panda::CopyableGlobal(vm, func)]() {
360         panda::LocalScope pandaScope(vm);
361         panda::TryCatch trycatch(vm);
362         func->Call(vm, func.ToLocal(), nullptr, 0);
363     };
364     GetArkUINodeModifiers()->getImageAnimatorModifier()->setImageAnimatorOnStart(
365         nativeNode, reinterpret_cast<void*>(&callback));
366     return panda::JSValueRef::Undefined(vm);
367 }
368 
ResetImageAnimatorOnStart(ArkUIRuntimeCallInfo * runtimeCallInfo)369 ArkUINativeModuleValue ImageAnimatorBridge::ResetImageAnimatorOnStart(ArkUIRuntimeCallInfo* runtimeCallInfo)
370 {
371     EcmaVM* vm = runtimeCallInfo->GetVM();
372     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
373     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
374     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
375     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
376     GetArkUINodeModifiers()->getImageAnimatorModifier()->resetImageAnimatorOnStart(nativeNode);
377     return panda::JSValueRef::Undefined(vm);
378 }
SetImageAnimatorOnPause(ArkUIRuntimeCallInfo * runtimeCallInfo)379 ArkUINativeModuleValue ImageAnimatorBridge::SetImageAnimatorOnPause(ArkUIRuntimeCallInfo* runtimeCallInfo)
380 {
381     EcmaVM* vm = runtimeCallInfo->GetVM();
382     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
383     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
384     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(1);
385     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
386     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
387         GetArkUINodeModifiers()->getImageAnimatorModifier()->resetImageAnimatorOnPause(nativeNode);
388         return panda::JSValueRef::Undefined(vm);
389     }
390     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
391     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
392     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
393     std::function<void()> callback = [vm, frameNode, func = panda::CopyableGlobal(vm, func)]() {
394         panda::LocalScope pandaScope(vm);
395         panda::TryCatch trycatch(vm);
396         func->Call(vm, func.ToLocal(), nullptr, 0);
397     };
398     GetArkUINodeModifiers()->getImageAnimatorModifier()->setImageAnimatorOnPause(
399         nativeNode, reinterpret_cast<void*>(&callback));
400     return panda::JSValueRef::Undefined(vm);
401 }
402 
ResetImageAnimatorOnPause(ArkUIRuntimeCallInfo * runtimeCallInfo)403 ArkUINativeModuleValue ImageAnimatorBridge::ResetImageAnimatorOnPause(ArkUIRuntimeCallInfo* runtimeCallInfo)
404 {
405     EcmaVM* vm = runtimeCallInfo->GetVM();
406     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
407     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
408     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
409     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
410     GetArkUINodeModifiers()->getImageAnimatorModifier()->resetImageAnimatorOnPause(nativeNode);
411     return panda::JSValueRef::Undefined(vm);
412 }
413 
SetImageAnimatorOnRepeat(ArkUIRuntimeCallInfo * runtimeCallInfo)414 ArkUINativeModuleValue ImageAnimatorBridge::SetImageAnimatorOnRepeat(ArkUIRuntimeCallInfo* runtimeCallInfo)
415 {
416     EcmaVM* vm = runtimeCallInfo->GetVM();
417     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
418     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
419     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(1);
420     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
421     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
422         GetArkUINodeModifiers()->getImageAnimatorModifier()->resetImageAnimatorOnRepeat(nativeNode);
423         return panda::JSValueRef::Undefined(vm);
424     }
425     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
426     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
427     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
428     std::function<void()> callback = [vm, frameNode, func = panda::CopyableGlobal(vm, func)]() {
429         panda::LocalScope pandaScope(vm);
430         panda::TryCatch trycatch(vm);
431         func->Call(vm, func.ToLocal(), nullptr, 0);
432     };
433     GetArkUINodeModifiers()->getImageAnimatorModifier()->setImageAnimatorOnRepeat(
434         nativeNode, reinterpret_cast<void*>(&callback));
435     return panda::JSValueRef::Undefined(vm);
436 }
437 
ResetImageAnimatorOnRepeat(ArkUIRuntimeCallInfo * runtimeCallInfo)438 ArkUINativeModuleValue ImageAnimatorBridge::ResetImageAnimatorOnRepeat(ArkUIRuntimeCallInfo* runtimeCallInfo)
439 {
440     EcmaVM* vm = runtimeCallInfo->GetVM();
441     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
442     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
443     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
444     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
445     GetArkUINodeModifiers()->getImageAnimatorModifier()->resetImageAnimatorOnRepeat(nativeNode);
446     return panda::JSValueRef::Undefined(vm);
447 }
448 
SetImageAnimatorOnCancel(ArkUIRuntimeCallInfo * runtimeCallInfo)449 ArkUINativeModuleValue ImageAnimatorBridge::SetImageAnimatorOnCancel(ArkUIRuntimeCallInfo* runtimeCallInfo)
450 {
451     EcmaVM* vm = runtimeCallInfo->GetVM();
452     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
453     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
454     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(1);
455     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
456     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
457         GetArkUINodeModifiers()->getImageAnimatorModifier()->resetImageAnimatorOnCancel(nativeNode);
458         return panda::JSValueRef::Undefined(vm);
459     }
460     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
461     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
462     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
463     std::function<void()> callback = [vm, frameNode, func = panda::CopyableGlobal(vm, func)]() {
464         panda::LocalScope pandaScope(vm);
465         panda::TryCatch trycatch(vm);
466         func->Call(vm, func.ToLocal(), nullptr, 0);
467     };
468     GetArkUINodeModifiers()->getImageAnimatorModifier()->setImageAnimatorOnCancel(
469         nativeNode, reinterpret_cast<void*>(&callback));
470     return panda::JSValueRef::Undefined(vm);
471 }
472 
ResetImageAnimatorOnCancel(ArkUIRuntimeCallInfo * runtimeCallInfo)473 ArkUINativeModuleValue ImageAnimatorBridge::ResetImageAnimatorOnCancel(ArkUIRuntimeCallInfo* runtimeCallInfo)
474 {
475     EcmaVM* vm = runtimeCallInfo->GetVM();
476     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
477     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
478     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
479     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
480     GetArkUINodeModifiers()->getImageAnimatorModifier()->resetImageAnimatorOnCancel(nativeNode);
481     return panda::JSValueRef::Undefined(vm);
482 }
483 
SetImageAnimatorOnFinish(ArkUIRuntimeCallInfo * runtimeCallInfo)484 ArkUINativeModuleValue ImageAnimatorBridge::SetImageAnimatorOnFinish(ArkUIRuntimeCallInfo* runtimeCallInfo)
485 {
486     EcmaVM* vm = runtimeCallInfo->GetVM();
487     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
488     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
489     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(1);
490     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
491     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
492         GetArkUINodeModifiers()->getImageAnimatorModifier()->resetImageAnimatorOnFinish(nativeNode);
493         return panda::JSValueRef::Undefined(vm);
494     }
495     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
496     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
497     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
498     std::function<void()> callback = [vm, frameNode, func = panda::CopyableGlobal(vm, func)]() {
499         panda::LocalScope pandaScope(vm);
500         panda::TryCatch trycatch(vm);
501         func->Call(vm, func.ToLocal(), nullptr, 0);
502     };
503     GetArkUINodeModifiers()->getImageAnimatorModifier()->setImageAnimatorOnFinish(
504         nativeNode, reinterpret_cast<void*>(&callback));
505     return panda::JSValueRef::Undefined(vm);
506 }
507 
ResetImageAnimatorOnFinish(ArkUIRuntimeCallInfo * runtimeCallInfo)508 ArkUINativeModuleValue ImageAnimatorBridge::ResetImageAnimatorOnFinish(ArkUIRuntimeCallInfo* runtimeCallInfo)
509 {
510     EcmaVM* vm = runtimeCallInfo->GetVM();
511     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
512     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
513     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
514     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
515     GetArkUINodeModifiers()->getImageAnimatorModifier()->resetImageAnimatorOnFinish(nativeNode);
516     return panda::JSValueRef::Undefined(vm);
517 }
518 } // namespace OHOS::Ace::NG
519