• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
16 #include "bridge/declarative_frontend/jsview/js_select.h"
17 
18 #include <string>
19 #include <vector>
20 
21 #include "bridge/declarative_frontend/jsview/js_interactable_view.h"
22 
23 #include "core/components/option/option_component.h"
24 #include "core/components/select/select_component.h"
25 #include "frameworks/bridge/common/utils/utils.h"
26 #include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h"
27 #include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h"
28 
29 namespace OHOS::Ace::Framework {
Create(const JSCallbackInfo & info)30 void JSSelect::Create(const JSCallbackInfo& info)
31 {
32     if (info.Length() < 0) {
33         return;
34     }
35 
36     auto selectTheme = GetTheme<SelectTheme>();
37     auto selectComponent = AceType::MakeRefPtr<SelectComponent>();
38     selectComponent->SetTheme(selectTheme);
39 
40     auto tipText = AceType::MakeRefPtr<TextComponent>("");
41     selectComponent->SetTipText(tipText);
42 
43     if (info[0]->IsArray()) {
44         auto paramArray = JSRef<JSArray>::Cast(info[0]);
45         size_t size = paramArray->Length();
46         for (size_t i = 0; i < size; i++) {
47             std::string value;
48             std::string icon;
49 
50             auto indexObject = JSRef<JSObject>::Cast(paramArray->GetValueAt(i));
51             auto selectValue = indexObject->GetProperty("value");
52             auto selectIcon = indexObject->GetProperty("icon");
53             if (!ParseJsString(selectValue, value)) {
54                 LOGE("selectValue is null");
55                 return;
56             }
57             if (!ParseJsMedia(selectIcon, icon)) {
58                 LOGE("selectValue is null");
59             }
60 
61             auto optionTheme = GetTheme<SelectTheme>();
62             auto optionComponent = AceType::MakeRefPtr<OHOS::Ace::OptionComponent>(optionTheme);
63             auto textComponent = AceType::MakeRefPtr<OHOS::Ace::TextComponent>(value);
64             auto iconComponent = AceType::MakeRefPtr<OHOS::Ace::ImageComponent>(icon);
65             optionComponent->SetTheme(optionTheme);
66             optionComponent->SetText(textComponent);
67             optionComponent->SetIcon(iconComponent);
68             optionComponent->SetTextStyle(optionTheme->GetTitleStyle());
69             optionComponent->SetSelectedTextStyle(optionTheme->GetTitleStyle());
70             optionComponent->SetSelectedBackgroundColor(optionTheme->GetSelectedColor());
71             optionComponent->SetValue(value);
72             selectComponent->AppendSelectOption(optionComponent);
73         }
74     }
75 
76     ViewStackProcessor::GetInstance()->Push(selectComponent);
77 }
78 
JSBind(BindingTarget globalObj)79 void JSSelect::JSBind(BindingTarget globalObj)
80 {
81     JSClass<JSSelect>::Declare("Select");
82     MethodOptions opt = MethodOptions::NONE;
83     JSClass<JSSelect>::StaticMethod("create", &JSSelect::Create, opt);
84 
85     JSClass<JSSelect>::StaticMethod("selected", &JSSelect::Selected, opt);
86     JSClass<JSSelect>::StaticMethod("value", &JSSelect::Value, opt);
87     JSClass<JSSelect>::StaticMethod("font", &JSSelect::Font, opt);
88     JSClass<JSSelect>::StaticMethod("fontColor", &JSSelect::FontColor, opt);
89     JSClass<JSSelect>::StaticMethod("selectedOptionBgColor", &JSSelect::SelectedOptionBgColor, opt);
90     JSClass<JSSelect>::StaticMethod("selectedOptionFont", &JSSelect::SelectedOptionFont, opt);
91     JSClass<JSSelect>::StaticMethod("selectedOptionFontColor", &JSSelect::SelectedOptionFontColor, opt);
92     JSClass<JSSelect>::StaticMethod("optionBgColor", &JSSelect::OptionBgColor, opt);
93     JSClass<JSSelect>::StaticMethod("optionFont", &JSSelect::OptionFont, opt);
94     JSClass<JSSelect>::StaticMethod("optionFontColor", &JSSelect::OptionFontColor, opt);
95     JSClass<JSSelect>::StaticMethod("onSelect", &JSSelect::OnSelected, opt);
96     // API7 onSelected deprecated
97     JSClass<JSSelect>::StaticMethod("onSelected", &JSSelect::OnSelected, opt);
98     JSClass<JSSelect>::StaticMethod("width", &JSSelect::JsWidth);
99     JSClass<JSSelect>::StaticMethod("height", &JSSelect::JsHeight);
100     JSClass<JSSelect>::StaticMethod("size", &JSSelect::JsSize);
101     JSClass<JSSelect>::StaticMethod("padding", &JSSelect::JsPadding);
102     JSClass<JSSelect>::StaticMethod("paddingTop", &JSSelect::SetPaddingTop, opt);
103     JSClass<JSSelect>::StaticMethod("paddingBottom", &JSSelect::SetPaddingBottom, opt);
104     JSClass<JSSelect>::StaticMethod("paddingLeft", &JSSelect::SetPaddingLeft, opt);
105     JSClass<JSSelect>::StaticMethod("paddingRight", &JSSelect::SetPaddingRight, opt);
106 
107     JSClass<JSSelect>::StaticMethod("onClick", &JSInteractableView::JsOnClick);
108     JSClass<JSSelect>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
109     JSClass<JSSelect>::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey);
110     JSClass<JSSelect>::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete);
111     JSClass<JSSelect>::StaticMethod("onAppear", &JSInteractableView::JsOnAppear);
112     JSClass<JSSelect>::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear);
113     JSClass<JSSelect>::Inherit<JSViewAbstract>();
114     JSClass<JSSelect>::Bind(globalObj);
115 }
116 
Selected(int value)117 void JSSelect::Selected(int value)
118 {
119     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
120     auto selectComponent = AceType::DynamicCast<SelectComponent>(component);
121     if (!selectComponent) {
122         LOGE("search component error");
123         return;
124     }
125     auto popup = selectComponent->GetPopup();
126     if (!popup) {
127         LOGE("popup is null");
128         return;
129     }
130     auto option = popup->GetSelectOptions();
131     if (value < 0 || value >= static_cast<int32_t>(option.size())) {
132         LOGE("Input selected index error, use the defalut value");
133         value = 0;
134     }
135 
136     auto tipText = selectComponent->GetTipText();
137     auto optionComponent = selectComponent->GetSelectOption(value);
138     if (!optionComponent) {
139         LOGE("optionComponent is null");
140         return;
141     }
142     optionComponent->SetSelected(true);
143 
144     auto optionText = optionComponent->GetText();
145     if (!optionText) {
146         return;
147     }
148     tipText->SetData(optionText->GetData());
149 }
150 
Value(const std::string & value)151 void JSSelect::Value(const std::string& value)
152 {
153     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
154     auto selectComponent = AceType::DynamicCast<SelectComponent>(component);
155     if (!selectComponent) {
156         LOGE("search component error");
157         return;
158     }
159     auto tipText = selectComponent->GetTipText();
160     tipText->SetData(value);
161 }
162 
Font(const JSCallbackInfo & info)163 void JSSelect::Font(const JSCallbackInfo& info)
164 {
165     if (!info[0]->IsObject()) {
166         return;
167     }
168     auto param = JSRef<JSObject>::Cast(info[0]);
169     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
170     auto selectComponent = AceType::DynamicCast<SelectComponent>(component);
171     if (!selectComponent) {
172         LOGE("search component error");
173         return;
174     }
175 
176     auto size = param->GetProperty("size");
177     TextStyle textStyle = selectComponent->GetSelectStyle();
178     if (!size->IsNull() && size->IsNumber()) {
179         Dimension fontSize;
180         if (ParseJsDimensionFp(size, fontSize)) {
181             textStyle.SetFontSize(fontSize);
182         }
183     }
184 
185     std::string weight;
186     auto fontWeight = param->GetProperty("weight");
187     if (!fontWeight->IsNull()) {
188         if (fontWeight->IsNumber()) {
189             weight = std::to_string(fontWeight->ToNumber<int32_t>());
190         } else {
191             ParseJsString(fontWeight, weight);
192         }
193         textStyle.SetFontWeight(ConvertStrToFontWeight(weight));
194     }
195 
196     auto family = param->GetProperty("family");
197     if (!family->IsNull() && family->IsString()) {
198         auto familyVal = family->ToString();
199         textStyle.SetFontFamilies(ConvertStrToFontFamilies(familyVal));
200     }
201 
202     auto style = param->GetProperty("style");
203     if (!style->IsNull() && style->IsNumber()) {
204         FontStyle styleVal = static_cast<FontStyle>(style->ToNumber<int32_t>());
205         textStyle.SetFontStyle(styleVal);
206     }
207     selectComponent->SetSelectStyle(std::move(textStyle));
208 }
209 
FontColor(const JSCallbackInfo & info)210 void JSSelect::FontColor(const JSCallbackInfo& info)
211 {
212     if (info.Length() < 1) {
213         LOGE("The argv is wrong, it is supposed to have at least 1 argument");
214         return;
215     }
216 
217     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
218     auto selectComponent = AceType::DynamicCast<SelectComponent>(component);
219     if (!selectComponent) {
220         LOGE("search component error");
221         return;
222     }
223 
224     Color textColor;
225     if (!ParseJsColor(info[0], textColor)) {
226         return;
227     }
228     auto textStyle = selectComponent->GetSelectStyle();
229     textStyle.SetTextColor(textColor);
230     selectComponent->SetSelectStyle(std::move(textStyle));
231 }
232 
SelectedOptionBgColor(const JSCallbackInfo & info)233 void JSSelect::SelectedOptionBgColor(const JSCallbackInfo& info)
234 {
235     if (info.Length() < 1) {
236         LOGE("The argv is wrong, it is supposed to have at least 1 argument");
237         return;
238     }
239     Color bgColor;
240     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
241     auto selectComponent = AceType::DynamicCast<SelectComponent>(component);
242     if (!selectComponent) {
243         LOGE("search component error");
244         return;
245     }
246     auto popup = selectComponent->GetPopup();
247     if (!popup) {
248         LOGE("popup is null");
249         return;
250     }
251     auto option = popup->GetSelectOptions();
252     if (!ParseJsColor(info[0], bgColor)) {
253         return;
254     }
255     for (auto& optionItem : option) {
256         if (optionItem) {
257             optionItem->SetSelectedBackgroundColor(bgColor);
258         }
259     }
260 }
261 
SelectedOptionFont(const JSCallbackInfo & info)262 void JSSelect::SelectedOptionFont(const JSCallbackInfo& info)
263 {
264     if (!info[0]->IsObject()) {
265         return;
266     }
267     auto param = JSRef<JSObject>::Cast(info[0]);
268     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
269     auto selectComponent = AceType::DynamicCast<SelectComponent>(component);
270     if (!selectComponent) {
271         LOGE("search component error");
272         return;
273     }
274     auto popup = selectComponent->GetPopup();
275     if (!popup) {
276         LOGE("popup is null");
277         return;
278     }
279     auto option = popup->GetSelectOptions();
280     if (info.Length() < 1) {
281         LOGE("The argv is wrong, it is supposed to have at least 1 argument");
282         return;
283     }
284     for (auto& optionItem : option) {
285         auto size = param->GetProperty("size");
286         TextStyle textStyle = optionItem->GetSelectedTextStyle();
287 
288         if (!size->IsNull() && size->IsNumber()) {
289             Dimension fontSize;
290             if (ParseJsDimensionFp(size, fontSize)) {
291                 textStyle.SetFontSize(fontSize);
292             }
293         }
294 
295         std::string weight;
296         auto fontWeight = param->GetProperty("weight");
297         if (!fontWeight->IsNull()) {
298             if (fontWeight->IsNumber()) {
299                 weight = std::to_string(fontWeight->ToNumber<int32_t>());
300             } else {
301                 ParseJsString(fontWeight, weight);
302             }
303             textStyle.SetFontWeight(ConvertStrToFontWeight(weight));
304         }
305 
306         auto family = param->GetProperty("family");
307         if (!family->IsNull() && family->IsString()) {
308             auto familyVal = family->ToString();
309             textStyle.SetFontFamilies(ConvertStrToFontFamilies(familyVal));
310         }
311 
312         auto style = param->GetProperty("style");
313         if (!style->IsNull() && style->IsNumber()) {
314             FontStyle styleVal = static_cast<FontStyle>(style->ToNumber<int32_t>());
315             textStyle.SetFontStyle(styleVal);
316         }
317 
318         optionItem->SetSelectedTextStyle(std::move(textStyle));
319     }
320 }
321 
SelectedOptionFontColor(const JSCallbackInfo & info)322 void JSSelect::SelectedOptionFontColor(const JSCallbackInfo& info)
323 {
324     if (info.Length() < 1) {
325         LOGE("The argv is wrong, it is supposed to have at least 1 argument");
326         return;
327     }
328     Color textColor;
329     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
330     auto selectComponent = AceType::DynamicCast<SelectComponent>(component);
331     if (!selectComponent) {
332         LOGE("search component error");
333         return;
334     }
335     auto popup = selectComponent->GetPopup();
336     if (!popup) {
337         LOGE("popup is null");
338         return;
339     }
340     auto option = popup->GetSelectOptions();
341     if (!ParseJsColor(info[0], textColor)) {
342         return;
343     }
344     for (auto& optionItem : option) {
345         if (optionItem) {
346             TextStyle textStyle = optionItem->GetSelectedTextStyle();
347             textStyle.SetTextColor(textColor);
348             optionItem->SetSelectedTextStyle(textStyle);
349         }
350     }
351 }
352 
OptionBgColor(const JSCallbackInfo & info)353 void JSSelect::OptionBgColor(const JSCallbackInfo& info)
354 {
355     if (info.Length() < 1) {
356         LOGE("The argv is wrong, it is supposed to have at least 1 argument");
357         return;
358     }
359     Color bgColor;
360     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
361     auto selectComponent = AceType::DynamicCast<SelectComponent>(component);
362     if (!selectComponent) {
363         LOGE("search component error");
364         return;
365     }
366     auto popup = selectComponent->GetPopup();
367     if (!popup) {
368         LOGE("popup is null");
369         return;
370     }
371     auto option = popup->GetSelectOptions();
372     if (!ParseJsColor(info[0], bgColor)) {
373         return;
374     }
375     for (auto& optionItem : option) {
376         if (optionItem) {
377             optionItem->SetBackgroundColor(bgColor);
378         }
379     }
380 }
381 
OptionFont(const JSCallbackInfo & info)382 void JSSelect::OptionFont(const JSCallbackInfo& info)
383 {
384     if (!info[0]->IsObject()) {
385         return;
386     }
387     auto param = JSRef<JSObject>::Cast(info[0]);
388     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
389     auto selectComponent = AceType::DynamicCast<SelectComponent>(component);
390     if (!selectComponent) {
391         LOGE("search component error");
392         return;
393     }
394     auto popup = selectComponent->GetPopup();
395     if (!popup) {
396         LOGE("popup is null");
397         return;
398     }
399     auto option = popup->GetSelectOptions();
400     if (info.Length() < 1) {
401         LOGE("The argv is wrong, it is supposed to have at least 1 argument");
402         return;
403     }
404     for (auto& optionItem : option) {
405         TextStyle textStyle = optionItem->GetTextStyle();
406         auto size = param->GetProperty("size");
407         if (!size->IsNull() && size->IsNumber()) {
408             Dimension fontSize;
409             if (ParseJsDimensionFp(size, fontSize)) {
410                 textStyle.SetFontSize(fontSize);
411             }
412         }
413 
414         std::string weight;
415         auto fontWeight = param->GetProperty("weight");
416         if (!fontWeight->IsNull()) {
417             if (fontWeight->IsNumber()) {
418                 weight = std::to_string(fontWeight->ToNumber<int32_t>());
419             } else {
420                 ParseJsString(fontWeight, weight);
421             }
422             textStyle.SetFontWeight(ConvertStrToFontWeight(weight));
423         }
424 
425         auto family = param->GetProperty("family");
426         if (!family->IsNull() && family->IsString()) {
427             auto familyVal = family->ToString();
428             textStyle.SetFontFamilies(ConvertStrToFontFamilies(familyVal));
429         }
430 
431         auto style = param->GetProperty("style");
432         if (!style->IsNull() && style->IsNumber()) {
433             FontStyle styleVal = static_cast<FontStyle>(style->ToNumber<int32_t>());
434             textStyle.SetFontStyle(styleVal);
435         }
436 
437         optionItem->SetTextStyle(std::move(textStyle));
438     }
439 }
440 
OptionFontColor(const JSCallbackInfo & info)441 void JSSelect::OptionFontColor(const JSCallbackInfo& info)
442 {
443     if (info.Length() < 1) {
444         LOGE("The argv is wrong, it is supposed to have at least 1 argument");
445         return;
446     }
447     Color textColor;
448     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
449     auto selectComponent = AceType::DynamicCast<SelectComponent>(component);
450     if (!selectComponent) {
451         LOGE("search component error");
452         return;
453     }
454     auto popup = selectComponent->GetPopup();
455     if (!popup) {
456         LOGE("popup is null");
457         return;
458     }
459     auto option = popup->GetSelectOptions();
460     if (!ParseJsColor(info[0], textColor)) {
461         return;
462     }
463     for (auto& optionItem : option) {
464         if (optionItem) {
465             TextStyle textStyle = optionItem->GetTextStyle();
466             textStyle.SetTextColor(textColor);
467             optionItem->SetTextStyle(textStyle);
468         }
469     }
470 }
471 
OnSelected(const JSCallbackInfo & info)472 void JSSelect::OnSelected(const JSCallbackInfo& info)
473 {
474     if (!JSViewBindEvent(&SelectComponent::SetOnSelected, info)) {
475         LOGE("Failed to bind event");
476     }
477     info.ReturnSelf();
478 }
479 
JsWidth(const JSCallbackInfo & info)480 void JSSelect::JsWidth(const JSCallbackInfo& info)
481 {
482     if (info.Length() < 1) {
483         LOGE("The arg is wrong, it is supposed to have atleast 1 arguments");
484         return;
485     }
486 
487     Width(info[0]);
488 }
489 
Width(const JSRef<JSVal> & jsValue)490 void JSSelect::Width(const JSRef<JSVal>& jsValue)
491 {
492     Dimension value;
493     if (!ParseJsDimensionVp(jsValue, value)) {
494         return;
495     }
496     auto stack = ViewStackProcessor::GetInstance();
497     auto selectComponent = AceType::DynamicCast<SelectComponent>(stack->GetMainComponent());
498     if (selectComponent) {
499         selectComponent->SetWidth(value);
500     }
501 }
502 
JsHeight(const JSCallbackInfo & info)503 void JSSelect::JsHeight(const JSCallbackInfo& info)
504 {
505     if (info.Length() < 1) {
506         LOGE("The arg is wrong, it is supposed to have atleast 1 arguments");
507         return;
508     }
509 
510     Height(info[0]);
511 }
512 
Height(const JSRef<JSVal> & jsValue)513 void JSSelect::Height(const JSRef<JSVal>& jsValue)
514 {
515     Dimension value;
516     if (!ParseJsDimensionVp(jsValue, value)) {
517         return;
518     }
519     auto stack = ViewStackProcessor::GetInstance();
520     auto selectComponent = AceType::DynamicCast<SelectComponent>(stack->GetMainComponent());
521     if (selectComponent) {
522         selectComponent->SetHeight(value);
523     }
524 }
525 
JsSize(const JSCallbackInfo & info)526 void JSSelect::JsSize(const JSCallbackInfo& info)
527 {
528     if (info.Length() < 1) {
529         LOGE("The arg is wrong, it is supposed to have atleast 1 arguments");
530         return;
531     }
532 
533     if (!info[0]->IsObject()) {
534         LOGE("arg is not Object or String.");
535         return;
536     }
537 
538     JSRef<JSObject> sizeObj = JSRef<JSObject>::Cast(info[0]);
539     Width(sizeObj->GetProperty("width"));
540     Height(sizeObj->GetProperty("height"));
541 }
542 
JsPadding(const JSCallbackInfo & info)543 void JSSelect::JsPadding(const JSCallbackInfo& info)
544 {
545     if (!info[0]->IsString() && !info[0]->IsNumber() && !info[0]->IsObject()) {
546         LOGE("arg is not a string, number or object.");
547         return;
548     }
549 
550     if (info[0]->IsObject()) {
551         auto stack = ViewStackProcessor::GetInstance();
552         auto selectComponent = AceType::DynamicCast<SelectComponent>(stack->GetMainComponent());
553         if (!selectComponent) {
554             LOGE("search component error");
555             return;
556         }
557         auto argsPtrItem = JsonUtil::ParseJsonString(info[0]->ToString());
558         if (!argsPtrItem || argsPtrItem->IsNull()) {
559             LOGE("Js Parse object failed. argsPtr is null. %s", info[0]->ToString().c_str());
560             return;
561         }
562         if (argsPtrItem->Contains("top")) {
563             Dimension topDimen = Dimension(0.0, DimensionUnit::VP);
564             if (ParseJsonDimensionVp(argsPtrItem->GetValue("top"), topDimen)) {
565                 selectComponent->SetTopPadding(topDimen);
566             }
567         }
568         if (argsPtrItem->Contains("left")) {
569             Dimension leftDimen = Dimension(0.0, DimensionUnit::VP);
570             if (ParseJsonDimensionVp(argsPtrItem->GetValue("left"), leftDimen)) {
571                 selectComponent->SetLeftPadding(leftDimen);
572             }
573         }
574         if (argsPtrItem->Contains("right")) {
575             Dimension rightDimen = Dimension(0.0, DimensionUnit::VP);
576             if (ParseJsonDimensionVp(argsPtrItem->GetValue("right"), rightDimen)) {
577                 selectComponent->SetRightPadding(rightDimen);
578             }
579         }
580         if (argsPtrItem->Contains("bottom")) {
581             Dimension bottomDimen = Dimension(0.0, DimensionUnit::VP);
582             if (ParseJsonDimensionVp(argsPtrItem->GetValue("bottom"), bottomDimen)) {
583                 selectComponent->SetBottomPadding(bottomDimen);
584             }
585         }
586     }
587     Dimension length;
588     if (ParseJsDimensionVp(info[0], length)) {
589         auto stack = ViewStackProcessor::GetInstance();
590         auto selectComponent = AceType::DynamicCast<SelectComponent>(stack->GetMainComponent());
591         if (selectComponent) {
592             selectComponent->SetLeftPadding(length);
593             selectComponent->SetTopPadding(length);
594             selectComponent->SetRightPadding(length);
595             selectComponent->SetBottomPadding(length);
596         }
597     }
598 }
599 
SetPaddingLeft(const JSCallbackInfo & info)600 void JSSelect::SetPaddingLeft(const JSCallbackInfo& info)
601 {
602     if (info.Length() < 1) {
603         LOGE("The arg is wrong, it is supposed to have at least 1 argument");
604         return;
605     }
606     Dimension value;
607     if (!ParseJsDimensionVp(info[0], value)) {
608         return;
609     }
610     auto stack = ViewStackProcessor::GetInstance();
611     auto selectComponent = AceType::DynamicCast<SelectComponent>(stack->GetMainComponent());
612     if (selectComponent) {
613         selectComponent->SetLeftPadding(value);
614     }
615 }
616 
SetPaddingTop(const JSCallbackInfo & info)617 void JSSelect::SetPaddingTop(const JSCallbackInfo& info)
618 {
619     if (info.Length() < 1) {
620         LOGE("The arg is wrong, it is supposed to have at least 1 argument");
621         return;
622     }
623     Dimension value;
624     if (!ParseJsDimensionVp(info[0], value)) {
625         return;
626     }
627     auto stack = ViewStackProcessor::GetInstance();
628     auto selectComponent = AceType::DynamicCast<SelectComponent>(stack->GetMainComponent());
629     if (selectComponent) {
630         selectComponent->SetTopPadding(value);
631     }
632 }
633 
SetPaddingRight(const JSCallbackInfo & info)634 void JSSelect::SetPaddingRight(const JSCallbackInfo& info)
635 {
636     if (info.Length() < 1) {
637         LOGE("The arg is wrong, it is supposed to have at least 1 argument");
638         return;
639     }
640     Dimension value;
641     if (!ParseJsDimensionVp(info[0], value)) {
642         return;
643     }
644     auto stack = ViewStackProcessor::GetInstance();
645     auto selectComponent = AceType::DynamicCast<SelectComponent>(stack->GetMainComponent());
646     if (selectComponent) {
647         selectComponent->SetRightPadding(value);
648     }
649 }
650 
SetPaddingBottom(const JSCallbackInfo & info)651 void JSSelect::SetPaddingBottom(const JSCallbackInfo& info)
652 {
653     if (info.Length() < 1) {
654         LOGE("The arg is wrong, it is supposed to have at least 1 argument");
655         return;
656     }
657     Dimension value;
658     if (!ParseJsDimensionVp(info[0], value)) {
659         return;
660     }
661     auto stack = ViewStackProcessor::GetInstance();
662     auto selectComponent = AceType::DynamicCast<SelectComponent>(stack->GetMainComponent());
663     if (selectComponent) {
664         selectComponent->SetBottomPadding(value);
665     }
666 }
667 } // namespace OHOS::Ace::Framework
668