• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLL_SCROLL_MODEL_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLL_SCROLL_MODEL_H
18 
19 #include <memory>
20 #include <mutex>
21 
22 #include "core/components/common/layout/constants.h"
23 #include "core/components/scroll_bar/scroll_proxy.h"
24 #include "core/components_ng/pattern/scroll/scroll_event_hub.h"
25 
26 namespace OHOS::Ace {
27 
28 class ScrollBarTheme;
29 class ScrollControllerBase;
30 
31 class ScrollModel {
32 public:
33     static ScrollModel* GetInstance();
34     virtual ~ScrollModel() = default;
35 
36     virtual void Create() = 0;
37     virtual RefPtr<ScrollControllerBase> GetOrCreateController() = 0;
38     virtual RefPtr<ScrollProxy> CreateScrollBarProxy() = 0;
39     virtual void SetAxis(Axis axis) = 0;
40     virtual void SetOnScrollBegin(OnScrollBeginEvent&& event) = 0;
41     virtual void SetOnScrollFrameBegin(OnScrollFrameBeginEvent&& event) = 0;
42     virtual void SetOnScroll(NG::ScrollEvent&& event) = 0;
43     virtual void SetOnScrollEdge(NG::ScrollEdgeEvent&& event) = 0;
44     virtual void SetOnScrollEnd(NG::ScrollEndEvent&& event) = 0;
45     virtual void SetOnScrollStart(OnScrollStartEvent&& event) = 0;
46     virtual void SetOnScrollStop(OnScrollStopEvent&& event) = 0;
47     virtual void SetScrollBarProxy(const RefPtr<ScrollProxy>& proxy) = 0;
48     virtual void InitScrollBar(const RefPtr<ScrollBarTheme>& theme, const std::pair<bool, Color>& color,
49         const std::pair<bool, Dimension>& width, EdgeEffect effect) = 0;
50     virtual void SetDisplayMode(int displayMode) = 0;
51     virtual void SetScrollBarWidth(const Dimension& dimension) = 0;
52     virtual void SetScrollBarColor(const Color& color) = 0;
53     virtual void SetEdgeEffect(EdgeEffect edgeEffect) = 0;
54     virtual void SetHasWidth(bool hasWidth) = 0;
55     virtual void SetHasHeight(bool hasHeight) = 0;
56     virtual void SetNestedScroll(const NestedScrollOptions& nestedOpt) = 0;
57     virtual void SetScrollEnabled(bool scrollEnabled) = 0;
58     virtual void SetFriction(double friction) = 0;
59     virtual void SetScrollSnap(ScrollSnapAlign scrollSnapAlign, const Dimension& intervalSize,
60         const std::vector<Dimension>& snapPaginations, const std::pair<bool, bool>& enableSnapToSide) = 0;
61 
62 private:
63     static std::unique_ptr<ScrollModel> instance_;
64     static std::mutex mutex_;
65 };
66 
67 } // namespace OHOS::Ace
68 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLL_SCROLL_MODEL_H
69