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) const23void 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()44void 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 End()60void MockImplicitAnimation::End() 61 { 62 remainingTicks_ = 0; 63 if (cbs_.finishCb) { 64 cbs_.finishCb(); 65 } 66 } 67 JumpToEnd()68void MockImplicitAnimation::JumpToEnd() 69 { 70 remainingTicks_ = 1; 71 UpdateProp(prop_); 72 if (cbs_.repeatCb) { 73 cbs_.repeatCb(); 74 } 75 End(); 76 } 77 } // namespace OHOS::Ace