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_gauge_bridge.h"
16
17 #include "base/geometry/dimension.h"
18 #include "core/interfaces/native/node/api.h"
19 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
20 #include "bridge/declarative_frontend/jsview/js_linear_gradient.h"
21 #include "core/components/common/properties/color.h"
22 #include "core/components_ng/pattern/gauge/gauge_paint_property.h"
23 #include "core/components_ng/pattern/gauge/gauge_theme.h"
24
25 namespace OHOS::Ace::NG {
26 namespace {
27 constexpr Color ERROR_COLOR = Color(0xFFE84026);
28 constexpr int NUM_0 = 0;
29 constexpr int NUM_1 = 1;
ResetColor(void * nativeNode)30 void ResetColor(void* nativeNode)
31 {
32 if (!Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
33 GetArkUIInternalNodeAPI()->GetGaugeModifier().ResetGradientColors(nativeNode);
34 } else {
35 GetArkUIInternalNodeAPI()->GetGaugeModifier().ResetColors(nativeNode);
36 }
37 }
38 }
39
SortColorStopOffset(std::vector<NG::ColorStopArray> & colors)40 void SortColorStopOffset(std::vector<NG::ColorStopArray>& colors)
41 {
42 for (auto& colorStopArray : colors) {
43 std::sort(colorStopArray.begin(), colorStopArray.end(),
44 [](const std::pair<Color, Dimension>& left, const std::pair<Color, Dimension>& right) {
45 return left.second.Value() < right.second.Value();
46 });
47
48 auto iter = std::unique(colorStopArray.begin(), colorStopArray.end(),
49 [](const std::pair<Color, Dimension>& left, const std::pair<Color, Dimension>& right) {
50 return left.second.Value() == right.second.Value();
51 });
52 colorStopArray.erase(iter, colorStopArray.end());
53 }
54 }
55
ConvertResourceColor(const EcmaVM * vm,const Local<JSValueRef> & item,std::vector<NG::ColorStopArray> & colors)56 void ConvertResourceColor(const EcmaVM* vm, const Local<JSValueRef>& item, std::vector<NG::ColorStopArray>& colors)
57 {
58 Color color;
59 if (!ArkTSUtils::ParseJsColorAlpha(vm, item, color)) {
60 color = ERROR_COLOR;
61 }
62 NG::ColorStopArray colorStopArray;
63 colorStopArray.emplace_back(std::make_pair(color, Dimension(0.0)));
64 colors.emplace_back(colorStopArray);
65 }
66
ConvertGradientColor(const EcmaVM * vm,const Local<JSValueRef> & itemParam,std::vector<NG::ColorStopArray> & colors,NG::GaugeType & type)67 void ConvertGradientColor(
68 const EcmaVM* vm, const Local<JSValueRef>& itemParam, std::vector<NG::ColorStopArray>& colors, NG::GaugeType& type)
69 {
70 if (!itemParam->IsObject()) {
71 type = NG::GaugeType::TYPE_CIRCULAR_MONOCHROME;
72 return ConvertResourceColor(vm, itemParam, colors);
73 }
74 Framework::JSLinearGradient* jsLinearGradient =
75 static_cast<Framework::JSLinearGradient*>(itemParam->ToObject(vm)->GetNativePointerField(0));
76 if (!jsLinearGradient) {
77 type = NG::GaugeType::TYPE_CIRCULAR_MONOCHROME;
78 return ConvertResourceColor(vm, itemParam, colors);
79 }
80
81 type = NG::GaugeType::TYPE_CIRCULAR_SINGLE_SEGMENT_GRADIENT;
82 if (jsLinearGradient->GetGradient().size() == 0) {
83 NG::ColorStopArray colorStopArray;
84 colorStopArray.emplace_back(std::make_pair(ERROR_COLOR, Dimension(0.0)));
85 colors.emplace_back(colorStopArray);
86 } else {
87 colors.emplace_back(jsLinearGradient->GetGradient());
88 }
89 }
90
SetGradientColorsObject(const EcmaVM * vm,const Local<JSValueRef> & info,std::vector<NG::ColorStopArray> & colors,std::vector<float> & weights,NG::GaugeType & type,void * nativeNode)91 void SetGradientColorsObject(const EcmaVM* vm, const Local<JSValueRef>& info, std::vector<NG::ColorStopArray>& colors,
92 std::vector<float>& weights, NG::GaugeType& type, void* nativeNode)
93 {
94 ArkUIGradientType gradient;
95 ConvertGradientColor(vm, info, colors, type);
96 auto colorStruct = std::make_unique<uint32_t[]>(colors[0].size());
97 auto offsetStruct = std::make_unique<ArkUILengthType[]>(colors[0].size());
98 std::vector<uint32_t> linearLengths { colors[0].size() };
99 for (uint32_t i = 0; i < colors[0].size(); i++) {
100 colorStruct[i] = colors[0][i].first.GetValue();
101 offsetStruct[i].number = colors[0][i].second.Value();
102 offsetStruct[i].unit = static_cast<int8_t>(colors[0][i].second.Unit());
103 }
104 gradient.color = colorStruct.get();
105 gradient.offset = offsetStruct.get();
106 gradient.gradientLength = &(*linearLengths.begin());
107 gradient.weight = nullptr;
108 gradient.type = static_cast<uint32_t>(type);
109 gradient.length = 1;
110 GetArkUIInternalNodeAPI()->GetGaugeModifier().SetGradientColors(nativeNode, &gradient, 0);
111 }
112
SetGradientColorsArray(const EcmaVM * vm,const Local<JSValueRef> & info,std::vector<NG::ColorStopArray> & colors,std::vector<float> & weights,NG::GaugeType & type,void * nativeNode)113 void SetGradientColorsArray(const EcmaVM* vm, const Local<JSValueRef>& info, std::vector<NG::ColorStopArray>& colors,
114 std::vector<float>& weights, NG::GaugeType& type, void* nativeNode)
115 {
116 ArkUIGradientType gradient;
117 uint32_t totalLength = 0;
118 std::vector<uint32_t> linearLengths(colors.size(), 0);
119 for (uint32_t i = 0; i < colors.size(); i++) {
120 linearLengths[i] = colors[i].size();
121 totalLength += colors[i].size();
122 }
123 auto colorStruct = std::make_unique<uint32_t[]>(totalLength);
124 auto offsetStruct = std::make_unique<ArkUILengthType[]>(totalLength);
125 int32_t pos = 0;
126 for (uint32_t i = 0; i < colors.size(); i++) {
127 for (uint32_t j = 0; j < colors[i].size(); j++, pos++) {
128 colorStruct[pos] = colors[i][j].first.GetValue();
129 offsetStruct[pos].number = colors[i][j].second.Value();
130 offsetStruct[pos].unit = static_cast<int8_t>(colors[i][j].second.Unit());
131 }
132 }
133 gradient.color = colorStruct.get();
134 gradient.offset = offsetStruct.get();
135 gradient.gradientLength = &(*linearLengths.begin());
136 gradient.weight = &(*weights.begin());
137 gradient.type = static_cast<uint32_t>(type);
138 gradient.length = colors.size();
139 GetArkUIInternalNodeAPI()->GetGaugeModifier().SetGradientColors(nativeNode, &gradient, weights.size());
140 }
141
SetGradientColors(const EcmaVM * vm,const Local<JSValueRef> & info,void * nativeNode)142 void SetGradientColors(const EcmaVM* vm, const Local<JSValueRef>& info, void* nativeNode)
143 {
144 if (info->IsNull() || info->IsUndefined()) {
145 GetArkUIInternalNodeAPI()->GetGaugeModifier().ResetGradientColors(nativeNode);
146 return;
147 }
148 NG::GaugeType type = NG::GaugeType::TYPE_CIRCULAR_MULTI_SEGMENT_GRADIENT;
149 std::vector<NG::ColorStopArray> colors;
150 std::vector<float> weights;
151 if (!info->IsArray(vm)) {
152 SetGradientColorsObject(vm, info, colors, weights, type, nativeNode);
153 return;
154 }
155 auto jsColorsArray = panda::CopyableGlobal<panda::ArrayRef>(vm, info);
156 if (jsColorsArray->Length(vm) == 0) {
157 GetArkUIInternalNodeAPI()->GetGaugeModifier().ResetGradientColors(nativeNode);
158 return;
159 }
160
161 for (size_t i = 0; i < jsColorsArray->Length(vm); ++i) {
162 if (static_cast<int32_t>(i) >= NG::COLORS_MAX_COUNT) {
163 break;
164 }
165 auto jsValue = jsColorsArray->GetValueAt(vm, info, i);
166 if (!jsValue->IsArray(vm)) {
167 continue;
168 }
169 auto tempColors = panda::CopyableGlobal<panda::ArrayRef>(vm, jsValue);
170 // Get weight
171 float weight = tempColors->GetValueAt(vm, jsValue, 1)->ToNumber(vm)->Value();
172 if (NonPositive(weight)) {
173 continue;
174 }
175 weights.push_back(weight);
176 // Get color
177 auto jsColorValue = tempColors->GetValueAt(vm, jsValue, 0);
178 ConvertGradientColor(vm, jsColorValue, colors, type);
179 }
180 type = NG::GaugeType::TYPE_CIRCULAR_MULTI_SEGMENT_GRADIENT;
181 SortColorStopOffset(colors);
182 SetGradientColorsArray(vm, info, colors, weights, type, nativeNode);
183 }
184
SetColors(ArkUIRuntimeCallInfo * runtimeCallInfo)185 ArkUINativeModuleValue GaugeBridge::SetColors(ArkUIRuntimeCallInfo* runtimeCallInfo)
186 {
187 EcmaVM* vm = runtimeCallInfo->GetVM();
188 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
189 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
190 Local<JSValueRef> jsArg = runtimeCallInfo->GetCallArgRef(NUM_1);
191 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
192
193 if (!Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
194 SetGradientColors(vm, jsArg, nativeNode);
195 return panda::JSValueRef::Undefined(vm);
196 }
197
198 if (!jsArg->IsArray(vm)) {
199 ResetColor(nativeNode);
200 return panda::JSValueRef::Undefined(vm);
201 }
202 auto jsColor = panda::CopyableGlobal<panda::ArrayRef>(vm, jsArg);
203 size_t length = jsColor->Length(vm);
204 auto colors = std::make_unique<uint32_t[]>(length);
205 auto weights = std::make_unique<float[]>(length);
206
207 auto theme = ArkTSUtils::GetTheme<ProgressTheme>();
208 for (size_t i = 0; i < length; i++) {
209 auto jsValue = jsColor->GetValueAt(vm, jsArg, i);
210 if (!jsValue->IsArray(vm)) {
211 ResetColor(nativeNode);
212 return panda::JSValueRef::Undefined(vm);
213 }
214 auto handle = panda::CopyableGlobal<panda::ArrayRef>(vm, jsValue);
215 float weight = handle->GetValueAt(vm, jsValue, 1)->ToNumber(vm)->Value();
216 Color selectedColor;
217 if (!ArkTSUtils::ParseJsColorAlpha(vm, handle->GetValueAt(vm, jsValue, 1), selectedColor)) {
218 selectedColor = ERROR_COLOR;
219 }
220 colors[i] = selectedColor.GetValue();
221 if (weight > 0) {
222 weights[i] = weight;
223 } else {
224 weights[i] = 0.0f;
225 }
226 }
227 GetArkUIInternalNodeAPI()->GetGaugeModifier().SetColors(nativeNode, colors.get(), weights.get(), length);
228 return panda::JSValueRef::Undefined(vm);
229 }
230
ResetColors(ArkUIRuntimeCallInfo * runtimeCallInfo)231 ArkUINativeModuleValue GaugeBridge::ResetColors(ArkUIRuntimeCallInfo* runtimeCallInfo)
232 {
233 EcmaVM* vm = runtimeCallInfo->GetVM();
234 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
235 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
236 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
237 ResetColor(nativeNode);
238 return panda::JSValueRef::Undefined(vm);
239 }
240
SetGaugeVaule(ArkUIRuntimeCallInfo * runtimeCallInfo)241 ArkUINativeModuleValue GaugeBridge::SetGaugeVaule(ArkUIRuntimeCallInfo* runtimeCallInfo)
242 {
243 EcmaVM* vm = runtimeCallInfo->GetVM();
244 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
245 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
246 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
247 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
248
249 if (!secondArg->IsNumber()) {
250 GetArkUIInternalNodeAPI()->GetGaugeModifier().ResetGaugeVaule(nativeNode);
251 return panda::JSValueRef::Undefined(vm);
252 }
253
254 float vaule = static_cast<float>(secondArg->ToNumber(vm)->Value());
255 GetArkUIInternalNodeAPI()->GetGaugeModifier().SetGaugeVaule(nativeNode, vaule);
256 return panda::JSValueRef::Undefined(vm);
257 }
258
ResetGaugeVaule(ArkUIRuntimeCallInfo * runtimeCallInfo)259 ArkUINativeModuleValue GaugeBridge::ResetGaugeVaule(ArkUIRuntimeCallInfo* runtimeCallInfo)
260 {
261 EcmaVM* vm = runtimeCallInfo->GetVM();
262 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
263 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
264 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
265 GetArkUIInternalNodeAPI()->GetGaugeModifier().ResetGaugeVaule(nativeNode);
266 return panda::JSValueRef::Undefined(vm);
267 }
268
SetGaugeStartAngle(ArkUIRuntimeCallInfo * runtimeCallInfo)269 ArkUINativeModuleValue GaugeBridge::SetGaugeStartAngle(ArkUIRuntimeCallInfo* runtimeCallInfo)
270 {
271 EcmaVM* vm = runtimeCallInfo->GetVM();
272 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
273 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
274 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
275 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
276
277 if (!secondArg->IsNumber()) {
278 GetArkUIInternalNodeAPI()->GetGaugeModifier().ResetGaugeStartAngle(nativeNode);
279 return panda::JSValueRef::Undefined(vm);
280 }
281
282 float vaule = static_cast<float>(secondArg->ToNumber(vm)->Value());
283 GetArkUIInternalNodeAPI()->GetGaugeModifier().SetGaugeStartAngle(nativeNode, vaule);
284 return panda::JSValueRef::Undefined(vm);
285 }
286
ResetGaugeStartAngle(ArkUIRuntimeCallInfo * runtimeCallInfo)287 ArkUINativeModuleValue GaugeBridge::ResetGaugeStartAngle(ArkUIRuntimeCallInfo* runtimeCallInfo)
288 {
289 EcmaVM* vm = runtimeCallInfo->GetVM();
290 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
291 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
292 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
293 GetArkUIInternalNodeAPI()->GetGaugeModifier().ResetGaugeStartAngle(nativeNode);
294 return panda::JSValueRef::Undefined(vm);
295 }
296
SetGaugeEndAngle(ArkUIRuntimeCallInfo * runtimeCallInfo)297 ArkUINativeModuleValue GaugeBridge::SetGaugeEndAngle(ArkUIRuntimeCallInfo* runtimeCallInfo)
298 {
299 EcmaVM* vm = runtimeCallInfo->GetVM();
300 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
301 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
302 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
303 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
304
305 if (!secondArg->IsNumber()) {
306 GetArkUIInternalNodeAPI()->GetGaugeModifier().ResetGaugeEndAngle(nativeNode);
307 return panda::JSValueRef::Undefined(vm);
308 }
309
310 float vaule = static_cast<float>(secondArg->ToNumber(vm)->Value());
311 GetArkUIInternalNodeAPI()->GetGaugeModifier().SetGaugeEndAngle(nativeNode, vaule);
312 return panda::JSValueRef::Undefined(vm);
313 }
314
ResetGaugeEndAngle(ArkUIRuntimeCallInfo * runtimeCallInfo)315 ArkUINativeModuleValue GaugeBridge::ResetGaugeEndAngle(ArkUIRuntimeCallInfo* runtimeCallInfo)
316 {
317 EcmaVM* vm = runtimeCallInfo->GetVM();
318 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
319 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
320 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
321 GetArkUIInternalNodeAPI()->GetGaugeModifier().ResetGaugeEndAngle(nativeNode);
322 return panda::JSValueRef::Undefined(vm);
323 }
324
SetGaugeStrokeWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)325 ArkUINativeModuleValue GaugeBridge::SetGaugeStrokeWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
326 {
327 EcmaVM* vm = runtimeCallInfo->GetVM();
328 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
329 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
330 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
331 Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(1);
332
333 CalcDimension strokeWidth;
334 if (!ArkTSUtils::ParseJsDimensionVpNG(vm, jsValue, strokeWidth) || strokeWidth.Unit() == DimensionUnit::PERCENT) {
335 strokeWidth = CalcDimension(0);
336 }
337 GetArkUIInternalNodeAPI()->GetGaugeModifier().SetGaugeStrokeWidth(
338 nativeNode, strokeWidth.Value(), static_cast<int>(strokeWidth.Unit()));
339 return panda::JSValueRef::Undefined(vm);
340 }
341
ResetGaugeStrokeWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)342 ArkUINativeModuleValue GaugeBridge::ResetGaugeStrokeWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
343 {
344 EcmaVM* vm = runtimeCallInfo->GetVM();
345 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
346 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
347 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
348 GetArkUIInternalNodeAPI()->GetGaugeModifier().ResetGaugeStrokeWidth(nativeNode);
349 return panda::JSValueRef::Undefined(vm);
350 }
351
SetGaugeTrackShadow(ArkUIRuntimeCallInfo * runtimeCallInfo)352 ArkUINativeModuleValue GaugeBridge::SetGaugeTrackShadow(ArkUIRuntimeCallInfo* runtimeCallInfo)
353 {
354 EcmaVM* vm = runtimeCallInfo->GetVM();
355 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
356 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
357 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
358 Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(1);
359 auto radiusArg = runtimeCallInfo->GetCallArgRef(2);
360 auto offsetXArg = runtimeCallInfo->GetCallArgRef(3);
361 auto offsetYArg = runtimeCallInfo->GetCallArgRef(4);
362
363 if (jsValue->IsNull()) {
364 GetArkUIInternalNodeAPI()->GetGaugeModifier().SetShadowOptions(nativeNode, DEFAULT_GAUGE_SHADOW_RADIUS,
365 DEFAULT_GAUGE_SHADOW_OFFSETX, DEFAULT_GAUGE_SHADOW_OFFSETY, false);
366 return panda::JSValueRef::Undefined(vm);
367 }
368
369 if (!jsValue->IsObject()) {
370 GetArkUIInternalNodeAPI()->GetGaugeModifier().ResetShadowOptions(nativeNode);
371 GetArkUIInternalNodeAPI()->GetGaugeModifier().SetIsShowIndicator(nativeNode, true);
372 return panda::JSValueRef::Undefined(vm);
373 }
374
375 double radius = 0.0;
376 if (!ArkTSUtils::ParseJsDouble(vm, radiusArg, radius)) {
377 radius = DEFAULT_GAUGE_SHADOW_RADIUS;
378 }
379
380 if (NonPositive(radius)) {
381 radius = DEFAULT_GAUGE_SHADOW_RADIUS;
382 }
383
384 double offsetX = 0.0;
385 if (!ArkTSUtils::ParseJsDouble(vm, offsetXArg, offsetX)) {
386 offsetX = DEFAULT_GAUGE_SHADOW_OFFSETX;
387 }
388
389 double offsetY = 0.0;
390 if (!ArkTSUtils::ParseJsDouble(vm, offsetYArg, offsetY)) {
391 offsetY = DEFAULT_GAUGE_SHADOW_OFFSETY;
392 }
393
394 GetArkUIInternalNodeAPI()->GetGaugeModifier().SetShadowOptions(nativeNode, radius, offsetX, offsetY, true);
395 return panda::JSValueRef::Undefined(vm);
396 }
397
ResetGaugeTrackShadow(ArkUIRuntimeCallInfo * runtimeCallInfo)398 ArkUINativeModuleValue GaugeBridge::ResetGaugeTrackShadow(ArkUIRuntimeCallInfo* runtimeCallInfo)
399 {
400 EcmaVM* vm = runtimeCallInfo->GetVM();
401 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
402 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
403 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
404 GetArkUIInternalNodeAPI()->GetGaugeModifier().ResetShadowOptions(nativeNode);
405 return panda::JSValueRef::Undefined(vm);
406 }
407
SetGaugeIndicator(ArkUIRuntimeCallInfo * runtimeCallInfo)408 ArkUINativeModuleValue GaugeBridge::SetGaugeIndicator(ArkUIRuntimeCallInfo* runtimeCallInfo)
409 {
410 EcmaVM* vm = runtimeCallInfo->GetVM();
411 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
412 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
413 auto iconArg = runtimeCallInfo->GetCallArgRef(1);
414 auto spaceArg = runtimeCallInfo->GetCallArgRef(2);
415 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
416 GetArkUIInternalNodeAPI()->GetGaugeModifier().SetIsShowIndicator(nativeNode, true);
417 std::string iconPath;
418 if (ArkTSUtils::ParseJsMedia(vm, iconArg, iconPath)) {
419 std::string bundleName;
420 std::string moduleName;
421 ArkTSUtils::GetJsMediaBundleInfo(vm, iconArg, bundleName, moduleName);
422 GetArkUIInternalNodeAPI()->GetGaugeModifier().SetIndicatorIconPath(nativeNode,
423 iconPath.c_str(), bundleName.c_str(), moduleName.c_str());
424 } else {
425 GetArkUIInternalNodeAPI()->GetGaugeModifier().ResetIndicatorIconPath(nativeNode);
426 }
427 CalcDimension space;
428 if (!ArkTSUtils::ParseJsDimensionVpNG(vm, spaceArg, space, false)) {
429 space = NG::INDICATOR_DISTANCE_TO_TOP;
430 }
431 if (space.IsNegative()) {
432 space = NG::INDICATOR_DISTANCE_TO_TOP;
433 }
434 GetArkUIInternalNodeAPI()->GetGaugeModifier().SetIndicatorSpace(nativeNode,
435 space.CalcValue().c_str(), space.Value(), static_cast<int32_t>(space.Unit()));
436 return panda::JSValueRef::Undefined(vm);
437 }
438
ResetGaugeIndicator(ArkUIRuntimeCallInfo * runtimeCallInfo)439 ArkUINativeModuleValue GaugeBridge::ResetGaugeIndicator(ArkUIRuntimeCallInfo* runtimeCallInfo)
440 {
441 EcmaVM* vm = runtimeCallInfo->GetVM();
442 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
443 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
444 auto valueArg = runtimeCallInfo->GetCallArgRef(1);
445 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
446 if (valueArg->IsNull()) {
447 GetArkUIInternalNodeAPI()->GetGaugeModifier().SetIsShowIndicator(nativeNode, false);
448 } else if (valueArg->IsUndefined() || (!valueArg->IsObject())) {
449 GetArkUIInternalNodeAPI()->GetGaugeModifier().ResetIndicatorIconPath(nativeNode);
450 GetArkUIInternalNodeAPI()->GetGaugeModifier().ResetIndicatorSpace(nativeNode);
451 GetArkUIInternalNodeAPI()->GetGaugeModifier().SetIsShowIndicator(nativeNode, true);
452 }
453 return panda::JSValueRef::Undefined(vm);
454 }
455 } // namespace OHOS::Ace::NG
456