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_INTERFACE_INNERKITS_ANIMATOR_OPTION_H 17 #define FOUNDATION_ACE_INTERFACE_INNERKITS_ANIMATOR_OPTION_H 18 19 #include <cstdint> 20 #include <memory> 21 #include <string> 22 23 #include "napi/native_api.h" 24 #include "napi/native_engine/native_value.h" 25 #include "napi/native_node_api.h" 26 27 #include "base/memory/referenced.h" 28 #include "core/animation/animator.h" 29 30 namespace OHOS::Ace::Napi { 31 32 struct AnimatorOption { 33 int32_t duration = 0; 34 int32_t delay = 0; 35 int32_t iterations = 0; 36 double begin = 0.0; 37 double end = 0.0; 38 std::string easing = "ease"; 39 std::string fill = "none"; 40 std::string direction = "normal"; 41 ToStringAnimatorOption42 std::string ToString() const 43 { 44 return "AnimatorOption:[" + std::to_string(duration) + "," + std::to_string(delay) + "," + 45 std::to_string(iterations) + "," + std::to_string(begin) + "," + std::to_string(end) + "," + easing + 46 "," + fill + "," + direction + "]"; 47 } 48 }; 49 50 class AnimatorResult final { 51 public: 52 AnimatorResult() = default; AnimatorResult(RefPtr<Animator> & animator,std::shared_ptr<AnimatorOption> & option)53 AnimatorResult(RefPtr<Animator>& animator, std::shared_ptr<AnimatorOption>& option) 54 : animator_(animator), option_(option) 55 { 56 ApplyOption(); 57 } 58 ~AnimatorResult() = default; 59 GetAnimator()60 RefPtr<Animator> GetAnimator() const 61 { 62 return animator_; 63 } 64 GetAnimatorOption()65 std::shared_ptr<AnimatorOption> GetAnimatorOption() const 66 { 67 return option_; 68 } 69 GetOnframeRef()70 napi_ref GetOnframeRef() const 71 { 72 return onframe_; 73 } 74 SetOnframeRef(const napi_ref & onframe)75 void SetOnframeRef(const napi_ref& onframe) 76 { 77 onframe_ = onframe; 78 } 79 GetOnfinishRef()80 napi_ref GetOnfinishRef() const 81 { 82 return onfinish_; 83 } 84 SetOnfinishRef(const napi_ref & onfinish)85 void SetOnfinishRef(const napi_ref& onfinish) 86 { 87 onfinish_ = onfinish; 88 } 89 GetOncancelRef()90 napi_ref GetOncancelRef() const 91 { 92 return oncancel_; 93 } 94 SetOncancelRef(const napi_ref & oncancel)95 void SetOncancelRef(const napi_ref& oncancel) 96 { 97 oncancel_ = oncancel; 98 } 99 GetOnrepeatRef()100 napi_ref GetOnrepeatRef() const 101 { 102 return onrepeat_; 103 } 104 SetOnrepeatRef(const napi_ref & onrepeat)105 void SetOnrepeatRef(const napi_ref& onrepeat) 106 { 107 onrepeat_ = onrepeat; 108 } 109 GetMotion()110 const RefPtr<Motion>& GetMotion() const 111 { 112 return motion_; 113 } 114 SetMotion(const RefPtr<Motion> & motion)115 void SetMotion(const RefPtr<Motion>& motion) 116 { 117 motion_ = motion; 118 } 119 120 void ApplyOption(); 121 122 void Destroy(napi_env env); 123 124 private: 125 RefPtr<Animator> animator_; 126 RefPtr<Motion> motion_; 127 std::shared_ptr<AnimatorOption> option_; 128 napi_ref onframe_ = nullptr; 129 napi_ref onfinish_ = nullptr; 130 napi_ref oncancel_ = nullptr; 131 napi_ref onrepeat_ = nullptr; 132 }; 133 134 } // namespace OHOS::Ace::Napi 135 136 #endif // #define FOUNDATION_ACE_INTERFACE_INNERKITS_ANIMATOR_RESULT_H 137