1 /*
2  * Copyright (c) 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_NG_PATTERNS_TIME_PICKER_TOSS_ANIMATION_CONTROLLER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TIME_PICKER_TOSS_ANIMATION_CONTROLLER_H
18 
19 #include "core/components/picker/picker_animation.h"
20 #include "core/components_ng/base/frame_node.h"
21 #include "core/pipeline_ng/pipeline_context.h"
22 #include "frameworks/base/memory/ace_type.h"
23 
24 namespace OHOS::Ace::NG {
25 class TimePickerColumnPattern;
26 
27 class TimePickerTossAnimationController : public virtual AceType {
28     DECLARE_ACE_TYPE(TimePickerTossAnimationController, AceType);
29 
30 public:
31     TimePickerTossAnimationController() = default;
32     ~TimePickerTossAnimationController() = default;
33 
SetColumn(const WeakPtr<TimePickerColumnPattern> & value)34     void SetColumn(const WeakPtr<TimePickerColumnPattern>& value)
35     {
36         column_ = value;
37     }
38 
SetPipelineContext(const WeakPtr<PipelineContext> & pipeline)39     void SetPipelineContext(const WeakPtr<PipelineContext>& pipeline)
40     {
41         pipeline_ = pipeline;
42     }
43 
44     void SetStart(double y);
45 
46     void SetEnd(double y);
47 
48     bool Play();
49 
GetTossNodeAnimation()50     RefPtr<NodeAnimatablePropertyFloat> GetTossNodeAnimation()
51     {
52         return property_;
53     }
54 
55     void StartSpringMotion();
56 
57     RefPtr<Curve> UpdatePlayAnimationValue();
58 
59     void StopTossAnimation();
60 
GetTossEndPosition()61     double GetTossEndPosition()
62     {
63         return end_;
64     }
65 
66 private:
67     double GetCurrentTime() const;
68     void CreatePropertyCallback();
69 
70     double yStart_ = 0.0;
71     double yEnd_ = 0.0;
72     double timeStart_ = 0.0;
73     double timeEnd_ = 0.0;
74     double speed_ = 0.0;
75     int32_t showCount_ = 0;
76     double end_ = 0.0;
77     WeakPtr<TimePickerColumnPattern> column_;
78     WeakPtr<PipelineContext> pipeline_;
79 
80     RefPtr<NodeAnimatablePropertyFloat> property_;
81 
82     ACE_DISALLOW_COPY_AND_MOVE(TimePickerTossAnimationController);
83 };
84 } // namespace OHOS::Ace::NG
85 
86 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TIME_PICKER_TOSS_ANIMATION_CONTROLLER_H
87