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 23 namespace OHOS::Ace::NG { 24 class FrameNode; 25 class LayoutWrapper; 26 class LayoutProperty; 27 28 class GeometryTransition : public AceType { 29 DECLARE_ACE_TYPE(GeometryTransition, AceType); 30 31 public: 32 GeometryTransition(const std::string& id, const WeakPtr<FrameNode>& frameNode, 33 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; 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(); 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 69 std::string id_; 70 WeakPtr<FrameNode> inNode_; 71 WeakPtr<FrameNode> outNode_; 72 State state_ = State::IDLE; 73 bool hasInAnim_ = false; 74 bool hasOutAnim_ = false; 75 SizeF inNodeActiveFrameSize_; 76 std::optional<RectF> outNodeTargetAbsRect_; 77 OffsetF outNodePos_; 78 SizeF outNodeSize_; 79 OffsetF outNodeParentPos_; 80 WeakPtr<FrameNode> holder_; 81 bool followWithoutTransition_ = false; 82 RefPtr<LayoutProperty> layoutPropertyIn_; 83 RefPtr<LayoutProperty> layoutPropertyOut_; 84 85 ACE_DISALLOW_COPY_AND_MOVE(GeometryTransition); 86 }; 87 } // namespace OHOS::Ace::NG 88 89 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_ANIMATION_GEOMETRY_TRANSITION_H