• 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_tabs_bridge.h"
16 
17 #include "base/utils/utils.h"
18 #include "core/interfaces/native/node/api.h"
19 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
20 #include "core/components/common/properties/color.h"
21 #include "frameworks/bridge/common/utils/utils.h"
22 #include "frameworks/bridge/declarative_frontend/engine/js_types.h"
23 #include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h"
24 #include "frameworks/core/components/tab_bar/tab_theme.h"
25 #include "frameworks/core/components_ng/pattern/tabs/tabs_node.h"
26 
27 namespace OHOS::Ace::NG {
28 constexpr int SIZE_OF_FIVE = 5;
29 constexpr int SIZE_OF_THREE = 3;
30 constexpr int SIZE_OF_VALUES = 2;
31 constexpr int TABS_ARG_INDEX_0 = 0;
32 constexpr int TABS_ARG_INDEX_1 = 1;
33 constexpr int TABS_ARG_INDEX_2 = 2;
34 constexpr int TABS_ARG_INDEX_3 = 3;
35 constexpr int TABS_ARG_INDEX_4 = 4;
36 constexpr int TABS_ARG_INDEX_5 = 5;
37 constexpr int32_t SM_COLUMN_NUM = 4;
38 constexpr int32_t MD_COLUMN_NUM = 8;
39 constexpr int32_t LG_COLUMN_NUM = 12;
40 constexpr int32_t DEFAULT_COLUMN = -1;
41 constexpr int REMAINDER = 2;
42 constexpr int TABBARMODE_SCROLLABLE = 1;
SetTabBarMode(ArkUIRuntimeCallInfo * runtimeCallInfo)43 ArkUINativeModuleValue TabsBridge::SetTabBarMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
44 {
45     EcmaVM* vm = runtimeCallInfo->GetVM();
46     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
47     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(TABS_ARG_INDEX_0);
48     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
49     Local<JSValueRef> barModeArg = runtimeCallInfo->GetCallArgRef(TABS_ARG_INDEX_1);
50     Local<JSValueRef> marginArg = runtimeCallInfo->GetCallArgRef(TABS_ARG_INDEX_2);
51     Local<JSValueRef> nonScrollableLayoutStyleArg = runtimeCallInfo->GetCallArgRef(TABS_ARG_INDEX_3);
52 
53     if (barModeArg->IsNull() || barModeArg->IsUndefined()) {
54         GetArkUIInternalNodeAPI()->GetTabsModifier().ResetTabBarMode(nativeNode);
55         return panda::JSValueRef::Undefined(vm);
56     }
57     TabBarMode barMode = TabBarMode::FIXED;
58     barMode = Framework::ConvertStrToTabBarMode(barModeArg->ToString(vm)->ToString());
59     int32_t tabBarMode = static_cast<int32_t>(barMode);
60     GetArkUIInternalNodeAPI()->GetTabsModifier().SetTabBarMode(nativeNode, tabBarMode);
61 
62     if (tabBarMode == TABBARMODE_SCROLLABLE) {
63         if (marginArg->IsNull() || marginArg->IsUndefined() || nonScrollableLayoutStyleArg->IsNull() ||
64             nonScrollableLayoutStyleArg->IsUndefined()) {
65             GetArkUIInternalNodeAPI()->GetTabsModifier().ResetScrollableBarModeOptions(nativeNode);
66             return panda::JSValueRef::Undefined(vm);
67         }
68         int barModeStyle = nonScrollableLayoutStyleArg->Int32Value(vm);
69         CalcDimension margin(0.0, DimensionUnit::VP);
70         if (!ArkTSUtils::ParseJsDimensionVp(vm, marginArg, margin)) {
71             margin.Reset();
72         }
73 
74         GetArkUIInternalNodeAPI()->GetTabsModifier().SetScrollableBarModeOptions(
75             nativeNode, margin.Value(), static_cast<int>(margin.Unit()), barModeStyle);
76     }
77     return panda::JSValueRef::Undefined(vm);
78 }
79 
ResetTabBarMode(ArkUIRuntimeCallInfo * runtimeCallInfo)80 ArkUINativeModuleValue TabsBridge::ResetTabBarMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
81 {
82     EcmaVM* vm = runtimeCallInfo->GetVM();
83     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
84     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
85     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
86     GetArkUIInternalNodeAPI()->GetTabsModifier().ResetTabBarMode(nativeNode);
87     return panda::JSValueRef::Undefined(vm);
88 }
89 
SetScrollableBarModeOptions(ArkUIRuntimeCallInfo * runtimeCallInfo)90 ArkUINativeModuleValue TabsBridge::SetScrollableBarModeOptions(ArkUIRuntimeCallInfo* runtimeCallInfo)
91 {
92     EcmaVM* vm = runtimeCallInfo->GetVM();
93     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
94     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(TABS_ARG_INDEX_0);
95     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(TABS_ARG_INDEX_1);
96     Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(TABS_ARG_INDEX_2);
97     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
98 
99     if (thirdArg->IsUndefined()) {
100         GetArkUIInternalNodeAPI()->GetTabsModifier().ResetScrollableBarModeOptions(nativeNode);
101         return panda::JSValueRef::Undefined(vm);
102     }
103     int barModeStyle = thirdArg->Int32Value(vm);
104 
105     CalcDimension margin(0.0, DimensionUnit::VP);
106     if (!ArkTSUtils::ParseJsDimensionVp(vm, secondArg, margin)) {
107         margin.Reset();
108     }
109 
110     GetArkUIInternalNodeAPI()->GetTabsModifier().SetScrollableBarModeOptions(
111         nativeNode, margin.Value(), static_cast<int>(margin.Unit()), barModeStyle);
112     return panda::JSValueRef::Undefined(vm);
113 }
114 
ResetScrollableBarModeOptions(ArkUIRuntimeCallInfo * runtimeCallInfo)115 ArkUINativeModuleValue TabsBridge::ResetScrollableBarModeOptions(ArkUIRuntimeCallInfo* runtimeCallInfo)
116 {
117     EcmaVM* vm = runtimeCallInfo->GetVM();
118     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
119     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
120     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
121     GetArkUIInternalNodeAPI()->GetTabsModifier().ResetScrollableBarModeOptions(nativeNode);
122     return panda::JSValueRef::Undefined(vm);
123 }
124 
SetBarGridAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)125 ArkUINativeModuleValue TabsBridge::SetBarGridAlign(ArkUIRuntimeCallInfo* runtimeCallInfo)
126 {
127     EcmaVM* vm = runtimeCallInfo->GetVM();
128     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
129     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(TABS_ARG_INDEX_0);
130     Local<JSValueRef> smArg = runtimeCallInfo->GetCallArgRef(TABS_ARG_INDEX_1);
131     Local<JSValueRef> mdArg = runtimeCallInfo->GetCallArgRef(TABS_ARG_INDEX_2);
132     Local<JSValueRef> lgArg = runtimeCallInfo->GetCallArgRef(TABS_ARG_INDEX_3);
133     Local<JSValueRef> gutterArg = runtimeCallInfo->GetCallArgRef(TABS_ARG_INDEX_4);
134     Local<JSValueRef> marginArg = runtimeCallInfo->GetCallArgRef(TABS_ARG_INDEX_5);
135     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
136 
137     int32_t sm = DEFAULT_COLUMN;
138     int32_t md = DEFAULT_COLUMN;
139     int32_t lg = DEFAULT_COLUMN;
140     if (smArg->IsNumber() && smArg->Int32Value(vm) >= 0 && smArg->Int32Value(vm) <= SM_COLUMN_NUM &&
141         smArg->Int32Value(vm) % REMAINDER == 0) {
142         sm = smArg->Int32Value(vm);
143     }
144     if (mdArg->IsNumber() && mdArg->Int32Value(vm) >= 0 && mdArg->Int32Value(vm) <= MD_COLUMN_NUM &&
145         mdArg->Int32Value(vm) % REMAINDER == 0) {
146         md = mdArg->Int32Value(vm);
147     }
148     if (lgArg->IsNumber() && lgArg->Int32Value(vm) >= 0 && lgArg->Int32Value(vm) <= LG_COLUMN_NUM &&
149         lgArg->Int32Value(vm) % REMAINDER == 0) {
150         lg = lgArg->Int32Value(vm);
151     }
152 
153     CalcDimension columnGutter;
154     CalcDimension columnMargin;
155     if (!ArkTSUtils::ParseJsDimensionVp(vm, gutterArg, columnGutter) || !NonNegative(columnGutter.Value()) ||
156         columnGutter.Unit() == DimensionUnit::PERCENT) {
157         columnGutter.Reset();
158     }
159     if (!ArkTSUtils::ParseJsDimensionVp(vm, marginArg, columnMargin) || !NonNegative(columnMargin.Value()) ||
160         columnMargin.Unit() == DimensionUnit::PERCENT) {
161         columnMargin.Reset();
162     }
163 
164     int unitsAndColumn[SIZE_OF_FIVE];
165     double values[SIZE_OF_VALUES];
166 
167     values[TABS_ARG_INDEX_0] = columnGutter.Value();
168     values[TABS_ARG_INDEX_1] = columnMargin.Value();
169     unitsAndColumn[TABS_ARG_INDEX_0] = static_cast<int>(columnGutter.Unit());
170     unitsAndColumn[TABS_ARG_INDEX_1] = static_cast<int>(columnMargin.Unit());
171     unitsAndColumn[TABS_ARG_INDEX_2] = sm;
172     unitsAndColumn[TABS_ARG_INDEX_3] = md;
173     unitsAndColumn[TABS_ARG_INDEX_4] = lg;
174 
175     GetArkUIInternalNodeAPI()->GetTabsModifier().SetBarGridAlign(
176         nativeNode, values, SIZE_OF_VALUES, unitsAndColumn, SIZE_OF_FIVE);
177     return panda::JSValueRef::Undefined(vm);
178 }
179 
ResetBarGridAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)180 ArkUINativeModuleValue TabsBridge::ResetBarGridAlign(ArkUIRuntimeCallInfo* runtimeCallInfo)
181 {
182     EcmaVM* vm = runtimeCallInfo->GetVM();
183     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
184     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
185     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
186     GetArkUIInternalNodeAPI()->GetTabsModifier().ResetBarGridAlign(nativeNode);
187     return panda::JSValueRef::Undefined(vm);
188 }
189 
SetDivider(ArkUIRuntimeCallInfo * runtimeCallInfo)190 ArkUINativeModuleValue TabsBridge::SetDivider(ArkUIRuntimeCallInfo* runtimeCallInfo)
191 {
192     EcmaVM* vm = runtimeCallInfo->GetVM();
193     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
194     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
195     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
196     Local<JSValueRef> dividerStrokeWidthArgs = runtimeCallInfo->GetCallArgRef(TABS_ARG_INDEX_1);
197     Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(TABS_ARG_INDEX_2);
198     Local<JSValueRef> dividerStartMarginArgs = runtimeCallInfo->GetCallArgRef(TABS_ARG_INDEX_3);
199     Local<JSValueRef> dividerEndMarginArgs = runtimeCallInfo->GetCallArgRef(TABS_ARG_INDEX_4);
200     if (dividerStrokeWidthArgs->IsUndefined() && dividerStartMarginArgs->IsUndefined() &&
201         dividerEndMarginArgs->IsUndefined() && colorArg->IsUndefined()) {
202         GetArkUIInternalNodeAPI()->GetTabsModifier().ResetDivider(nativeNode);
203         return panda::JSValueRef::Undefined(vm);
204     }
205 
206     CalcDimension dividerStrokeWidth;
207     CalcDimension dividerStartMargin;
208     CalcDimension dividerEndMargin;
209     uint32_t color;
210     auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
211     auto context = frameNode->GetContext();
212     auto themeManager = context->GetThemeManager();
213     CHECK_NULL_RETURN(themeManager, panda::NativePointerRef::New(vm, nullptr));
214     auto tabTheme = themeManager->GetTheme<TabTheme>();
215     CHECK_NULL_RETURN(tabTheme, panda::NativePointerRef::New(vm, nullptr));
216 
217     if (!ArkTSUtils::ParseJsDimensionVp(vm, dividerStrokeWidthArgs, dividerStrokeWidth) ||
218         LessNotEqual(dividerStrokeWidth.Value(), 0.0f) || dividerStrokeWidth.Unit() == DimensionUnit::PERCENT) {
219         dividerStrokeWidth.Reset();
220     }
221     Color colorObj;
222     if (!ArkTSUtils::ParseJsColorAlpha(vm, colorArg, colorObj)) {
223         color = tabTheme->GetDividerColor().GetValue();
224     } else {
225         color = colorObj.GetValue();
226     }
227     if (!ArkTSUtils::ParseJsDimensionVp(vm, dividerStartMarginArgs, dividerStartMargin) ||
228         LessNotEqual(dividerStartMargin.Value(), 0.0f) || dividerStartMargin.Unit() == DimensionUnit::PERCENT) {
229         dividerStartMargin.Reset();
230     }
231     if (!ArkTSUtils::ParseJsDimensionVp(vm, dividerEndMarginArgs, dividerEndMargin) ||
232         LessNotEqual(dividerEndMargin.Value(), 0.0f) || dividerEndMargin.Unit() == DimensionUnit::PERCENT) {
233         dividerEndMargin.Reset();
234     }
235     uint32_t size = SIZE_OF_THREE;
236     double values[size];
237     int32_t units[size];
238     values[TABS_ARG_INDEX_0] = dividerStrokeWidth.Value();
239     values[TABS_ARG_INDEX_1] = dividerStartMargin.Value();
240     values[TABS_ARG_INDEX_2] = dividerEndMargin.Value();
241     units[TABS_ARG_INDEX_0] = static_cast<int32_t>(dividerStrokeWidth.Unit());
242     units[TABS_ARG_INDEX_1] = static_cast<int32_t>(dividerStartMargin.Unit());
243     units[TABS_ARG_INDEX_2] = static_cast<int32_t>(dividerEndMargin.Unit());
244     GetArkUIInternalNodeAPI()->GetTabsModifier().SetDivider(nativeNode, color, values, units, size);
245     return panda::JSValueRef::Undefined(vm);
246 }
247 
ResetDivider(ArkUIRuntimeCallInfo * runtimeCallInfo)248 ArkUINativeModuleValue TabsBridge::ResetDivider(ArkUIRuntimeCallInfo* runtimeCallInfo)
249 {
250     EcmaVM* vm = runtimeCallInfo->GetVM();
251     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
252     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
253     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
254     GetArkUIInternalNodeAPI()->GetTabsModifier().ResetDivider(nativeNode);
255     return panda::JSValueRef::Undefined(vm);
256 }
257 
SetFadingEdge(ArkUIRuntimeCallInfo * runtimeCallInfo)258 ArkUINativeModuleValue TabsBridge::SetFadingEdge(ArkUIRuntimeCallInfo* runtimeCallInfo)
259 {
260     EcmaVM* vm = runtimeCallInfo->GetVM();
261     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
262     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
263     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
264     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
265     if (secondArg->IsUndefined() || secondArg->IsNull()) {
266         GetArkUIInternalNodeAPI()->GetTabsModifier().ResetFadingEdge(nativeNode);
267         return panda::JSValueRef::Undefined(vm);
268     }
269     bool fadingEdge = secondArg->ToBoolean(vm)->Value();
270     GetArkUIInternalNodeAPI()->GetTabsModifier().SetFadingEdge(nativeNode, fadingEdge);
271     return panda::JSValueRef::Undefined(vm);
272 }
273 
ResetFadingEdge(ArkUIRuntimeCallInfo * runtimeCallInfo)274 ArkUINativeModuleValue TabsBridge::ResetFadingEdge(ArkUIRuntimeCallInfo* runtimeCallInfo)
275 {
276     EcmaVM* vm = runtimeCallInfo->GetVM();
277     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
278     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
279     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
280     GetArkUIInternalNodeAPI()->GetTabsModifier().ResetFadingEdge(nativeNode);
281     return panda::JSValueRef::Undefined(vm);
282 }
283 
SetBarBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)284 ArkUINativeModuleValue TabsBridge::SetBarBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
285 {
286     EcmaVM* vm = runtimeCallInfo->GetVM();
287     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
288     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
289     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
290     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
291     Color color;
292     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
293         GetArkUIInternalNodeAPI()->GetTabsModifier().ResetBarBackgroundColor(nativeNode);
294     } else {
295         GetArkUIInternalNodeAPI()->GetTabsModifier().SetBarBackgroundColor(nativeNode, color.GetValue());
296     }
297     return panda::JSValueRef::Undefined(vm);
298 }
299 
ResetBarBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)300 ArkUINativeModuleValue TabsBridge::ResetBarBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
301 {
302     EcmaVM* vm = runtimeCallInfo->GetVM();
303     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
304     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
305     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
306     GetArkUIInternalNodeAPI()->GetTabsModifier().ResetBarBackgroundColor(nativeNode);
307     return panda::JSValueRef::Undefined(vm);
308 }
309 
SetBarOverlap(ArkUIRuntimeCallInfo * runtimeCallInfo)310 ArkUINativeModuleValue TabsBridge::SetBarOverlap(ArkUIRuntimeCallInfo* runtimeCallInfo)
311 {
312     EcmaVM* vm = runtimeCallInfo->GetVM();
313     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
314     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
315     Local<JSValueRef> overlapArg = runtimeCallInfo->GetCallArgRef(1);
316     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
317     if (overlapArg->IsUndefined()) {
318         GetArkUIInternalNodeAPI()->GetTabsModifier().ResetBarOverlap(nativeNode);
319     } else {
320         bool overlap = overlapArg->ToBoolean(vm)->Value();
321         GetArkUIInternalNodeAPI()->GetTabsModifier().SetBarOverlap(nativeNode, overlap);
322     }
323     return panda::JSValueRef::Undefined(vm);
324 }
325 
ResetBarOverlap(ArkUIRuntimeCallInfo * runtimeCallInfo)326 ArkUINativeModuleValue TabsBridge::ResetBarOverlap(ArkUIRuntimeCallInfo* runtimeCallInfo)
327 {
328     EcmaVM* vm = runtimeCallInfo->GetVM();
329     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
330     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
331     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
332     GetArkUIInternalNodeAPI()->GetTabsModifier().ResetBarOverlap(nativeNode);
333     return panda::JSValueRef::Undefined(vm);
334 }
SetIsVertical(ArkUIRuntimeCallInfo * runtimeCallInfo)335 ArkUINativeModuleValue TabsBridge::SetIsVertical(ArkUIRuntimeCallInfo* runtimeCallInfo)
336 {
337     EcmaVM* vm = runtimeCallInfo->GetVM();
338     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
339     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
340     Local<JSValueRef> isVerticalArg = runtimeCallInfo->GetCallArgRef(1);
341     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
342     if (isVerticalArg->IsNull() || isVerticalArg->IsUndefined()) {
343         GetArkUIInternalNodeAPI()->GetTabsModifier().ResetIsVertical(nativeNode);
344         return panda::JSValueRef::Undefined(vm);
345     }
346     bool isVertical = isVerticalArg->ToBoolean(vm)->Value();
347     GetArkUIInternalNodeAPI()->GetTabsModifier().SetIsVertical(nativeNode, isVertical);
348     return panda::JSValueRef::Undefined(vm);
349 }
350 
ResetIsVertical(ArkUIRuntimeCallInfo * runtimeCallInfo)351 ArkUINativeModuleValue TabsBridge::ResetIsVertical(ArkUIRuntimeCallInfo* runtimeCallInfo)
352 {
353     EcmaVM* vm = runtimeCallInfo->GetVM();
354     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
355     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
356     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
357     GetArkUIInternalNodeAPI()->GetTabsModifier().ResetIsVertical(nativeNode);
358     return panda::JSValueRef::Undefined(vm);
359 }
360 
SetTabBarPosition(ArkUIRuntimeCallInfo * runtimeCallInfo)361 ArkUINativeModuleValue TabsBridge::SetTabBarPosition(ArkUIRuntimeCallInfo* runtimeCallInfo)
362 {
363     EcmaVM* vm = runtimeCallInfo->GetVM();
364     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
365     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
366     Local<JSValueRef> barValArg = runtimeCallInfo->GetCallArgRef(1);
367     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
368     if (barValArg->IsNull() || barValArg->IsUndefined()) {
369         GetArkUIInternalNodeAPI()->GetTabsModifier().ResetTabBarPosition(nativeNode);
370     } else {
371         int32_t barVal = barValArg->Int32Value(vm);
372         GetArkUIInternalNodeAPI()->GetTabsModifier().SetTabBarPosition(nativeNode, barVal);
373     }
374 
375     return panda::JSValueRef::Undefined(vm);
376 }
377 
ResetTabBarPosition(ArkUIRuntimeCallInfo * runtimeCallInfo)378 ArkUINativeModuleValue TabsBridge::ResetTabBarPosition(ArkUIRuntimeCallInfo* runtimeCallInfo)
379 {
380     EcmaVM* vm = runtimeCallInfo->GetVM();
381     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
382     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
383     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
384     GetArkUIInternalNodeAPI()->GetTabsModifier().ResetTabBarPosition(nativeNode);
385     return panda::JSValueRef::Undefined(vm);
386 }
387 
SetScrollable(ArkUIRuntimeCallInfo * runtimeCallInfo)388 ArkUINativeModuleValue TabsBridge::SetScrollable(ArkUIRuntimeCallInfo* runtimeCallInfo)
389 {
390     EcmaVM* vm = runtimeCallInfo->GetVM();
391     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
392     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
393     Local<JSValueRef> scrollableArg = runtimeCallInfo->GetCallArgRef(1);
394     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
395     ArkUINativeModuleValue undefinedRes = panda::JSValueRef::Undefined(vm);
396 
397     if (scrollableArg->IsNull() || scrollableArg->IsUndefined()) {
398         GetArkUIInternalNodeAPI()->GetTabsModifier().ResetScrollable(nativeNode);
399         return undefinedRes;
400     }
401 
402     bool scrollable = scrollableArg->ToBoolean(vm)->Value();
403     GetArkUIInternalNodeAPI()->GetTabsModifier().SetScrollable(nativeNode, scrollable);
404     return undefinedRes;
405 }
406 
ResetScrollable(ArkUIRuntimeCallInfo * runtimeCallInfo)407 ArkUINativeModuleValue TabsBridge::ResetScrollable(ArkUIRuntimeCallInfo* runtimeCallInfo)
408 {
409     EcmaVM* vm = runtimeCallInfo->GetVM();
410     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
411     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
412     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
413     GetArkUIInternalNodeAPI()->GetTabsModifier().ResetScrollable(nativeNode);
414     return panda::JSValueRef::Undefined(vm);
415 }
416 
SetTabBarWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)417 ArkUINativeModuleValue TabsBridge::SetTabBarWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
418 {
419     EcmaVM* vm = runtimeCallInfo->GetVM();
420     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
421     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
422     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
423     Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(1);
424     CalcDimension width;
425     ArkUINativeModuleValue undefinedRes = panda::JSValueRef::Undefined(vm);
426 
427     if (jsValue->IsNull() || jsValue->IsUndefined() || !ArkTSUtils::ParseJsDimensionVpNG(vm, jsValue, width)) {
428         GetArkUIInternalNodeAPI()->GetTabsModifier().ResetTabBarWidth(nativeNode);
429         return undefinedRes;
430     }
431 
432     GetArkUIInternalNodeAPI()->GetTabsModifier().SetTabBarWidth(
433         nativeNode, width.Value(), static_cast<int>(width.Unit()));
434     return undefinedRes;
435 }
436 
ResetTabBarWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)437 ArkUINativeModuleValue TabsBridge::ResetTabBarWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
438 {
439     EcmaVM* vm = runtimeCallInfo->GetVM();
440     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
441     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
442     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
443     GetArkUIInternalNodeAPI()->GetTabsModifier().ResetTabBarWidth(nativeNode);
444     return panda::JSValueRef::Undefined(vm);
445 }
446 
SetTabBarHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)447 ArkUINativeModuleValue TabsBridge::SetTabBarHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
448 {
449     EcmaVM* vm = runtimeCallInfo->GetVM();
450     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
451     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
452     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
453     Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(1);
454     CalcDimension height;
455     ArkUINativeModuleValue undefinedRes = panda::JSValueRef::Undefined(vm);
456 
457     if (jsValue->IsNull() || jsValue->IsUndefined() || !ArkTSUtils::ParseJsDimensionVpNG(vm, jsValue, height)) {
458         GetArkUIInternalNodeAPI()->GetTabsModifier().ResetTabBarHeight(nativeNode);
459         return undefinedRes;
460     }
461 
462     GetArkUIInternalNodeAPI()->GetTabsModifier().SetTabBarHeight(
463         nativeNode, height.Value(), static_cast<int>(height.Unit()));
464     return undefinedRes;
465 }
466 
ResetTabBarHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)467 ArkUINativeModuleValue TabsBridge::ResetTabBarHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
468 {
469     EcmaVM* vm = runtimeCallInfo->GetVM();
470     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
471     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
472     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
473     GetArkUIInternalNodeAPI()->GetTabsModifier().ResetTabBarHeight(nativeNode);
474     return panda::JSValueRef::Undefined(vm);
475 }
476 
SetBarAdaptiveHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)477 ArkUINativeModuleValue TabsBridge::SetBarAdaptiveHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
478 {
479     EcmaVM* vm = runtimeCallInfo->GetVM();
480     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
481     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
482     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
483     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
484     bool value = secondArg->ToBoolean(vm)->Value();
485     GetArkUIInternalNodeAPI()->GetTabsModifier().SetBarAdaptiveHeight(nativeNode, value);
486     return panda::JSValueRef::Undefined(vm);
487 }
488 
ResetBarAdaptiveHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)489 ArkUINativeModuleValue TabsBridge::ResetBarAdaptiveHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
490 {
491     EcmaVM* vm = runtimeCallInfo->GetVM();
492     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
493     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
494     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
495     GetArkUIInternalNodeAPI()->GetTabsModifier().ResetBarAdaptiveHeight(nativeNode);
496     return panda::JSValueRef::Undefined(vm);
497 }
498 
SetAnimationDuration(ArkUIRuntimeCallInfo * runtimeCallInfo)499 ArkUINativeModuleValue TabsBridge::SetAnimationDuration(ArkUIRuntimeCallInfo* runtimeCallInfo)
500 {
501     EcmaVM* vm = runtimeCallInfo->GetVM();
502     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
503     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
504     Local<JSValueRef> durationArg = runtimeCallInfo->GetCallArgRef(1);
505     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
506     if (durationArg->IsNull() || durationArg->IsUndefined()) {
507         GetArkUIInternalNodeAPI()->GetTabsModifier().ResetAnimationDuration(nativeNode);
508         return panda::JSValueRef::Undefined(vm);
509     }
510     float duration = durationArg->ToNumber(vm)->Value();
511     GetArkUIInternalNodeAPI()->GetTabsModifier().SetAnimationDuration(nativeNode, duration);
512     return panda::JSValueRef::Undefined(vm);
513 }
514 
ResetAnimationDuration(ArkUIRuntimeCallInfo * runtimeCallInfo)515 ArkUINativeModuleValue TabsBridge::ResetAnimationDuration(ArkUIRuntimeCallInfo* runtimeCallInfo)
516 {
517     EcmaVM* vm = runtimeCallInfo->GetVM();
518     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
519     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
520     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
521     GetArkUIInternalNodeAPI()->GetTabsModifier().ResetAnimationDuration(nativeNode);
522     return panda::JSValueRef::Undefined(vm);
523 }
524 
SetBarPosition(ArkUIRuntimeCallInfo * runtimeCallInfo)525 ArkUINativeModuleValue TabsBridge::SetBarPosition(ArkUIRuntimeCallInfo* runtimeCallInfo)
526 {
527     EcmaVM* vm = runtimeCallInfo->GetVM();
528     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
529     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
530     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
531     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
532     int32_t barVal = secondArg->ToNumber(vm)->Value();
533     GetArkUIInternalNodeAPI()->GetTabsModifier().SetTabBarPosition(nativeNode, barVal);
534     return panda::JSValueRef::Undefined(vm);
535 }
536 
ResetBarPosition(ArkUIRuntimeCallInfo * runtimeCallInfo)537 ArkUINativeModuleValue TabsBridge::ResetBarPosition(ArkUIRuntimeCallInfo* runtimeCallInfo)
538 {
539     EcmaVM* vm = runtimeCallInfo->GetVM();
540     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
541     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
542     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
543     GetArkUIInternalNodeAPI()->GetTabsModifier().ResetTabBarPosition(nativeNode);
544     return panda::JSValueRef::Undefined(vm);
545 }
546 
SetTabClip(ArkUIRuntimeCallInfo * runtimeCallInfo)547 ArkUINativeModuleValue TabsBridge::SetTabClip(ArkUIRuntimeCallInfo* runtimeCallInfo)
548 {
549     EcmaVM* vm = runtimeCallInfo->GetVM();
550     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
551     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
552     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
553     auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
554 
555     Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
556     if (info[TABS_ARG_INDEX_1]->IsUndefined()) {
557         ViewAbstract::SetClipEdge(frameNode, false);
558         return panda::JSValueRef::Undefined(vm);
559     }
560     if (info[TABS_ARG_INDEX_1]->IsObject()) {
561         CommonBridge::SetClip(runtimeCallInfo);
562     } else if (info[TABS_ARG_INDEX_1]->IsBoolean()) {
563         GetArkUIInternalNodeAPI()->GetTabsModifier().SetTabClip(nativeNode, info[TABS_ARG_INDEX_1]->ToBoolean());
564     }
565     return panda::JSValueRef::Undefined(vm);
566 }
567 
ResetTabClip(ArkUIRuntimeCallInfo * runtimeCallInfo)568 ArkUINativeModuleValue TabsBridge::ResetTabClip(ArkUIRuntimeCallInfo* runtimeCallInfo)
569 {
570     EcmaVM* vm = runtimeCallInfo->GetVM();
571     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
572     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
573     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
574     GetArkUIInternalNodeAPI()->GetTabsModifier().ResetTabClip(nativeNode);
575     return panda::JSValueRef::Undefined(vm);
576 }
577 } // namespace OHOS::Ace::NG
578