• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "core/components/stepper/render_stepper_item.h"
17 
18 #include "core/components/stepper/stepper_item_component.h"
19 #include "core/event/ace_event_helper.h"
20 
21 namespace OHOS::Ace {
22 
Update(const RefPtr<Component> & component)23 void RenderStepperItem::Update(const RefPtr<Component>& component)
24 {
25     auto stepperItem = AceType::DynamicCast<StepperItemComponent>(component);
26     if (!stepperItem) {
27         LOGW("stepper item component is null");
28         return;
29     }
30     label_ = stepperItem->GetLabel();
31     auto context = context_.Upgrade();
32     if (!context) {
33         LOGE("context is null");
34         return;
35     }
36     appearEvent_ = AceAsyncEvent<void(const std::string&)>::Create(stepperItem->GetAppearEventId(), context_);
37     disappearEvent_ = AceAsyncEvent<void(const std::string&)>::Create(stepperItem->GetDisappearEventId(), context_);
38     MarkNeedLayout();
39 }
40 
PerformLayout()41 void RenderStepperItem::PerformLayout()
42 {
43     if (!GetChildren().empty()) {
44         auto child = GetChildren().front();
45         child->Layout(GetLayoutParam());
46         auto size = GetLayoutParam().Constrain(Size(child->GetLayoutSize().Width(), child->GetLayoutSize().Height()));
47         SetLayoutSize(size);
48     }
49 }
50 
FireAppearEvent() const51 void RenderStepperItem::FireAppearEvent() const
52 {
53     if (appearEvent_) {
54         std::string param = std::string("\"appear\",null");
55         appearEvent_(param);
56     }
57 }
58 
FireDisappearEvent() const59 void RenderStepperItem::FireDisappearEvent() const
60 {
61     if (disappearEvent_) {
62         std::string param = std::string("\"disappear\",null");
63         disappearEvent_(param);
64     }
65 }
66 
67 } // namespace OHOS::Ace
68