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_BRIDGE_JS_FRONTEND_ENGINE_COMMON_BASE_ANIMATION_BRIDGE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_JS_FRONTEND_ENGINE_COMMON_BASE_ANIMATION_BRIDGE_H 18 19 #include <string> 20 #include <unordered_map> 21 22 #include "base/geometry/dimension.h" 23 #include "core/components/tween/tween_component.h" 24 25 namespace OHOS::Ace::Framework { 26 27 enum class AnimatorOperation { 28 NONE, 29 PLAY, 30 FINISH, 31 PAUSE, 32 CANCEL, 33 REVERSE, 34 }; 35 36 class ACE_EXPORT BaseAnimationBridgeUtils { 37 public: 38 static constexpr int32_t TRANSFORM_ORIGIN_DEFAULT_SIZE = 2; 39 static constexpr const char ITERATIONS_INFINITY[] = "Infinity"; 40 static constexpr const char ANIMATION_FROM[] = "0.0"; 41 static constexpr const char ANIMATION_TO[] = "100.0"; 42 // prefix id of TweenComponent, for differentiation from id of ComposedComponent 43 static constexpr const char COMPONENT_PREFIX[] = "FrontendTween"; 44 45 static std::vector<Dimension> HandleTransformOrigin( 46 const std::vector<std::unordered_map<std::string, std::string>>& animationFrames); 47 48 static void SetTweenComponentParams(const RefPtr<Curve>& curve, 49 const std::vector<std::unordered_map<std::string, std::string>>& animationFrames, 50 RefPtr<TweenComponent>& tweenComponent, TweenOption& tweenOption); 51 static void JsParseAnimationFrames( 52 const std::string& content, std::vector<std::unordered_map<std::string, std::string>>& animationFrames); 53 54 static void JsParseAnimationOptions(const std::string& content, int32_t& iterations, 55 std::unordered_map<std::string, double>& animationDoubleOptions, 56 std::unordered_map<std::string, std::string>& animationStringOptions); 57 58 static void JsParseAnimatorParams(const std::string& content, int32_t& iterations, 59 std::unordered_map<std::string, double>& animationDoubleParams, 60 std::unordered_map<std::string, std::string>& animationStringParams); 61 }; 62 63 class BaseAnimationBridge : public virtual AceType { 64 DECLARE_ACE_TYPE(BaseAnimationBridge, AceType); 65 public: OnJsEngineDestroy()66 virtual void OnJsEngineDestroy() {} 67 JsGetAnimator()68 virtual RefPtr<Animator> JsGetAnimator() 69 { 70 return nullptr; 71 }; 72 }; 73 74 } // namespace OHOS::Ace::Framework 75 76 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_JS_FRONTEND_ENGINE_COMMON_BASE_ANIMATION_BRIDGE_H 77