1 /*
2 * Copyright (c) 2023 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/water_flow_model_impl.h"
17
18 #include "bridge/declarative_frontend/jsview/js_view_common_def.h"
19 #include "core/components_v2/water_flow/water_flow_component.h"
20
21 namespace OHOS::Ace::Framework {
Create()22 void WaterFlowModelImpl::Create()
23 {
24 std::list<RefPtr<Component>> componentChildren;
25 auto waterflowComponent = AceType::MakeRefPtr<V2::WaterFlowComponent>(componentChildren);
26 CHECK_NULL_VOID(waterflowComponent);
27 ViewStackProcessor::GetInstance()->Push(waterflowComponent);
28 }
29
SetFooter(std::function<void ()> && footer)30 void WaterFlowModelImpl::SetFooter(std::function<void()>&& footer)
31 {
32 if (footer) {
33 auto waterflowComponent =
34 AceType::DynamicCast<V2::WaterFlowComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
35 CHECK_NULL_VOID(waterflowComponent);
36 ScopedViewStackProcessor builderViewStackProcessor;
37 footer();
38 RefPtr<Component> customComponent = ViewStackProcessor::GetInstance()->Finish();
39 waterflowComponent->SetFooterComponent(customComponent);
40 }
41 }
42
CreateScrollController()43 RefPtr<ScrollControllerBase> WaterFlowModelImpl::CreateScrollController()
44 {
45 return AceType::MakeRefPtr<V2::WaterFlowPositionController>();
46 }
47
CreateScrollBarProxy()48 RefPtr<ScrollProxy> WaterFlowModelImpl::CreateScrollBarProxy()
49 {
50 return AceType::MakeRefPtr<ScrollBarProxy>();
51 }
52
SetScroller(RefPtr<ScrollControllerBase> scroller,RefPtr<ScrollProxy> proxy)53 void WaterFlowModelImpl::SetScroller(RefPtr<ScrollControllerBase> scroller, RefPtr<ScrollProxy> proxy)
54 {
55 auto waterflowScroller = AceType::DynamicCast<V2::WaterFlowPositionController>(scroller);
56 JSViewSetProperty(&V2::WaterFlowComponent::SetController, waterflowScroller);
57 auto scrollBarProxy = AceType::DynamicCast<ScrollBarProxy>(proxy);
58 JSViewSetProperty(&V2::WaterFlowComponent::SetScrollBarProxy, scrollBarProxy);
59 }
60
SetColumnsTemplate(const std::string & value)61 void WaterFlowModelImpl::SetColumnsTemplate(const std::string& value)
62 {
63 JSViewSetProperty(&V2::WaterFlowComponent::SetColumnsArgs, value);
64 }
65
SetRowsTemplate(const std::string & value)66 void WaterFlowModelImpl::SetRowsTemplate(const std::string& value)
67 {
68 JSViewSetProperty(&V2::WaterFlowComponent::SetRowsArgs, value);
69 }
70
SetItemMinWidth(const Dimension & minWidth)71 void WaterFlowModelImpl::SetItemMinWidth(const Dimension& minWidth)
72 {
73 JSViewSetProperty(&V2::WaterFlowComponent::SetMinWidth, minWidth);
74 }
75
SetItemMinHeight(const Dimension & minHeight)76 void WaterFlowModelImpl::SetItemMinHeight(const Dimension& minHeight)
77 {
78 JSViewSetProperty(&V2::WaterFlowComponent::SetMinHeight, minHeight);
79 }
80
SetItemMaxWidth(const Dimension & maxWidth)81 void WaterFlowModelImpl::SetItemMaxWidth(const Dimension& maxWidth)
82 {
83 JSViewSetProperty(&V2::WaterFlowComponent::SetMaxWidth, maxWidth);
84 }
85
SetItemMaxHeight(const Dimension & maxHeight)86 void WaterFlowModelImpl::SetItemMaxHeight(const Dimension& maxHeight)
87 {
88 JSViewSetProperty(&V2::WaterFlowComponent::SetMaxHeight, maxHeight);
89 }
90
SetColumnsGap(const Dimension & value)91 void WaterFlowModelImpl::SetColumnsGap(const Dimension& value)
92 {
93 JSViewSetProperty(&V2::WaterFlowComponent::SetColumnsGap, value);
94 }
95
SetRowsGap(const Dimension & value)96 void WaterFlowModelImpl::SetRowsGap(const Dimension& value)
97 {
98 JSViewSetProperty(&V2::WaterFlowComponent::SetRowsGap, value);
99 }
100
SetLayoutDirection(FlexDirection value)101 void WaterFlowModelImpl::SetLayoutDirection(FlexDirection value)
102 {
103 JSViewSetProperty(&V2::WaterFlowComponent::SetLayoutDirection, value);
104 }
105
SetOnReachStart(OnReachEvent && onReachStart)106 void WaterFlowModelImpl::SetOnReachStart(OnReachEvent&& onReachStart)
107 {
108 JSViewSetProperty(&V2::WaterFlowComponent::SetOnReachStart, std::move(onReachStart));
109 }
110
SetOnReachEnd(OnReachEvent && onReachEnd)111 void WaterFlowModelImpl::SetOnReachEnd(OnReachEvent&& onReachEnd)
112 {
113 JSViewSetProperty(&V2::WaterFlowComponent::SetOnReachEnd, std::move(onReachEnd));
114 }
115 } // namespace OHOS::Ace::Framework