• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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_SCROLL_SCROLL_CONTROLLER_BASE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SCROLL_SCROLL_CONTROLLER_BASE_H
18 
19 #include "base/geometry/axis.h"
20 #include "base/geometry/dimension.h"
21 #include "base/geometry/offset.h"
22 #include "base/geometry/rect.h"
23 #include "base/memory/ace_type.h"
24 #include "core/animation/curve.h"
25 #include "core/components/common/layout/constants.h"
26 #include "core/components_ng/pattern/scrollable/scrollable_properties.h"
27 #include "core/event/ace_events.h"
28 
29 namespace OHOS::Ace {
30 
31 constexpr uint32_t POSITION_MIDDLE = 0;
32 constexpr uint32_t POSITION_TOP = 1 << 0;
33 constexpr uint32_t POSITION_BOTTOM = 1 << 1;
34 
35 enum class ScrollEvent : size_t {
36     SCROLL_TOP = 0,
37     SCROLL_BOTTOM,
38     SCROLL_TOUCHUP,
39     SCROLL_END,
40     SCROLL_POSITION,
41     SCROLL_EDGE,
42     SCROLL_LEFT,
43     SCROLL_RIGHT,
44     UNKNOWN,
45 };
46 
47 enum class ScrollEdgeType : size_t {
48     SCROLL_TOP = 0,
49     SCROLL_BOTTOM,
50     SCROLL_LEFT,
51     SCROLL_RIGHT,
52     SCROLL_NONE,
53 };
54 
55 enum class ScrollAlign {
56     START = 0,
57     CENTER,
58     END,
59     AUTO,
60     NONE,
61 };
62 
63 using OnFinishFunc = std::function<void()>;
64 class ACE_EXPORT ScrollControllerBase : public AceType {
65     DECLARE_ACE_TYPE(ScrollControllerBase, AceType);
66 
67 public:
68     ScrollControllerBase() = default;
69     ~ScrollControllerBase() override = default;
70 
71     virtual void ScrollToIndex(int32_t index, bool smooth = false, ScrollAlign align = ScrollAlign::NONE,
72         std::optional<float> extraOffset = std::nullopt)
73     {}
74 
75     virtual void JumpToItemInGroup(int32_t index, int32_t indexInGroup, bool smooth = false,
76         ScrollAlign align = ScrollAlign::NONE, int32_t source = 3) {} // 3 is SCROLL_FROM_JUMP
77 
GetScrollDirection()78     virtual Axis GetScrollDirection() const
79     {
80         return Axis::NONE;
81     }
82 
83     virtual bool AnimateTo(
84         const Dimension& position, float duration, const RefPtr<Curve>& curve, bool smooth, bool canOverScroll = false)
85     {
86         return true;
87     }
ScrollBy(double pixelX,double pixelY,bool smooth)88     virtual void ScrollBy(double pixelX, double pixelY, bool smooth) {}
ScrollToEdge(ScrollEdgeType scrollEdgeType,float velocity)89     virtual void ScrollToEdge(ScrollEdgeType scrollEdgeType, float velocity) {}
ScrollToEdge(ScrollEdgeType scrollEdgeType,bool smooth)90     virtual void ScrollToEdge(ScrollEdgeType scrollEdgeType, bool smooth) {}
Fling(double flingVelocity)91     virtual void Fling(double flingVelocity) {}
ScrollPage(bool reverse,bool smooth)92     virtual void ScrollPage(bool reverse, bool smooth) {}
GetCurrentOffset()93     virtual Offset GetCurrentOffset() const
94     {
95         return Offset();
96     }
IsAtEnd()97     virtual bool IsAtEnd() const
98     {
99         return true;
100     }
GetItemRect(int32_t index)101     virtual Rect GetItemRect(int32_t index) const
102     {
103         return Rect();
104     }
GetItemRectInGroup(int32_t index,int32_t indexInGroup)105     virtual Rect GetItemRectInGroup(int32_t index, int32_t indexInGroup) const
106     {
107         return Rect();
108     }
CloseAllSwipeActions(OnFinishFunc && onFinishCallback)109     virtual void CloseAllSwipeActions(OnFinishFunc&& onFinishCallback) {}
110 
SetObserver(const ScrollerObserver & observer)111     virtual void SetObserver(const ScrollerObserver& observer) {}
112 };
113 } // namespace OHOS::Ace
114 
115 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SCROLL_SCROLL_CONTROLLER_BASE_H
116