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 "core/components_v2/water_flow/water_flow_component.h"
17 
18 #include "core/components_v2/water_flow/render_water_flow.h"
19 #include "core/components_v2/water_flow/water_flow_element.h"
20 
21 namespace OHOS::Ace::V2 {
CreateElement()22 RefPtr<Element> WaterFlowComponent::CreateElement()
23 {
24     return AceType::MakeRefPtr<WaterFlowElement>();
25 }
26 
CreateRenderNode()27 RefPtr<RenderNode> WaterFlowComponent::CreateRenderNode()
28 {
29     return RenderWaterFlow::Create();
30 }
31 
SetColumnsGap(const Dimension & columnsGap)32 void WaterFlowComponent::SetColumnsGap(const Dimension& columnsGap)
33 {
34     if (LessNotEqual(columnsGap.Value(), 0.0)) {
35         LOGW("Invalid RowGap, use 0.0px");
36         columnsGap_ = 0.0_px;
37         return;
38     }
39     columnsGap_ = columnsGap;
40 }
41 
SetRowsGap(const Dimension & rowsGap)42 void WaterFlowComponent::SetRowsGap(const Dimension& rowsGap)
43 {
44     if (LessNotEqual(rowsGap.Value(), 0.0)) {
45         LOGW("Invalid RowGap, use 0.0px");
46         rowsGap_ = 0.0_px;
47         return;
48     }
49     rowsGap_ = rowsGap;
50 }
51 
SetLayoutDirection(FlexDirection direction)52 void WaterFlowComponent::SetLayoutDirection(FlexDirection direction)
53 {
54     if (direction < FlexDirection::ROW || direction > FlexDirection::COLUMN_REVERSE) {
55         LOGW("Invalid direction %{public}d", direction);
56         return;
57     }
58     direction_ = direction;
59 }
60 
SetController(const RefPtr<V2::WaterFlowPositionController> & controller)61 void WaterFlowComponent::SetController(const RefPtr<V2::WaterFlowPositionController>& controller)
62 {
63     controller_ = controller;
64 }
65 
SetScrollBarProxy(const RefPtr<ScrollBarProxy> & scrollBarProxy)66 void WaterFlowComponent::SetScrollBarProxy(const RefPtr<ScrollBarProxy>& scrollBarProxy)
67 {
68     scrollBarProxy_ = scrollBarProxy;
69 }
70 
SetScrolledEvent(const EventMarker & event)71 void WaterFlowComponent::SetScrolledEvent(const EventMarker& event)
72 {
73     scrolledEvent_ = event;
74 }
75 
SetScrollBarDisplayMode(DisplayMode displayMode)76 void WaterFlowComponent::SetScrollBarDisplayMode(DisplayMode displayMode)
77 {
78     displayMode_ = displayMode;
79 }
80 
SetColumnsArgs(const std::string & columnsArgs)81 void WaterFlowComponent::SetColumnsArgs(const std::string& columnsArgs)
82 {
83     columnsArgs_ = columnsArgs;
84 }
85 
SetRowsArgs(const std::string & rowsArgs)86 void WaterFlowComponent::SetRowsArgs(const std::string& rowsArgs)
87 {
88     rowsArgs_ = rowsArgs;
89 }
90 
SetMinWidth(const Dimension & minWidth)91 void WaterFlowComponent::SetMinWidth(const Dimension& minWidth)
92 {
93     if (LessNotEqual(minWidth.Value(), 0.0)) {
94         LOGW("Invalid minWidth, use 0.0px");
95         minWidth_ = 0.0_px;
96         return;
97     }
98     minWidth_ = minWidth;
99 }
100 
SetMinHeight(const Dimension & minHeight)101 void WaterFlowComponent::SetMinHeight(const Dimension& minHeight)
102 {
103     if (LessNotEqual(minHeight.Value(), 0.0)) {
104         LOGW("Invalid minHeight, use 0.0px");
105         minHeight_ = 0.0_px;
106         return;
107     }
108     minHeight_ = minHeight;
109 }
110 
SetMaxWidth(const Dimension & maxWidth)111 void WaterFlowComponent::SetMaxWidth(const Dimension& maxWidth)
112 {
113     if (LessNotEqual(maxWidth.Value(), 0.0)) {
114         LOGW("Invalid maxWidth, use 0.0px");
115         maxWidth_ = 0.0_px;
116         return;
117     }
118     maxWidth_ = maxWidth;
119 }
120 
SetMaxHeight(const Dimension & maxHeight)121 void WaterFlowComponent::SetMaxHeight(const Dimension& maxHeight)
122 {
123     if (LessNotEqual(maxHeight.Value(), 0.0)) {
124         LOGW("Invalid maxHeight, use 0.0px");
125         maxHeight_ = 0.0_px;
126         return;
127     }
128     maxHeight_ = maxHeight;
129 }
130 
SetFooterComponent(RefPtr<Component> component)131 void WaterFlowComponent::SetFooterComponent(RefPtr<Component> component)
132 {
133     footerComponent_ = std::move(component);
134 }
135 } // namespace OHOS::Ace::V2
136