1 /* 2 * Copyright (c) 2023 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_COMPONENTS_NG_PAINTS_ADAPTER_ROSEN_TRANSITION_EFFECT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_ADAPTER_ROSEN_TRANSITION_EFFECT_H 18 19 #include "base/geometry/ng/rect_t.h" 20 #include "base/geometry/ng/size_t.h" 21 #include "base/memory/ace_type.h" 22 #include "base/memory/referenced.h" 23 #include "core/components/common/properties/animation_option.h" 24 #include "core/components_ng/property/transition_property.h" 25 26 namespace OHOS::Ace::NG { 27 class RosenRenderContext; 28 29 // Base class for transition effect, providing basic functions for transition effect. 30 // Implementations of transition effect should inherit from this class, see rosen_transition_effect_impl.h for details. 31 class RosenTransitionEffect : public AceType { 32 public: 33 RosenTransitionEffect() = default; 34 ~RosenTransitionEffect() override = default; 35 36 void Attach(const RefPtr<RosenRenderContext>& context, bool activeTransition); 37 void Detach(RosenRenderContext* context); 38 39 void UpdateTransitionContext( 40 const RefPtr<RosenRenderContext>& context, const RectF& selfRect, const SizeF& viewSize); 41 42 void Appear(); 43 void Disappear(bool activeTransition = true); 44 45 // Chain with another transition effect, the chained effect will be applied after this effect. 46 void CombineWith(const RefPtr<RosenTransitionEffect>& effect); 47 virtual void SetAnimationOption(const std::shared_ptr<AnimationOption>& option); 48 49 static RefPtr<RosenTransitionEffect> ConvertToRosenTransitionEffect(const RefPtr<ChainedTransitionEffect>& effect); 50 static bool UpdateRosenTransitionEffect( 51 const RefPtr<RosenTransitionEffect>& rosenEffect, const RefPtr<ChainedTransitionEffect>& chainedEffect); 52 53 static RefPtr<RosenTransitionEffect> CreateDefaultRosenTransitionEffect(); 54 55 protected: OnAttach(const RefPtr<RosenRenderContext> & context,bool activeTransition)56 virtual void OnAttach(const RefPtr<RosenRenderContext>& context, bool activeTransition) {} OnDetach(RosenRenderContext * context)57 virtual void OnDetach(RosenRenderContext* context) {} OnAppear()58 virtual void OnAppear() {} OnDisappear(bool activeTransition)59 virtual void OnDisappear(bool activeTransition) {} OnUpdateTransitionContext(const RefPtr<RosenRenderContext> & context,const RectF & selfRect,const SizeF & viewSize)60 virtual void OnUpdateTransitionContext( 61 const RefPtr<RosenRenderContext>& context, const RectF& selfRect, const SizeF& viewSize) 62 {} 63 64 private: 65 RefPtr<RosenTransitionEffect> chainedEffect_ = nullptr; 66 std::shared_ptr<AnimationOption> animationOption_ = nullptr; 67 68 void ApplyAnimationOption(const std::function<void()>& func, bool withAnimation = true); 69 70 DECLARE_ACE_TYPE(RosenTransitionEffect, AceType); 71 ACE_DISALLOW_COPY_AND_MOVE(RosenTransitionEffect); 72 }; 73 } // namespace OHOS::Ace::NG 74 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_ADAPTER_ROSEN_TRANSITION_EFFECT_H 75