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