1 /* 2 * Copyright (c) 2025 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_PATTERN_NAV_CONTENT_LAYOUT_PROPERTY_BASE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_NAV_CONTENT_LAYOUT_PROPERTY_BASE_H 18 19 #include "core/components_ng/layout/layout_property.h" 20 #include "core/components_ng/pattern/linear_layout/linear_layout_property.h" 21 #include "core/components_ng/property/property.h" 22 23 namespace OHOS::Ace::NG { 24 25 26 class ACE_EXPORT NavContentLayoutPropertyBase : public LinearLayoutProperty { 27 DECLARE_ACE_TYPE(NavContentLayoutPropertyBase, LinearLayoutProperty); 28 29 public: NavContentLayoutPropertyBase(bool isVertical)30 explicit NavContentLayoutPropertyBase(bool isVertical) : LinearLayoutProperty(isVertical) {}; 31 ~NavContentLayoutPropertyBase() override = default; 32 Clone()33 RefPtr<LayoutProperty> Clone() const override 34 { 35 auto copy = MakeRefPtr<NavContentLayoutPropertyBase>(IsVertical()); 36 copy->LayoutProperty::UpdateLayoutProperty(DynamicCast<LayoutProperty>(this)); 37 return copy; 38 } 39 Reset()40 void Reset() override 41 { 42 LayoutProperty::Reset(); 43 } 44 ExpandConstraintWithSafeArea()45 void ExpandConstraintWithSafeArea() override 46 { 47 auto host = GetHost(); 48 if (!host || !host->GetIgnoreLayoutProcess()) { 49 return; 50 } 51 RefPtr<FrameNode> parent = host->GetAncestorNodeOfFrame(false); 52 CHECK_NULL_VOID(parent); 53 IgnoreLayoutSafeAreaOpts options = { .type = NG::LAYOUT_SAFE_AREA_TYPE_SYSTEM, 54 .edges = NG::LAYOUT_SAFE_AREA_EDGE_ALL }; 55 if (!IsIgnoreOptsValid()) { 56 return; 57 } 58 options = *GetIgnoreLayoutSafeAreaOpts(); 59 ExpandEdges sae = parent->GetAccumulatedSafeAreaExpand(true, options); 60 OptionalSizeF expandedSize; 61 auto geometryNode = host->GetGeometryNode(); 62 CHECK_NULL_VOID(geometryNode); 63 auto parentConstraint = geometryNode->GetParentLayoutConstraint(); 64 if (parentConstraint) { 65 expandedSize = parentConstraint->selfIdealSize; 66 } 67 layoutConstraint_->selfIdealSize.SetWidth( 68 expandedSize.Width().value_or(0.0f) + sae.left.value_or(0.0f) + sae.right.value_or(0.0f)); 69 layoutConstraint_->selfIdealSize.SetHeight( 70 expandedSize.Height().value_or(0.0f) + sae.top.value_or(0.0f) + sae.bottom.value_or(0.0f)); 71 } 72 }; 73 74 } // namespace OHOS::Ace::NG 75 76 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_NAV_CONTENT_LAYOUT_PROPERTY_BASE_H 77