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 24 namespace OHOS::Ace { 25 constexpr float DEFAULT_SCROLL_TO_MASS = 1.0f; 26 constexpr float DEFAULT_SCROLL_TO_STIFFNESS = 227.0f; 27 constexpr float DEFAULT_SCROLL_TO_DAMPING = 33.0f; 28 constexpr float DEFAULT_SCROLL_TO_VELOCITY = 7.0f; 29 30 enum class ScrollState { 31 IDLE = 0, 32 SCROLL, 33 FLING, 34 }; 35 36 enum class NestedScrollMode { 37 SELF_ONLY = 0, 38 SELF_FIRST, 39 PARENT_FIRST, 40 PARALLEL, 41 }; 42 43 enum class ScrollSnapAlign { 44 NONE = 0, 45 START, 46 CENTER, 47 END, 48 }; 49 50 struct ScrollInfo { 51 Dimension dx; 52 Dimension dy; 53 54 bool operator==(const ScrollInfo& scrollInfo) const 55 { 56 return dx == scrollInfo.dx && dy == scrollInfo.dy; 57 } 58 }; 59 60 struct ScrollFrameInfo { 61 Dimension offset; 62 ScrollState state; 63 64 bool operator==(const ScrollFrameInfo& scrollInfo) const 65 { 66 return offset == scrollInfo.offset && state == scrollInfo.state; 67 } 68 }; 69 70 struct ScrollFrameResult { 71 Dimension offset; 72 73 bool operator==(const ScrollFrameResult& scrollRes) const 74 { 75 return offset == scrollRes.offset; 76 } 77 }; 78 79 struct NestedScrollOptions { 80 NestedScrollMode forward; 81 NestedScrollMode backward; 82 NeedParentNestedScrollOptions83 bool NeedParent() const 84 { 85 return forward != NestedScrollMode::SELF_ONLY || backward != NestedScrollMode::SELF_ONLY; 86 } 87 }; 88 89 constexpr int32_t SCROLL_FROM_NONE = 0; 90 constexpr int32_t SCROLL_FROM_UPDATE = 1; 91 constexpr int32_t SCROLL_FROM_ANIMATION = 2; 92 constexpr int32_t SCROLL_FROM_JUMP = 3; 93 constexpr int32_t SCROLL_FROM_ANIMATION_SPRING = 4; 94 constexpr int32_t SCROLL_FROM_CHILD = 5; 95 constexpr int32_t SCROLL_FROM_BAR = 6; 96 constexpr int32_t SCROLL_FROM_FOCUS_JUMP = 7; 97 constexpr int32_t SCROLL_FROM_ROTATE = 8; 98 constexpr int32_t SCROLL_FROM_INDEXER = 9; 99 constexpr int32_t SCROLL_FROM_START = 10; // from drag start 100 constexpr int32_t SCROLL_FROM_AXIS = 11; 101 constexpr int32_t SCROLL_FROM_ANIMATION_CONTROLLER = 12; 102 constexpr int32_t SCROLL_FROM_BAR_FLING = 13; 103 104 using OnScrollEvent = std::function<void(Dimension, ScrollState)>; 105 using OnScrollBeginEvent = std::function<ScrollInfo(Dimension, Dimension)>; 106 using OnScrollFrameBeginEvent = std::function<ScrollFrameResult(Dimension, ScrollState)>; 107 using OnScrollStartEvent = std::function<void()>; 108 using OnScrollStopEvent = std::function<void()>; 109 using OnReachEvent = std::function<void()>; 110 using OnScrollIndexEvent = std::function<void(int32_t, int32_t, int32_t)>; 111 112 using ScrollPositionCallback = std::function<bool(double, int32_t source)>; 113 using ScrollEndCallback = std::function<void()>; 114 using CalePredictSnapOffsetCallback = std::function<std::optional<float>(float delta)>; 115 using StartScrollSnapMotionCallback = std::function<void(float scrollSnapDelta, float scrollSnapVelocity)>; 116 } // namespace OHOS::Ace 117 118 #endif 119