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_side_bar_container_bridge.h"
16
17 #include "base/geometry/calc_dimension.h"
18 #include "base/geometry/dimension.h"
19 #include "core/interfaces/native/node/api.h"
20 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
21
22 namespace OHOS::Ace::NG {
23 constexpr int NUM_0 = 0;
24 constexpr int NUM_1 = 1;
25 constexpr int NUM_2 = 2;
26 constexpr int NUM_3 = 3;
27 constexpr int NUM_4 = 4;
28 constexpr int NUM_5 = 5;
29 constexpr int NUM_6 = 6;
30 constexpr int NUM_7 = 7;
31 constexpr uint32_t DEFAULT_SIDE_BAR_DIVIDER_COLOR = 0x08000000;
32 const CalcDimension DEFAULT_MAX_SIDE_BAR_WIDTH(280.0, DimensionUnit::VP);
33 const CalcDimension DEFAULT_SIDE_BAR_MIN_CONTENT_WIDTH(360.0, DimensionUnit::VP);
34 const Dimension DEFAULT_CONTROL_BUTTON_WIDTH = 32.0_vp;
35 const Dimension DEFAULT_CONTROL_BUTTON_WIDTH_V10 = 24.0_vp;
36 const Dimension DEFAULT_CONTROL_BUTTON_HEIGHT = 32.0_vp;
37 const Dimension DEFAULT_CONTROL_BUTTON_HEIGHT_V10 = 24.0_vp;
38 constexpr Dimension DEFAULT_CONTROL_BUTTON_LEFT = 16.0_vp;
39 constexpr Dimension DEFAULT_CONTROL_BUTTON_TOP = 48.0_vp;
SetSideBarWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)40 ArkUINativeModuleValue SideBarContainerBridge::SetSideBarWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
41 {
42 EcmaVM* vm = runtimeCallInfo->GetVM();
43 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
44 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
45 Local<JSValueRef> sideBarWidthArg = runtimeCallInfo->GetCallArgRef(NUM_1);
46 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
47 CalcDimension sideBarWidth;
48 if (ArkTSUtils::ParseJsDimensionNG(vm, sideBarWidthArg, sideBarWidth, DimensionUnit::VP, true) &&
49 sideBarWidth.Value() >= 0) {
50 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().SetSideBarWidth(
51 nativeNode, sideBarWidth.Value(), static_cast<int32_t>(sideBarWidth.Unit()));
52 } else {
53 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().ResetSideBarWidth(nativeNode);
54 }
55 return panda::JSValueRef::Undefined(vm);
56 }
57
ResetSideBarWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)58 ArkUINativeModuleValue SideBarContainerBridge::ResetSideBarWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
59 {
60 EcmaVM* vm = runtimeCallInfo->GetVM();
61 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
62 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
63 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
64 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().ResetSideBarWidth(nativeNode);
65 return panda::JSValueRef::Undefined(vm);
66 }
67
SetMinSideBarWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)68 ArkUINativeModuleValue SideBarContainerBridge::SetMinSideBarWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
69 {
70 EcmaVM* vm = runtimeCallInfo->GetVM();
71 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
72 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
73 Local<JSValueRef> minSideBarWidthArg = runtimeCallInfo->GetCallArgRef(NUM_1);
74 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
75 CalcDimension minSideBarWidth;
76 if (ArkTSUtils::ParseJsDimensionNG(vm, minSideBarWidthArg, minSideBarWidth, DimensionUnit::VP, true) &&
77 minSideBarWidth.Value() >= 0) {
78 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().SetMinSideBarWidth(
79 nativeNode, minSideBarWidth.Value(), static_cast<int32_t>(minSideBarWidth.Unit()));
80 } else {
81 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().ResetMinSideBarWidth(nativeNode);
82 }
83 return panda::JSValueRef::Undefined(vm);
84 }
85
ResetMinSideBarWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)86 ArkUINativeModuleValue SideBarContainerBridge::ResetMinSideBarWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
87 {
88 EcmaVM* vm = runtimeCallInfo->GetVM();
89 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
90 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
91 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
92 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().ResetMinSideBarWidth(nativeNode);
93 return panda::JSValueRef::Undefined(vm);
94 }
95
SetControlButton(ArkUIRuntimeCallInfo * runtimeCallInfo)96 ArkUINativeModuleValue SideBarContainerBridge::SetControlButton(ArkUIRuntimeCallInfo* runtimeCallInfo)
97 {
98 EcmaVM* vm = runtimeCallInfo->GetVM();
99 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
100 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
101 Local<JSValueRef> leftArg = runtimeCallInfo->GetCallArgRef(NUM_1);
102 Local<JSValueRef> topArg = runtimeCallInfo->GetCallArgRef(NUM_2);
103 Local<JSValueRef> widthArg = runtimeCallInfo->GetCallArgRef(NUM_3);
104 Local<JSValueRef> heightArg = runtimeCallInfo->GetCallArgRef(NUM_4);
105 Local<JSValueRef> iconsShownArg = runtimeCallInfo->GetCallArgRef(NUM_5);
106 Local<JSValueRef> iconsHiddenArg = runtimeCallInfo->GetCallArgRef(NUM_6);
107 Local<JSValueRef> iconsSwitchingArg = runtimeCallInfo->GetCallArgRef(NUM_7);
108 double values[NUM_4];
109 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
110 if (leftArg->IsNumber() && leftArg->ToNumber(vm)->Value() >= 0) {
111 values[NUM_0] = leftArg->ToNumber(vm)->Value();
112 } else {
113 values[NUM_0] = DEFAULT_CONTROL_BUTTON_LEFT.Value();
114 }
115 if (topArg->IsNumber() && topArg->ToNumber(vm)->Value() >= 0) {
116 values[NUM_1] = topArg->ToNumber(vm)->Value();
117 } else {
118 values[NUM_1] = DEFAULT_CONTROL_BUTTON_TOP.Value();
119 }
120 if (widthArg->IsNumber() && widthArg->ToNumber(vm)->Value() >= 0) {
121 values[NUM_2] = widthArg->ToNumber(vm)->Value();
122 } else {
123 if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN)) {
124 values[NUM_2] = DEFAULT_CONTROL_BUTTON_WIDTH_V10.Value();
125 } else {
126 values[NUM_2] = DEFAULT_CONTROL_BUTTON_WIDTH.Value();
127 }
128 }
129 if (heightArg->IsNumber() && heightArg->ToNumber(vm)->Value() >= 0) {
130 values[NUM_3] = heightArg->ToNumber(vm)->Value();
131 } else {
132 if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN)) {
133 values[NUM_3] = DEFAULT_CONTROL_BUTTON_HEIGHT_V10.Value();
134 } else {
135 values[NUM_3] = DEFAULT_CONTROL_BUTTON_HEIGHT.Value();
136 }
137 }
138 std::string iconsShown;
139 std::string iconsHidden;
140 std::string iconsSwitching;
141 struct ArkUIIconsStruct iconsStruct {
142 nullptr, nullptr, nullptr
143 };
144 if (ArkTSUtils::ParseJsMedia(vm, iconsShownArg, iconsShown)) {
145 iconsStruct.ShowIconInfo = iconsShown.c_str();
146 }
147 if (ArkTSUtils::ParseJsMedia(vm, iconsHiddenArg, iconsHidden)) {
148 iconsStruct.HiddenIconInfo = iconsHidden.c_str();
149 }
150 if (ArkTSUtils::ParseJsMedia(vm, iconsSwitchingArg, iconsSwitching)) {
151 iconsStruct.SwitchingIconInfo = iconsSwitching.c_str();
152 }
153 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().SetControlButton(nativeNode, values, NUM_4, &iconsStruct);
154 return panda::JSValueRef::Undefined(vm);
155 }
156
ResetControlButton(ArkUIRuntimeCallInfo * runtimeCallInfo)157 ArkUINativeModuleValue SideBarContainerBridge::ResetControlButton(ArkUIRuntimeCallInfo* runtimeCallInfo)
158 {
159 EcmaVM* vm = runtimeCallInfo->GetVM();
160 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
161 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
162 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
163 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().ResetControlButton(nativeNode);
164 return panda::JSValueRef::Undefined(vm);
165 }
166
SetShowControlButton(ArkUIRuntimeCallInfo * runtimeCallInfo)167 ArkUINativeModuleValue SideBarContainerBridge::SetShowControlButton(ArkUIRuntimeCallInfo* runtimeCallInfo)
168 {
169 EcmaVM* vm = runtimeCallInfo->GetVM();
170 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
171 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
172 Local<JSValueRef> showControlButtonArg = runtimeCallInfo->GetCallArgRef(NUM_1);
173 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
174 bool isShow = true;
175 if (showControlButtonArg->IsBoolean()) {
176 isShow = showControlButtonArg->ToBoolean(vm)->Value();
177 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().SetShowControlButton(nativeNode, isShow);
178 } else {
179 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().ResetShowControlButton(nativeNode);
180 }
181 return panda::JSValueRef::Undefined(vm);
182 }
183
ResetShowControlButton(ArkUIRuntimeCallInfo * runtimeCallInfo)184 ArkUINativeModuleValue SideBarContainerBridge::ResetShowControlButton(ArkUIRuntimeCallInfo* runtimeCallInfo)
185 {
186 EcmaVM* vm = runtimeCallInfo->GetVM();
187 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
188 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
189 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
190 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().ResetShowControlButton(nativeNode);
191 return panda::JSValueRef::Undefined(vm);
192 }
193
SetAutoHide(ArkUIRuntimeCallInfo * runtimeCallInfo)194 ArkUINativeModuleValue SideBarContainerBridge::SetAutoHide(ArkUIRuntimeCallInfo* runtimeCallInfo)
195 {
196 EcmaVM* vm = runtimeCallInfo->GetVM();
197 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
198 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
199 Local<JSValueRef> autoHideArg = runtimeCallInfo->GetCallArgRef(NUM_1);
200 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
201 if (autoHideArg->IsBoolean()) {
202 uint32_t value = static_cast<uint32_t>(autoHideArg->ToBoolean(vm)->Value());
203 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().SetAutoHide(nativeNode, value);
204 } else {
205 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().ResetAutoHide(nativeNode);
206 }
207 return panda::JSValueRef::Undefined(vm);
208 }
209
ResetAutoHide(ArkUIRuntimeCallInfo * runtimeCallInfo)210 ArkUINativeModuleValue SideBarContainerBridge::ResetAutoHide(ArkUIRuntimeCallInfo* runtimeCallInfo)
211 {
212 EcmaVM* vm = runtimeCallInfo->GetVM();
213 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
214 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
215 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
216 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().ResetAutoHide(nativeNode);
217 return panda::JSValueRef::Undefined(vm);
218 }
219
SetMaxSideBarWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)220 ArkUINativeModuleValue SideBarContainerBridge::SetMaxSideBarWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
221 {
222 EcmaVM* vm = runtimeCallInfo->GetVM();
223 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
224 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
225 Local<JSValueRef> maxSideBarWidthArg = runtimeCallInfo->GetCallArgRef(NUM_1);
226 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
227 CalcDimension maxSideBarWidth(DEFAULT_MAX_SIDE_BAR_WIDTH);
228 if (ArkTSUtils::ParseJsDimensionNG(vm, maxSideBarWidthArg, maxSideBarWidth, DimensionUnit::VP, true) &&
229 maxSideBarWidth.Value() >= 0) {
230 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().SetSideBarContainerMaxSideBarWidth(
231 nativeNode, maxSideBarWidth.Value(), static_cast<int32_t>(maxSideBarWidth.Unit()));
232 } else {
233 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().ResetSideBarContainerMaxSideBarWidth(nativeNode);
234 }
235 return panda::JSValueRef::Undefined(vm);
236 }
237
ResetMaxSideBarWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)238 ArkUINativeModuleValue SideBarContainerBridge::ResetMaxSideBarWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
239 {
240 EcmaVM* vm = runtimeCallInfo->GetVM();
241 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
242 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
243 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
244 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().ResetSideBarContainerMaxSideBarWidth(nativeNode);
245 return panda::JSValueRef::Undefined(vm);
246 }
247
SetMinContentWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)248 ArkUINativeModuleValue SideBarContainerBridge::SetMinContentWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
249 {
250 EcmaVM* vm = runtimeCallInfo->GetVM();
251 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
252 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
253 Local<JSValueRef> minContentWidthArg = runtimeCallInfo->GetCallArgRef(NUM_1);
254 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
255 CalcDimension minContentWidth(DEFAULT_SIDE_BAR_MIN_CONTENT_WIDTH);
256 if (ArkTSUtils::ParseJsDimensionNG(vm, minContentWidthArg, minContentWidth, DimensionUnit::VP, true) &&
257 minContentWidth.Value() >= 0) {
258 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().SetSideBarContainerMinContentWidth(
259 nativeNode, minContentWidth.Value(), static_cast<int32_t>(minContentWidth.Unit()));
260 } else {
261 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().ResetSideBarContainerMinContentWidth(nativeNode);
262 }
263 return panda::JSValueRef::Undefined(vm);
264 }
265
ResetMinContentWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)266 ArkUINativeModuleValue SideBarContainerBridge::ResetMinContentWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
267 {
268 EcmaVM* vm = runtimeCallInfo->GetVM();
269 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
270 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
271 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
272 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().ResetSideBarContainerMinContentWidth(nativeNode);
273 return panda::JSValueRef::Undefined(vm);
274 }
275
SetSideBarPosition(ArkUIRuntimeCallInfo * runtimeCallInfo)276 ArkUINativeModuleValue SideBarContainerBridge::SetSideBarPosition(ArkUIRuntimeCallInfo* runtimeCallInfo)
277 {
278 EcmaVM* vm = runtimeCallInfo->GetVM();
279 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
280 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
281 Local<JSValueRef> sideBarPositionArg = runtimeCallInfo->GetCallArgRef(NUM_1);
282 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
283 int32_t sideBarPosition = static_cast<int32_t>(SideBarPosition::START);
284 if (sideBarPositionArg->IsInt()) {
285 sideBarPosition = sideBarPositionArg->Int32Value(vm);
286 }
287 if (sideBarPosition < static_cast<int32_t>(SideBarPosition::START) ||
288 sideBarPosition > static_cast<int32_t>(SideBarPosition::END)) {
289 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().ResetSideBarPosition(nativeNode);
290 } else {
291 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().SetSideBarPosition(nativeNode, sideBarPosition);
292 }
293 return panda::JSValueRef::Undefined(vm);
294 }
295
ResetSideBarPosition(ArkUIRuntimeCallInfo * runtimeCallInfo)296 ArkUINativeModuleValue SideBarContainerBridge::ResetSideBarPosition(ArkUIRuntimeCallInfo* runtimeCallInfo)
297 {
298 EcmaVM* vm = runtimeCallInfo->GetVM();
299 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
300 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
301 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
302 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().ResetSideBarPosition(nativeNode);
303 return panda::JSValueRef::Undefined(vm);
304 }
305
SetShowSideBar(ArkUIRuntimeCallInfo * runtimeCallInfo)306 ArkUINativeModuleValue SideBarContainerBridge::SetShowSideBar(ArkUIRuntimeCallInfo* runtimeCallInfo)
307 {
308 EcmaVM* vm = runtimeCallInfo->GetVM();
309 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
310 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
311 Local<JSValueRef> showSideBarArg = runtimeCallInfo->GetCallArgRef(NUM_1);
312 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
313 if (showSideBarArg->IsBoolean()) {
314 bool isShow = showSideBarArg->ToBoolean(vm)->Value();
315 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().SetShowSideBar(nativeNode, isShow);
316 } else {
317 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().ResetShowSideBar(nativeNode);
318 }
319 return panda::JSValueRef::Undefined(vm);
320 }
321
ResetShowSideBar(ArkUIRuntimeCallInfo * runtimeCallInfo)322 ArkUINativeModuleValue SideBarContainerBridge::ResetShowSideBar(ArkUIRuntimeCallInfo* runtimeCallInfo)
323 {
324 EcmaVM* vm = runtimeCallInfo->GetVM();
325 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
326 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
327 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
328 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().ResetShowSideBar(nativeNode);
329 return panda::JSValueRef::Undefined(vm);
330 }
331
SetDivider(ArkUIRuntimeCallInfo * runtimeCallInfo)332 ArkUINativeModuleValue SideBarContainerBridge::SetDivider(ArkUIRuntimeCallInfo* runtimeCallInfo)
333 {
334 EcmaVM* vm = runtimeCallInfo->GetVM();
335 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
336 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
337 Local<JSValueRef> strokeWidthArg = runtimeCallInfo->GetCallArgRef(NUM_1);
338 Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(NUM_2);
339 Local<JSValueRef> startMarginArg = runtimeCallInfo->GetCallArgRef(NUM_3);
340 Local<JSValueRef> endMarginArg = runtimeCallInfo->GetCallArgRef(NUM_4);
341 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
342 CalcDimension strokeWidth;
343 CalcDimension startMargin;
344 CalcDimension endMargin;
345 double values[NUM_3] = { 1.0, 0.0, 0.0 };
346 int32_t units[NUM_3] = { static_cast<int32_t>(DimensionUnit::VP) };
347 if (ArkTSUtils::ParseJsDimensionNG(vm, strokeWidthArg, strokeWidth, DimensionUnit::VP, false) &&
348 strokeWidth.Value() >= 0) {
349 values[NUM_0] = strokeWidth.Value();
350 units[NUM_0] = static_cast<int32_t>(strokeWidth.Unit());
351 } else {
352 strokeWidth.SetValue(1.0);
353 strokeWidth.SetUnit(DimensionUnit::VP);
354 }
355 if (ArkTSUtils::ParseJsDimensionNG(vm, startMarginArg, startMargin, DimensionUnit::VP, false) &&
356 startMargin.Value() >= 0) {
357 values[NUM_1] = startMargin.Value();
358 units[NUM_1] = static_cast<int32_t>(startMargin.Unit());
359 } else {
360 startMargin.SetValue(0.0);
361 startMargin.SetUnit(DimensionUnit::VP);
362 }
363 if (ArkTSUtils::ParseJsDimensionNG(vm, endMarginArg, endMargin, DimensionUnit::VP, false) &&
364 endMargin.Value() >= 0) {
365 values[NUM_2] = endMargin.Value();
366 units[NUM_2] = static_cast<int32_t>(endMargin.Unit());
367 } else {
368 endMargin.SetValue(0.0);
369 endMargin.SetUnit(DimensionUnit::VP);
370 }
371
372 Color color(DEFAULT_SIDE_BAR_DIVIDER_COLOR);
373 if (!ArkTSUtils::ParseJsColorAlpha(vm, colorArg, color)) {
374 color.SetValue(DEFAULT_SIDE_BAR_DIVIDER_COLOR);
375 }
376 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().SetSideBarContainerDivider(
377 nativeNode, values, units, NUM_3, color.GetValue());
378 return panda::JSValueRef::Undefined(vm);
379 }
380
ResetDivider(ArkUIRuntimeCallInfo * runtimeCallInfo)381 ArkUINativeModuleValue SideBarContainerBridge::ResetDivider(ArkUIRuntimeCallInfo* runtimeCallInfo)
382 {
383 EcmaVM* vm = runtimeCallInfo->GetVM();
384 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
385 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
386 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
387 GetArkUIInternalNodeAPI()->GetSideBarContainerModifier().ResetSideBarContainerDivider(nativeNode);
388 return panda::JSValueRef::Undefined(vm);
389 }
390 } // namespace OHOS::Ace::NG
391