1 /* 2 * Copyright (c) 2021-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_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/event/ace_events.h" 27 28 namespace OHOS::Ace { 29 30 constexpr uint32_t POSITION_MIDDLE = 0; 31 constexpr uint32_t POSITION_TOP = 1 << 0; 32 constexpr uint32_t POSITION_BOTTOM = 1 << 1; 33 34 enum class ScrollEvent : size_t { 35 SCROLL_TOP = 0, 36 SCROLL_BOTTOM, 37 SCROLL_TOUCHUP, 38 SCROLL_END, 39 SCROLL_POSITION, 40 SCROLL_EDGE, 41 SCROLL_LEFT, 42 SCROLL_RIGHT, 43 UNKNOWN, 44 }; 45 46 enum class ScrollEdgeType : size_t { 47 SCROLL_TOP = 0, 48 SCROLL_BOTTOM, 49 SCROLL_LEFT, 50 SCROLL_RIGHT, 51 SCROLL_NONE, 52 }; 53 54 enum class ScrollAlign { 55 START = 0, 56 CENTER, 57 END, 58 AUTO, 59 NONE, 60 }; 61 62 using OnFinishFunc = std::function<void()>; 63 class ACE_EXPORT ScrollControllerBase : public AceType { 64 DECLARE_ACE_TYPE(ScrollControllerBase, AceType); 65 66 public: 67 ScrollControllerBase() = default; 68 ~ScrollControllerBase() override = default; 69 70 virtual void JumpTo(int32_t index, bool smooth = false, ScrollAlign align = ScrollAlign::NONE, 71 int32_t source = 3) {} 72 73 virtual void JumpToItemInGroup(int32_t index, int32_t indexInGroup, bool smooth = false, 74 ScrollAlign align = ScrollAlign::NONE, int32_t source = 3) {} // 3 is SCROLL_FROM_JUMP 75 GetScrollDirection()76 virtual Axis GetScrollDirection() const 77 { 78 return Axis::NONE; 79 } 80 81 virtual bool AnimateTo( 82 const Dimension& position, float duration, const RefPtr<Curve>& curve, bool smooth, bool canOverScroll = false) 83 { 84 return true; 85 } ScrollBy(double pixelX,double pixelY,bool smooth)86 virtual void ScrollBy(double pixelX, double pixelY, bool smooth) {} ScrollToEdge(ScrollEdgeType scrollEdgeType,bool smooth)87 virtual void ScrollToEdge(ScrollEdgeType scrollEdgeType, bool smooth) {} ScrollPage(bool reverse,bool smooth)88 virtual void ScrollPage(bool reverse, bool smooth) {} GetCurrentOffset()89 virtual Offset GetCurrentOffset() const 90 { 91 return Offset(); 92 } IsAtEnd()93 virtual bool IsAtEnd() const 94 { 95 return true; 96 } GetItemRect(int32_t index)97 virtual Rect GetItemRect(int32_t index) const 98 { 99 return Rect(); 100 } GetItemRectInGroup(int32_t index,int32_t indexInGroup)101 virtual Rect GetItemRectInGroup(int32_t index, int32_t indexInGroup) const 102 { 103 return Rect(); 104 } CloseAllSwipeActions(OnFinishFunc && onFinishCallback)105 virtual void CloseAllSwipeActions(OnFinishFunc&& onFinishCallback) {} 106 }; 107 } // namespace OHOS::Ace 108 109 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SCROLL_SCROLL_CONTROLLER_BASE_H 110