1 /* 2 * Copyright (c) 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_NG_PATTERNS_TEXT_PICKER_TEXT_PICKER_OVERSCROLL_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_PICKER_TEXT_PICKER_OVERSCROLL_H 18 19 #include "core/components_ng/pattern/pattern.h" 20 #include "core/gestures/velocity_tracker.h" 21 #include "frameworks/base/memory/ace_type.h" 22 23 namespace OHOS::Ace::NG { 24 25 class TextPickerOverscroller final { 26 public: TextPickerOverscroller()27 TextPickerOverscroller() {} 28 29 bool ApplyCurrentOffset(float yLast, float offsetY, float scrollDelta); 30 SetColumn(const WeakPtr<Pattern> & value)31 void SetColumn(const WeakPtr<Pattern>& value) 32 { 33 column_ = value; 34 } 35 SetOverScroll(float overScroll)36 void SetOverScroll(float overScroll) 37 { 38 overScroll_ = overScroll; 39 } 40 GetOverScroll()41 float GetOverScroll() const 42 { 43 return overScroll_; 44 } 45 GetBackScroll()46 float GetBackScroll() const 47 { 48 return backScrollOffset_; 49 } 50 SetStart(float offsetY)51 void SetStart(float offsetY) 52 { 53 overScrollStartOffsetY_ = offsetY; 54 } 55 56 bool InMaxOverScroll() const; 57 bool IsOverScroll() const; 58 bool IsBackOverScroll() const; 59 60 void Reset(); 61 void UpdateTossSpring(float offsetY); 62 bool ShouldStartRebound(); 63 ResetVelocity()64 void ResetVelocity() 65 { 66 velocityTracker_.Reset(); 67 } 68 SetLoopTossOffset(float offset)69 void SetLoopTossOffset(float offset) 70 { 71 loopTossOffset_ = offset; 72 } 73 74 RefPtr<Curve> GetReboundCurve() const; 75 76 private: 77 float GetOverScrollOffset(float yLast, float offsetY) const; 78 bool CanOverScroll(float scrollDelta) const; 79 80 float height_ = 0.0; 81 float overScroll_ = 0.0; 82 float backScrollOffset_ = 0.0; 83 float deltaScrollOffset_ = 0.0; 84 float overScrollStartOffsetY_ = 0.0; 85 float loopTossOffset_ = 0.0; 86 bool isFirstStart_ = false; 87 88 WeakPtr<Pattern> column_; 89 VelocityTracker velocityTracker_; 90 ACE_DISALLOW_COPY_AND_MOVE(TextPickerOverscroller); 91 }; 92 } // namespace OHOS::Ace::NG 93 94 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_PICKER_TEXT_PICKER_OVERSCROLL_H