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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SCROLLABLE_SCROLLABLE_PROPERTIES_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SCROLLABLE_SCROLLABLE_PROPERTIES_H 18 19 #include <functional> 20 #include <optional> 21 22 #include "base/geometry/dimension.h" 23 #include "core/components_ng/base/frame_scene_status.h" 24 25 namespace OHOS::Ace { 26 constexpr float DEFAULT_SCROLL_TO_MASS = 1.0f; 27 constexpr float DEFAULT_SCROLL_TO_STIFFNESS = 227.0f; 28 constexpr float DEFAULT_SCROLL_TO_DAMPING = 33.0f; 29 constexpr float DEFAULT_SCROLL_TO_VELOCITY = 7.0f; 30 // for add item and scrollEdge(Edge.Bottom) in one layout 31 constexpr int32_t LAST_ITEM = -1; 32 33 enum class ScrollState { 34 IDLE = 0, 35 SCROLL, 36 FLING, 37 }; 38 39 enum class NestedScrollMode { 40 SELF_ONLY = 0, 41 SELF_FIRST, 42 PARENT_FIRST, 43 PARALLEL, 44 }; 45 46 enum class ScrollSnapAlign { 47 NONE = 0, 48 START, 49 CENTER, 50 END, 51 }; 52 53 enum class ScrollPagingStatus { 54 // no enablePaging and scrollSnap setting 55 NONE = 0, 56 // scrollSnap has set, enablePaging is not effective 57 INVALID, 58 // enablePaging is effective 59 VALID, 60 }; 61 62 struct ScrollInfo { 63 Dimension dx; 64 Dimension dy; 65 66 bool operator==(const ScrollInfo& scrollInfo) const 67 { 68 return dx == scrollInfo.dx && dy == scrollInfo.dy; 69 } 70 }; 71 72 struct ScrollFrameInfo { 73 Dimension offset; 74 ScrollState state; 75 76 bool operator==(const ScrollFrameInfo& scrollInfo) const 77 { 78 return offset == scrollInfo.offset && state == scrollInfo.state; 79 } 80 }; 81 82 struct ScrollFrameResult { 83 Dimension offset; 84 85 bool operator==(const ScrollFrameResult& scrollRes) const 86 { 87 return offset == scrollRes.offset; 88 } 89 }; 90 91 struct NestedScrollOptions { 92 NestedScrollMode forward; 93 NestedScrollMode backward; 94 NeedParentNestedScrollOptions95 bool NeedParent() const 96 { 97 return forward != NestedScrollMode::SELF_ONLY || backward != NestedScrollMode::SELF_ONLY; 98 } 99 NeedParentNestedScrollOptions100 bool NeedParent(bool forward) const 101 { 102 return forward ? this->forward != NestedScrollMode::SELF_ONLY : backward != NestedScrollMode::SELF_ONLY; 103 } 104 }; 105 106 constexpr int32_t SCROLL_FROM_NONE = 0; 107 constexpr int32_t SCROLL_FROM_UPDATE = 1; 108 constexpr int32_t SCROLL_FROM_ANIMATION = 2; 109 constexpr int32_t SCROLL_FROM_JUMP = 3; 110 constexpr int32_t SCROLL_FROM_ANIMATION_SPRING = 4; 111 constexpr int32_t SCROLL_FROM_CHILD = 5; 112 constexpr int32_t SCROLL_FROM_BAR = 6; 113 constexpr int32_t SCROLL_FROM_FOCUS_JUMP = 7; 114 constexpr int32_t SCROLL_FROM_ROTATE = 8; 115 constexpr int32_t SCROLL_FROM_INDEXER = 9; 116 constexpr int32_t SCROLL_FROM_START = 10; // from drag start 117 constexpr int32_t SCROLL_FROM_AXIS = 11; 118 constexpr int32_t SCROLL_FROM_ANIMATION_CONTROLLER = 12; 119 constexpr int32_t SCROLL_FROM_BAR_FLING = 13; 120 121 // app tail animation 122 constexpr char TRAILING_ANIMATION[] = "TRAILING_ANIMATION"; 123 124 using OnScrollEvent = std::function<void(Dimension, ScrollState)>; 125 using OnScrollBeginEvent = std::function<ScrollInfo(Dimension, Dimension)>; 126 using OnScrollFrameBeginEvent = std::function<ScrollFrameResult(Dimension, ScrollState)>; 127 using OnScrollStartEvent = std::function<void()>; 128 using OnScrollStopEvent = std::function<void()>; 129 using OnReachEvent = std::function<void()>; 130 using OnScrollIndexEvent = std::function<void(int32_t, int32_t, int32_t)>; 131 132 using ScrollPositionCallback = std::function<bool(double, int32_t source)>; 133 using ScrollEndCallback = std::function<void()>; 134 using CalePredictSnapOffsetCallback = 135 std::function<std::optional<float>(float delta, float dragDistance, float velocity)>; 136 using StartScrollSnapMotionCallback = std::function<void(float scrollSnapDelta, float scrollSnapVelocity)>; 137 using ScrollBarFRCallback = std::function<void(double velocity, NG::SceneStatus sceneStatus)>; 138 } // namespace OHOS::Ace 139 140 #endif 141