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 GeometryTransition(const std::string& id, bool followWithoutTransition = false); 34 ~GeometryTransition() override = default; 35 36 bool IsNodeInAndActive(const WeakPtr<FrameNode>& frameNode) const; 37 bool IsNodeOutAndActive(const WeakPtr<FrameNode>& frameNode) const; 38 bool IsRunning(const WeakPtr<FrameNode>& frameNode) const; 39 bool IsInAndOutEmpty() const; 40 bool IsInAndOutValid() const; 41 std::string ToString() const; GetId()42 std::string GetId() const 43 { 44 return id_; 45 } 46 void Build(const WeakPtr<FrameNode>& frameNode, bool isNodeIn); 47 bool Update(const WeakPtr<FrameNode>& which, const WeakPtr<FrameNode>& value); 48 void OnReSync(const WeakPtr<FrameNode>& trigger = nullptr, const AnimationOption& option = AnimationOption()); 49 bool OnAdditionalLayout(const WeakPtr<FrameNode>& frameNode); 50 bool OnFollowWithoutTransition(std::optional<bool> direction = std::nullopt); 51 void WillLayout(const RefPtr<LayoutWrapper>& layoutWrapper); 52 void DidLayout(const RefPtr<LayoutWrapper>& layoutWrapper); 53 54 private: 55 enum class State { 56 IDLE, 57 ACTIVE, 58 IDENTITY, 59 }; 60 61 bool IsNodeInAndIdentity(const WeakPtr<FrameNode>& frameNode) const; 62 void SwapInAndOut(bool condition); 63 std::pair<RefPtr<FrameNode>, RefPtr<FrameNode>> GetMatchedPair(bool isNodeIn) const; 64 void RecordOutNodeFrame(); 65 void MarkLayoutDirty(const RefPtr<FrameNode>& node, int32_t layoutPriority = 0); 66 void ModifyLayoutConstraint(const RefPtr<LayoutWrapper>& layoutWrapper, bool isNodeIn); 67 void SyncGeometry(bool isNodeIn); 68 bool IsParent(const WeakPtr<FrameNode>& parent, const WeakPtr<FrameNode>& child) const; 69 void RecordAnimationOption(const WeakPtr<FrameNode>& trigger, const AnimationOption& option); 70 RectF GetNodeAbsFrameRect(const RefPtr<FrameNode>& node, std::optional<OffsetF> parentPos = std::nullopt) const; 71 72 static constexpr int32_t RESYNC_DURATION = 1; 73 std::string id_; 74 WeakPtr<FrameNode> inNode_; 75 WeakPtr<FrameNode> outNode_; 76 State state_ = State::IDLE; 77 bool hasInAnim_ = false; 78 bool hasOutAnim_ = false; 79 bool isSynced_ = false; 80 SizeF inNodeActiveFrameSize_; 81 std::optional<RectF> inNodeAbsRect_; 82 std::optional<RectF> outNodeTargetAbsRect_; 83 OffsetF outNodePos_; 84 SizeF outNodeSize_; 85 OffsetF outNodeParentPos_; 86 bool outNodeParentHasScales_ = false; 87 RefPtr<FrameNode> holder_; 88 bool followWithoutTransition_ = false; 89 // static node means the node on the tree without transition 90 std::optional<RectF> staticNodeAbsRect_; 91 RefPtr<LayoutProperty> layoutPropertyIn_; 92 RefPtr<LayoutProperty> layoutPropertyOut_; 93 AnimationOption animationOption_; 94 AnimationOption implicitAnimationOption_; 95 96 ACE_DISALLOW_COPY_AND_MOVE(GeometryTransition); 97 }; 98 } // namespace OHOS::Ace::NG 99 100 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_ANIMATION_GEOMETRY_TRANSITION_H