• 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 #include "test/mock/core/animation/mock_implicit_animation.h"
17 
18 #include "test/mock/core/animation/mock_animation_proxy.h"
19 
20 #include "core/components_ng/base/modifier.h"
21 
22 namespace OHOS::Ace {
UpdateProp(const WeakPtr<NG::PropertyBase> & propWk) const23 void MockImplicitAnimation::UpdateProp(const WeakPtr<NG::PropertyBase>& propWk) const
24 {
25 #ifdef ENHANCED_ANIMATION
26     if (auto prop = AceType::DynamicCast<NG::AnimatablePropertyFloat>(propWk.Upgrade()); prop) {
27         NG::MockAnimationProxy<float>::GetInstance().Next(prop, remainingTicks_);
28         auto cb = prop->GetUpdateCallback();
29         if (cb) {
30             cb(NG::MockAnimationProxy<float>::GetInstance().GetStagingValue(prop));
31         }
32     }
33     if (auto prop = AceType::DynamicCast<NG::AnimatablePropertyOffsetF>(propWk.Upgrade()); prop) {
34         NG::MockAnimationProxy<NG::OffsetF>::GetInstance().Next(prop, remainingTicks_);
35         auto cb = prop->GetUpdateCallback();
36         if (cb) {
37             cb(NG::MockAnimationProxy<NG::OffsetF>::GetInstance().GetStagingValue(prop));
38         }
39     }
40     /* add update code for other types */
41 #endif
42 }
43 
Next()44 void MockImplicitAnimation::Next()
45 {
46     if (paused_ || Finished()) {
47         return;
48     }
49     UpdateProp(prop_);
50     if (cbs_.repeatCb) {
51         cbs_.repeatCb();
52     }
53     if (--remainingTicks_ <= 0) {
54         if (cbs_.finishCb) {
55             cbs_.finishCb();
56         }
57     }
58 }
59 
ForceUpdate(float delta)60 void MockImplicitAnimation::ForceUpdate(float delta)
61 {
62     auto prop = AceType::DynamicCast<NG::AnimatablePropertyFloat>(prop_.Upgrade());
63     CHECK_NULL_VOID(prop);
64     NG::MockAnimationProxy<float>::GetInstance().ForceUpdate(prop, delta);
65     auto cb = prop->GetUpdateCallback();
66     if (cb) {
67         cb(NG::MockAnimationProxy<float>::GetInstance().GetStagingValue(prop));
68     }
69 }
70 
End()71 void MockImplicitAnimation::End()
72 {
73     remainingTicks_ = 0;
74     if (cbs_.finishCb) {
75         cbs_.finishCb();
76     }
77 }
78 
JumpToEnd()79 void MockImplicitAnimation::JumpToEnd()
80 {
81     if (Finished()) {
82         return;
83     }
84     remainingTicks_ = 1;
85 }
86 } // namespace OHOS::Ace