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 // If disappearing effect is non Identity, return true HasDisappearTransition()50 virtual bool HasDisappearTransition() const 51 { 52 return true; 53 } 54 55 static RefPtr<RosenTransitionEffect> ConvertToRosenTransitionEffect(const RefPtr<ChainedTransitionEffect>& effect); 56 static bool UpdateRosenTransitionEffect( 57 const RefPtr<RosenTransitionEffect>& rosenEffect, const RefPtr<ChainedTransitionEffect>& chainedEffect); 58 59 static RefPtr<RosenTransitionEffect> CreateDefaultRosenTransitionEffect(); 60 61 protected: OnAttach(const RefPtr<RosenRenderContext> & context,bool activeTransition)62 virtual void OnAttach(const RefPtr<RosenRenderContext>& context, bool activeTransition) {} OnDetach(RosenRenderContext * context)63 virtual void OnDetach(RosenRenderContext* context) {} OnAppear()64 virtual void OnAppear() {} OnDisappear(bool activeTransition)65 virtual void OnDisappear(bool activeTransition) {} OnUpdateTransitionContext(const RefPtr<RosenRenderContext> & context,const RectF & selfRect,const SizeF & viewSize)66 virtual void OnUpdateTransitionContext( 67 const RefPtr<RosenRenderContext>& context, const RectF& selfRect, const SizeF& viewSize) 68 {} 69 70 private: 71 RefPtr<RosenTransitionEffect> chainedEffect_ = nullptr; 72 std::shared_ptr<AnimationOption> animationOption_ = nullptr; 73 74 void ApplyAnimationOption(const std::function<void()>& func, bool withAnimation = true); 75 76 DECLARE_ACE_TYPE(RosenTransitionEffect, AceType); 77 ACE_DISALLOW_COPY_AND_MOVE(RosenTransitionEffect); 78 }; 79 } // namespace OHOS::Ace::NG 80 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_ADAPTER_ROSEN_TRANSITION_EFFECT_H 81