• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SCROLLABLE_AXIS_AXIS_SCROLL_ANIMATOR_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SCROLLABLE_AXIS_AXIS_SCROLL_ANIMATOR_H
18 #include "base/geometry/dimension.h"
19 #include "base/utils/time_util.h"
20 #include "core/animation/curves.h"
21 #include "core/animation/motion.h"
22 
23 namespace OHOS::Ace::NG {
24 
25 using MoveCallbck = std::function<float(float)>;
26 constexpr int32_t AXIS_DISTANCE_THRESHOLD = 720;
27 constexpr int32_t AXIS_KEY_DISTANCE = 240;
28 constexpr float AXIS_ANIMATION_DURATION = 200.f;
29 constexpr float AXIS_ANIMATION_KEY_DURATION = 100.f;
30 
31 class ACE_EXPORT AxisScrollMotion : public Motion {
32     DECLARE_ACE_TYPE(AxisScrollMotion, Motion);
33 
34 public:
AxisScrollMotion(float startPos,float distance)35     AxisScrollMotion(float startPos, float distance)
36     {
37         Reset(startPos, distance);
38     }
39 
GetCurrentPosition()40     double GetCurrentPosition() override
41     {
42         return currentPos_;
43     }
44 
GetFinalPosition()45     double GetFinalPosition()
46     {
47         return finalPos_;
48     }
49 
GetCurrentVelocity()50     double GetCurrentVelocity() override
51     {
52         return 0.0;
53     }
54 
55     void Reset(float startPos, float distance);
56 
57     bool IsCompleted() override;
58 
GetMotionType()59     std::string GetMotionType() const override
60     {
61         return "axis scroll motion";
62     }
63 
64     void Move(float offsetTime) override;
65 
GetCurrentTime()66     float GetCurrentTime()
67     {
68         return currentTime_;
69     }
70 
ResetCurrentTime()71     void ResetCurrentTime()
72     {
73         currentTime_ = 0.f;
74     }
75 
76 private:
77     float currentPos_ = 0.f;
78     float distance_ = 0.f;
79     float startPos_ = 0.f;
80     float finalPos_ = 0.f;
81     float startTime_ = 0.f;
82     float currentTime_ = 0.f;
83     float endTime_ = 0.f;
84     MoveCallbck moveCallback_;
85 
86     ACE_DISALLOW_COPY_AND_MOVE(AxisScrollMotion);
87 };
88 } // namespace OHOS::Ace::NG
89 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SCROLLABLE_AXIS_AXIS_SCROLL_ANIMATOR_H