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_TEXT_PICKER_TOSS_ANIMATION_CONTROLLER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_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 TextPickerColumnPattern;
26 
27 class TextPickerTossAnimationController : public virtual AceType {
28     DECLARE_ACE_TYPE(TextPickerTossAnimationController, AceType);
29 
30 public:
31     TextPickerTossAnimationController() = default;
32     ~TextPickerTossAnimationController() = default;
33 
SetColumn(const WeakPtr<TextPickerColumnPattern> & value)34     void SetColumn(const WeakPtr<TextPickerColumnPattern>& 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() const
51     {
52         return property_;
53     }
54 
55     void StartSpringMotion();
56 
57     RefPtr<Curve> UpdatePlayAnimationValue();
58 
59     void StopTossAnimation();
60 
GetTossEndPosition()61     double GetTossEndPosition() const
62     {
63         return end_;
64     }
65 
66     double GetTossOffset() const;
67 
68     bool GetTossPlaying() const;
69     void SetTossPlaying(bool playing);
70 private:
71     double GetCurrentTime() const;
72     void CreatePropertyCallback();
73 
74     double yStart_ = 0.0;
75     double yEnd_ = 0.0;
76     double timeStart_ = 0.0;
77     double timeEnd_ = 0.0;
78     double speed_ = 0.0;
79     int32_t showCount_ = 0;
80     double end_ = 0.0;
81     bool isManualStopToss_ = false;
82     bool isTossPlaying_ = false;
83     WeakPtr<TextPickerColumnPattern> column_;
84     WeakPtr<PipelineContext> pipeline_;
85     RefPtr<NodeAnimatablePropertyFloat> property_;
86 
87     ACE_DISALLOW_COPY_AND_MOVE(TextPickerTossAnimationController);
88 };
89 } // namespace OHOS::Ace::NG
90 
91 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_PICKER_TOSS_ANIMATION_CONTROLLER_H
92