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