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 namespace OHOS::Ace {
19 
Update(const RefPtr<Component> & component)20 void RenderStepperItem::Update(const RefPtr<Component>& component)
21 {
22     auto stepperItem = AceType::DynamicCast<StepperItemComponent>(component);
23     if (!stepperItem) {
24         LOGW("stepper item component is null");
25         return;
26     }
27     label_ = stepperItem->GetLabel();
28     auto context = context_.Upgrade();
29     if (!context) {
30         LOGE("context is null");
31         return;
32     }
33     appearEvent_ = AceAsyncEvent<void(const std::string&)>::Create(stepperItem->GetAppearEventId(), context_);
34     disappearEvent_ = AceAsyncEvent<void(const std::string&)>::Create(stepperItem->GetDisappearEventId(), context_);
35     MarkNeedLayout();
36 }
37 
PerformLayout()38 void RenderStepperItem::PerformLayout()
39 {
40     if (!GetChildren().empty()) {
41         auto child = GetChildren().front();
42         child->Layout(GetLayoutParam());
43         auto size = GetLayoutParam().Constrain(Size(child->GetLayoutSize().Width(), child->GetLayoutSize().Height()));
44         SetLayoutSize(size);
45     }
46 }
47 
FireAppearEvent() const48 void RenderStepperItem::FireAppearEvent() const
49 {
50     if (appearEvent_) {
51         std::string param = std::string("\"appear\",null");
52         appearEvent_(param);
53     }
54 }
55 
FireDisappearEvent() const56 void RenderStepperItem::FireDisappearEvent() const
57 {
58     if (disappearEvent_) {
59         std::string param = std::string("\"disappear\",null");
60         disappearEvent_(param);
61     }
62 }
63 
64 } // namespace OHOS::Ace
65