• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WATERFLOW_WATER_FLOW_MODEL_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WATERFLOW_WATER_FLOW_MODEL_H
18 
19 #include <mutex>
20 
21 #include "core/common/resource/resource_object.h"
22 #include "core/components/common/layout/constants.h"
23 #include "core/components/scroll/scroll_controller_base.h"
24 #include "core/components/scroll_bar/scroll_proxy.h"
25 #include "core/components_ng/pattern/scrollable/scrollable_properties.h"
26 #include "core/components_ng/pattern/waterflow/layout/water_flow_layout_algorithm_base.h"
27 #include "core/components_ng/pattern/waterflow/water_flow_sections.h"
28 
29 namespace OHOS::Ace {
30 class WaterFlowModel {
31 public:
32     ACE_FORCE_EXPORT static WaterFlowModel* GetInstance();
33     virtual ~WaterFlowModel() = default;
34 
35     virtual void Create() = 0;
36     virtual void SetFooter(std::function<void()>&& footer) = 0;
37     virtual void SetFooterWithFrameNode(const RefPtr<NG::UINode>& footer) = 0;
38     virtual RefPtr<ScrollControllerBase> CreateScrollController() = 0;
39     virtual RefPtr<ScrollProxy> CreateScrollBarProxy() = 0;
40     virtual void SetScroller(RefPtr<ScrollControllerBase> scroller, RefPtr<ScrollProxy> proxy) = 0;
41     virtual void SetLayoutMode(NG::WaterFlowLayoutMode mode) = 0;
42 
43     virtual void SetColumnsTemplate(const std::string& value) = 0;
44     virtual void SetRowsTemplate(const std::string& value) = 0;
45 
46     // itemConstraintSize
47     virtual void SetItemMinWidth(const Dimension& minWidth) = 0;
48     virtual void SetItemMinHeight(const Dimension& minHeight) = 0;
49     virtual void SetItemMaxWidth(const Dimension& maxWidth) = 0;
50     virtual void SetItemMaxHeight(const Dimension& maxHeight) = 0;
51 
52     virtual void SetColumnsGap(const Dimension& value) = 0;
53     virtual void SetRowsGap(const Dimension& value) = 0;
54 
55     virtual void SetLayoutDirection(FlexDirection value) = 0;
56     virtual void SetNestedScroll(const NestedScrollOptions& nestedOpt) = 0;
57     virtual void SetScrollEnabled(bool scrollEnabled) = 0;
58 
59     virtual void SetOnReachStart(OnReachEvent&& onReachStart) = 0;
60     virtual void SetOnReachEnd(OnReachEvent&& onReachEnd) = 0;
61     virtual void SetOnScrollFrameBegin(OnScrollFrameBeginEvent&& ScrollFrameBegin) = 0;
62     virtual void SetOnScroll(std::function<void(Dimension, ScrollState)>&& onScroll) = 0;
63     virtual void SetOnScrollStart(std::function<void()>&& onScrollStart) = 0;
64     virtual void SetOnScrollStop(std::function<void()>&& onScrollStop) = 0;
65     virtual void SetOnScrollIndex(std::function<void(int32_t, int32_t)>&& onScrollIndex) = 0;
66 
67     virtual void SetFriction(double friction) = 0;
68     virtual void SetCachedCount(int32_t value, bool show = false) = 0;
69 
70     virtual void SetEdgeEffect(EdgeEffect edgeEffect, bool alwaysEnabled, EffectEdge effectEdge = EffectEdge::ALL) = 0;
GetEdgeEffect()71     EdgeEffect GetEdgeEffect() const
72     {
73         return EdgeEffect::NONE;
74     }
GetAlwaysEnableEdgeEffect()75     bool GetAlwaysEnableEdgeEffect() const
76     {
77         return false;
78     }
GetDisplayMode()79     static DisplayMode GetDisplayMode()
80     {
81         return DisplayMode::OFF;
82     }
83     virtual void SetScrollBarMode(DisplayMode value) = 0;
84     virtual void SetScrollBarColor(const std::string& value) = 0;
85     virtual void SetScrollBarWidth(const std::string& value) = 0;
GetOrCreateWaterFlowSections()86     virtual RefPtr<NG::WaterFlowSections> GetOrCreateWaterFlowSections()
87     {
88         return nullptr;
89     }
90 
ResetSections()91     virtual void ResetSections() {}
ParseResObjFriction(const RefPtr<ResourceObject> & resObj)92     virtual void ParseResObjFriction(const RefPtr<ResourceObject>& resObj) {};
93 
SetSyncLoad(bool syncLoad)94     virtual void SetSyncLoad(bool syncLoad) {}
ParseResObjScrollBarColor(const RefPtr<ResourceObject> & resObj)95     virtual void ParseResObjScrollBarColor(const RefPtr<ResourceObject>& resObj) {};
96 
97 private:
98     static std::unique_ptr<WaterFlowModel> instance_;
99     static std::mutex mutex_;
100 };
101 } // namespace OHOS::Ace
102 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WATERFLOW_WATER_FLOW_MODEL_H
103