• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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/models/stepper_item_model_impl.h"
17 
18 #include "bridge/declarative_frontend/view_stack_processor.h"
19 #include "core/components/focus_animation/focus_animation_theme.h"
20 #include "core/components/stepper/stepper_item_component_v2.h"
21 #include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h"
22 #include "frameworks/core/components/stepper/stepper_theme.h"
23 
24 namespace OHOS::Ace::Framework {
25 
Create()26 void StepperItemModelImpl::Create()
27 {
28     std::list<RefPtr<OHOS::Ace::Component>> componentChildren;
29     auto stepperItemComponentV2 = AceType::MakeRefPtr<StepperItemComponentV2>(
30         FlexDirection::ROW, FlexAlign::FLEX_START, FlexAlign::FLEX_START, componentChildren);
31     ViewStackProcessor::GetInstance()->Push(stepperItemComponentV2);
32 
33     RefPtr<StepperItemComponent> stepperItemComponent = ViewStackProcessor::GetInstance()->GetStepperItemComponent();
34     RefPtr<StepperTheme> stepperTheme = JSViewAbstract::GetTheme<StepperTheme>();
35     if (stepperTheme) {
36         TextStyle textStyle_ = stepperTheme->GetTextStyle();
37         textStyle_.SetAdaptTextSize(stepperTheme->GetTextStyle().GetFontSize(), stepperTheme->GetMinFontSize());
38         textStyle_.SetMaxLines(stepperTheme->GetTextMaxLines());
39         textStyle_.SetTextOverflow(TextOverflow::ELLIPSIS);
40         stepperItemComponent->SetTextStyle(textStyle_);
41     }
42     auto focusAnimationTheme = JSViewAbstract::GetTheme<FocusAnimationTheme>();
43     if (focusAnimationTheme) {
44         stepperItemComponent->SetFocusAnimationColor(focusAnimationTheme->GetColor());
45     }
46     ViewStackProcessor::GetInstance()->GetStepperDisplayComponent();
47     ViewStackProcessor::GetInstance()->GetStepperScrollComponent();
48 }
49 
SetPrevLabel(const std::string & leftLabel)50 void StepperItemModelImpl::SetPrevLabel(const std::string& leftLabel)
51 {
52     RefPtr<StepperItemComponent> stepperItem = ViewStackProcessor::GetInstance()->GetStepperItemComponent();
53     if (!stepperItem) {
54         LOGE("StepperItemComponent.");
55         return;
56     }
57     StepperLabels label = stepperItem->GetLabel();
58     label.leftLabel = leftLabel;
59     stepperItem->SetLabel(label);
60 }
61 
SetNextLabel(const std::string & rightLabel)62 void StepperItemModelImpl::SetNextLabel(const std::string& rightLabel)
63 {
64     RefPtr<StepperItemComponent> stepperItem = ViewStackProcessor::GetInstance()->GetStepperItemComponent();
65     if (!stepperItem) {
66         LOGE("StepperItemComponent.");
67         return;
68     }
69     StepperLabels label = stepperItem->GetLabel();
70     label.rightLabel = rightLabel;
71     stepperItem->SetLabel(label);
72 }
73 
SetStatus(const std::string & labelStatus)74 void StepperItemModelImpl::SetStatus(const std::string& labelStatus)
75 {
76     RefPtr<StepperItemComponent> stepperItem = ViewStackProcessor::GetInstance()->GetStepperItemComponent();
77     if (!stepperItem) {
78         LOGE("StepperItemComponent is NULL");
79         return;
80     }
81     StepperLabels label = stepperItem->GetLabel();
82     label.initialStatus = labelStatus;
83     stepperItem->SetLabel(label);
84 }
85 
86 } // namespace OHOS::Ace::Framework