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_CORE_COMPONENTS_TRANSITION_TRANSITION_ELEMENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TRANSITION_TRANSITION_ELEMENT_H 18 19 #include "core/animation/property_animatable.h" 20 #include "core/components/box/box_base_element.h" 21 #include "core/components/common/properties/page_transition_option.h" 22 #include "core/components/common/properties/tween_option.h" 23 #include "core/components/display/display_component.h" 24 #include "core/components/transform/transform_element.h" 25 #include "core/pipeline/base/composed_element.h" 26 27 namespace OHOS::Ace { 28 29 class Animator; 30 class TweenElement; 31 32 enum class TransitionOptionType { 33 TRANSITION_IN, 34 TRANSITION_OUT, 35 TRANSITION_SHARED_IN, 36 TRANSITION_SHARED_OUT, 37 }; 38 39 class TransitionElement : public ComposedElement { 40 DECLARE_ACE_TYPE(TransitionElement, ComposedElement); 41 42 public: TransitionElement(const ComposeId & id)43 explicit TransitionElement(const ComposeId& id) : ComposedElement(id) {} 44 ~TransitionElement() override = default; 45 46 void Update() override; 47 void PerformBuild() override; 48 void SetController(const RefPtr<Animator>& controller); 49 RefPtr<Animator> GetController() const; 50 void SetTouchable(bool enable); 51 void SetWrapHidden(bool hidden); 52 void AddPreFlush(); 53 void SkipPostFlush(); 54 void SwitchTransitionOption(TransitionOptionType direction, bool needApplyOption = false); 55 void SetTransition(const TweenOption& inOption, const TweenOption& outOption); 56 void SetSharedTransition(const TweenOption& inOption, const TweenOption& outOption); 57 RefPtr<Element> GetContentElement() const; 58 void ResetPageTransitionAnimation() const; 59 60 protected: 61 RefPtr<Component> BuildChild() override; 62 63 private: 64 RefPtr<TweenElement> GetChildTween() const; 65 RefPtr<BoxBaseElement> GetChildBox() const; 66 RefPtr<DisplayElement> GetChildDisplay() const; 67 RefPtr<TransformElement> GetChildTransform() const; 68 void ReplaceAnimation(TweenOption& transitionOption); 69 void ApplyAnimation(TweenOption& transitionOption); 70 71 RefPtr<Animator> controller_; 72 TweenOption transitionOption_; 73 bool hasBuildChild_ = false; 74 75 std::map<TransitionOptionType, TweenOption> optionMap_; 76 }; 77 78 } // namespace OHOS::Ace 79 80 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TRANSITION_TRANSITION_ELEMENT_H 81