1 /* 2 * Copyright (c) 2021 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_ANIMATION_ANIMATION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_ANIMATION_H 18 19 #include "base/utils/listener.h" 20 #include "core/animation/curve.h" 21 #include "core/animation/interpolator.h" 22 23 namespace OHOS::Ace { 24 25 template<typename T> 26 class ACE_FORCE_EXPORT Animation : public Interpolator, public ValueListenable<T> { 27 DECLARE_ACE_TYPE(Animation, Interpolator); 28 29 public: 30 virtual const T& GetValue() const = 0; 31 OnInitNotify(float normalizedTime,bool reverse)32 void OnInitNotify(float normalizedTime, bool reverse) override 33 { 34 // If the user sets the initial value, the animation stay at the initial value. 35 if (inited_) { 36 ValueListenable<T>::NotifyListener(initValue_); 37 } else { 38 OnNormalizedTimestampChanged(normalizedTime, reverse); 39 } 40 } 41 SetInitValue(const T & initValue)42 void SetInitValue(const T& initValue) 43 { 44 initValue_ = initValue; 45 inited_ = true; 46 } 47 HasInitValue()48 bool HasInitValue() const 49 { 50 return inited_; 51 } 52 SetCurve(const RefPtr<Curve> & curve)53 virtual void SetCurve(const RefPtr<Curve>& curve) {} 54 55 private: 56 T initValue_ {}; 57 bool inited_ = false; 58 }; 59 60 } // namespace OHOS::Ace 61 62 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_ANIMATION_H 63