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_ANIMATION_GEOMETRY_TRANSITION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_ANIMATION_GEOMETRY_TRANSITION_H 18 19 #include "base/memory/ace_type.h" 20 #include "base/memory/referenced.h" 21 #include "base/geometry/ng/rect_t.h" 22 #include "core/components/common/properties/animation_option.h" 23 24 namespace OHOS::Ace::NG { 25 class FrameNode; 26 class LayoutWrapper; 27 class LayoutProperty; 28 29 class GeometryTransition : public AceType { 30 DECLARE_ACE_TYPE(GeometryTransition, AceType); 31 32 public: 33 explicit GeometryTransition(const std::string& id, 34 bool followWithoutTransition = false, bool doRegisterSharedTransition = true); 35 ~GeometryTransition() override = default; 36 37 bool IsNodeInAndActive(const WeakPtr<FrameNode>& frameNode) const; 38 bool IsNodeOutAndActive(const WeakPtr<FrameNode>& frameNode) const; 39 bool IsRunning(const WeakPtr<FrameNode>& frameNode) const; 40 bool IsInAndOutEmpty() const; 41 bool IsInAndOutValid() const; 42 std::string ToString() const; GetId()43 std::string GetId() const 44 { 45 return id_; 46 } 47 GetFollowWithoutTransition()48 bool GetFollowWithoutTransition() const 49 { 50 return followWithoutTransition_; 51 } 52 GetDoRegisterSharedTransition()53 bool GetDoRegisterSharedTransition() const 54 { 55 return doRegisterSharedTransition_; 56 } 57 58 void Build(const WeakPtr<FrameNode>& frameNode, bool isNodeIn); 59 bool Update(const WeakPtr<FrameNode>& which, const WeakPtr<FrameNode>& value); 60 void OnReSync(const WeakPtr<FrameNode>& trigger = nullptr, const AnimationOption& option = AnimationOption()); 61 bool OnAdditionalLayout(const WeakPtr<FrameNode>& frameNode); 62 bool OnFollowWithoutTransition(std::optional<bool> direction = std::nullopt); 63 void WillLayout(const RefPtr<LayoutWrapper>& layoutWrapper); 64 void DidLayout(const RefPtr<LayoutWrapper>& layoutWrapper); 65 66 private: 67 enum class State { 68 IDLE, 69 ACTIVE, 70 IDENTITY, 71 }; 72 73 bool IsNodeInAndIdentity(const WeakPtr<FrameNode>& frameNode) const; 74 void SwapInAndOut(bool condition); 75 std::pair<RefPtr<FrameNode>, RefPtr<FrameNode>> GetMatchedPair(bool isNodeIn) const; 76 void RecordOutNodeFrame(); 77 void MarkLayoutDirty(const RefPtr<FrameNode>& node, int32_t layoutPriority = 0); 78 void ModifyLayoutConstraint(const RefPtr<LayoutWrapper>& layoutWrapper, bool isNodeIn); 79 void SyncGeometry(bool isNodeIn); 80 bool IsParent(const WeakPtr<FrameNode>& parent, const WeakPtr<FrameNode>& child) const; 81 void RecordAnimationOption(const WeakPtr<FrameNode>& trigger, const AnimationOption& option); 82 RectF GetNodeAbsFrameRect(const RefPtr<FrameNode>& node, std::optional<OffsetF> parentPos = std::nullopt) const; 83 void AnimateWithSandBox(const OffsetF& inNodeParentPos, bool inNodeParentHasScales, 84 const std::function<void()>& propertyCallback, const AnimationOption& option); 85 void SyncGeometryPropertiesAfterLayout(const RefPtr<FrameNode>& syncNode); 86 RefPtr<FrameNode> GetWindowBoundaryNode(const RefPtr<FrameNode>& node) const; 87 void HandleOcclusionScene(const RefPtr<FrameNode>& node, bool flag); 88 89 static constexpr int32_t RESYNC_DURATION = 1; 90 std::string id_; 91 WeakPtr<FrameNode> inNode_; 92 WeakPtr<FrameNode> outNode_; 93 WeakPtr<FrameNode> outWindowBoundaryNode_; 94 State state_ = State::IDLE; 95 bool hasInAnim_ = false; 96 bool hasOutAnim_ = false; 97 bool isSynced_ = false; 98 SizeF inNodeActiveFrameSize_; 99 std::optional<RectF> inNodeAbsRect_; 100 std::optional<RectF> outNodeTargetAbsRect_; 101 OffsetF outNodePos_; 102 SizeF outNodeSize_; 103 OffsetF outNodeParentPos_; 104 bool outNodeParentHasScales_ = false; 105 RefPtr<FrameNode> holder_; 106 bool followWithoutTransition_ = false; 107 bool doRegisterSharedTransition_ = true; 108 // static node means the node on the tree without transition 109 std::optional<RectF> staticNodeAbsRect_; 110 RefPtr<LayoutProperty> layoutPropertyIn_; 111 RefPtr<LayoutProperty> layoutPropertyOut_; 112 AnimationOption animationOption_; 113 114 ACE_DISALLOW_COPY_AND_MOVE(GeometryTransition); 115 }; 116 } // namespace OHOS::Ace::NG 117 118 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_ANIMATION_GEOMETRY_TRANSITION_H