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 FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_ANIMATOR_H 17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_ANIMATOR_H 18 19 #include "frameworks/base/memory/ace_type.h" 20 #include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h" 21 #include "frameworks/core/animation/keyframe_animation.h" 22 23 namespace OHOS::Ace::Framework { 24 25 class JSAnimator : public AceType { 26 DECLARE_ACE_TYPE(JSAnimator, AceType); 27 28 public: 29 JSAnimator() = default; 30 ~JSAnimator() override = default; 31 32 static void JSBind(BindingTarget globalObj); 33 static void Create(const JSCallbackInfo& info); 34 static void Pop(); 35 36 static void SetState(int32_t state); 37 static void SetDuration(int32_t duration); 38 static void SetCurve(const JSCallbackInfo& info); 39 static void SetDelay(int32_t delay); 40 static void SetFillMode(int32_t fillMode); 41 static void SetIteration(int32_t iteration); 42 static void SetPlayMode(int32_t playMode); 43 static void SetMotion(const JSCallbackInfo& info); 44 45 static void OnStart(const JSCallbackInfo& info); 46 static void OnPause(const JSCallbackInfo& info); 47 static void OnRepeat(const JSCallbackInfo& info); 48 static void OnCancel(const JSCallbackInfo& info); 49 static void OnFinish(const JSCallbackInfo& info); 50 static void OnFrame(const JSCallbackInfo& info); 51 52 private: 53 static EventMarker GetEventMarker(const JSCallbackInfo& info); 54 static std::string animatorId_; 55 }; 56 57 class JSSpringProp : public AceType { 58 DECLARE_ACE_TYPE(JSSpringProp, AceType); 59 60 public: 61 JSSpringProp() = default; 62 ~JSSpringProp() override = default; 63 64 static void ConstructorCallback(const JSCallbackInfo& info); 65 static void DestructorCallback(JSSpringProp* obj); 66 SetSpringProp(const RefPtr<SpringProperty> & springProp)67 void SetSpringProp(const RefPtr<SpringProperty>& springProp) 68 { 69 springProp_ = springProp; 70 } 71 GetSpringProp()72 const RefPtr<SpringProperty>& GetSpringProp() 73 { 74 return springProp_; 75 } 76 77 private: 78 RefPtr<SpringProperty> springProp_; 79 80 }; 81 82 class JSMotion : public AceType { 83 DECLARE_ACE_TYPE(JSMotion, AceType); 84 85 public: 86 JSMotion() = default; 87 ~JSMotion() override = default; 88 89 static void ConstructorCallback(const JSCallbackInfo& info); 90 static void DestructorCallback(JSMotion* obj); 91 SetMotion(const RefPtr<Motion> & motion)92 void SetMotion(const RefPtr<Motion>& motion) 93 { 94 motion_ = motion; 95 } 96 GetMotion()97 const RefPtr<Motion>& GetMotion() 98 { 99 return motion_; 100 } 101 102 private: 103 RefPtr<Motion> motion_; 104 105 }; 106 107 } // namespace OHOS::Ace::Framework 108 109 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_ANIMATOR_H