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 #include "core/components/transform/transform_element.h" 17 18 #include "core/components/page/page_element.h" 19 20 namespace OHOS::Ace { 21 ~TransformElement()22TransformElement::~TransformElement() 23 { 24 auto page = pageElement_.Upgrade(); 25 if (page) { 26 page->RemoveCardTransition(GetRetakeId()); 27 } 28 } 29 PerformBuild()30void TransformElement::PerformBuild() 31 { 32 RefPtr<TransformComponent> transform = AceType::DynamicCast<TransformComponent>(component_); 33 const auto& child = children_.empty() ? nullptr : children_.front(); 34 const auto& newComponent = transform ? transform->GetChild() : nullptr; 35 UpdateChild(child, newComponent); 36 if (transform) { 37 AddCardTransform(transform->GetTransitionEffect()); 38 } 39 } 40 AddCardTransform(TransitionEffect option)41void TransformElement::AddCardTransform(TransitionEffect option) 42 { 43 if (option == TransitionEffect::UNFOLD) { 44 auto page = SearchParentPage(); 45 if (!page) { 46 return; 47 } 48 pageElement_ = page; 49 page->AddCardTransition(AceType::Claim(this)); 50 } 51 } 52 SearchParentPage() const53RefPtr<PageElement> TransformElement::SearchParentPage() const 54 { 55 auto parent = GetElementParent().Upgrade(); 56 while (parent) { 57 auto page = AceType::DynamicCast<PageElement>(parent); 58 if (page) { 59 return page; 60 } 61 parent = parent->GetElementParent().Upgrade(); 62 } 63 LOGW("No parent page found."); 64 return nullptr; 65 } 66 67 } // namespace OHOS::Ace