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_SHARED_TRANSITION_SHARED_TRANSITION_ELEMENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SHARED_TRANSITION_SHARED_TRANSITION_ELEMENT_H 18 19 #include "core/animation/shared_transition_effect.h" 20 #include "core/components/box/box_component.h" 21 #include "core/components/box/box_element.h" 22 #include "core/components/box/render_box.h" 23 #include "core/components/common/properties/tween_option.h" 24 #include "core/components/shared_transition/shared_transition_component.h" 25 #include "core/pipeline/base/composed_element.h" 26 27 namespace OHOS::Ace { 28 29 class BoxComponent; 30 class PageElement; 31 class RenderBox; 32 33 class SharedTransitionElement : public ComposedElement, public FlushEvent { 34 DECLARE_ACE_TYPE(SharedTransitionElement, ComposedElement); 35 36 public: 37 using SizeModifiedCallback = std::function<void()>; SharedTransitionElement(const ComposeId & id)38 explicit SharedTransitionElement(const ComposeId& id) : ComposedElement(id) {} 39 ~SharedTransitionElement() override; 40 41 void Update() override; 42 // Prepare playing Shared Transition, Shared Transition Component prepare to show up in overlay. 43 // Passenger wears a suit and aboard shuttle, where passenger means Shared Transition Component and shuttle means 44 // overlay. 45 bool AboardShuttle(Offset& ticket); GetPassengerComponent()46 RefPtr<Component> GetPassengerComponent() const 47 { 48 return passengerComponent_; 49 } 50 GetPassengerElement()51 RefPtr<Element> GetPassengerElement() const 52 { 53 return passengerElement_; 54 } 55 // After finish Shared Transition, Shared Transition cleared from overlay and come back to source. 56 // Passenger arrives at destination and teleports back home 57 void GetOffShuttle(); 58 // When Shared Transition plays, only shared transition component in overlay can be seen, others will be invisible 59 // on their own page. 60 // When Shared Transition finished, shared transition component is visible on its own page, and overlay is cleared. 61 void SetVisible(bool visible); 62 const ShareId& GetShareId() const; 63 const RefPtr<SharedTransitionEffect>& GetEffect() const; 64 Size GetSuitSize() const; 65 Offset GetGlobalOffset() const; 66 float GetOpacity() const; 67 int32_t GetZIndex() const; 68 RefPtr<Element> GetContentElement() const; 69 bool IsEnablePopEnter() const; 70 bool IsEnablePushEnter() const; 71 bool IsEnablePopExit() const; 72 bool IsEnablePushExit() const; 73 GetOption()74 const TweenOption& GetOption() const 75 { 76 return option_; 77 } 78 79 void PerformBuild() override; 80 81 void SetSizeModified(SizeModifiedCallback&& sizeModifiedCallback); 82 83 protected: 84 RefPtr<Component> BuildChild() override; 85 void OnPostFlush() override; 86 87 private: 88 void Register(); 89 RefPtr<RenderBox> GetRenderPassengerWithPajamas() const; 90 RefPtr<RenderBox> GetRenderBox(); 91 RefPtr<PageElement> SearchParentPage() const; 92 93 ShareId shareId_; 94 ShareId oldShareId_; 95 TweenOption option_; 96 RefPtr<BoxComponent> passengerComponent_; // Set When Build Passenger Aboard, Reset When Destruct. 97 RefPtr<BoxElement> passengerElement_; // Set When Passenger Aboard, Reset When GetOff Shuttle 98 RefPtr<RenderBox> passengerRender_; // Set When Passenger Aboard, Reset When GetOff Shuttle 99 RefPtr<SharedTransitionEffect> effect_; 100 WeakPtr<PageElement> pageElement_; 101 Dimension passengerHeight_; 102 Dimension passengerWidth_; 103 bool enablePopEnter_ = true; 104 bool enablePopExit_ = true; 105 bool enablePushEnter_ = true; 106 bool enablePushExit_ = true; 107 SizeModifiedCallback sizeModifiedCallback_; 108 float opacity_ = 1.0f; 109 int32_t zIndex_ = 0; 110 }; 111 112 } // namespace OHOS::Ace 113 114 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SHARED_TRANSITION_SHARED_TRANSITION_ELEMENT_H 115