1 /* 2 * Copyright (c) 2024 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_NAVIGATION_NAVDESTINATION_LAYOUT_PROPERTY_BASE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_NAVIGATION_NAVDESTINATION_LAYOUT_PROPERTY_BASE_H 18 19 #include "base/geometry/dimension.h" 20 #include "base/utils/macros.h" 21 #include "core/components/common/layout/constants.h" 22 #include "core/components_ng/base/inspector_filter.h" 23 #include "core/components_ng/layout/layout_property.h" 24 #include "core/components_ng/pattern/navigation/navigation_declaration.h" 25 #include "core/components_ng/property/property.h" 26 27 namespace OHOS::Ace::NG { 28 29 /** 30 * Used for titleBar and toolBar's animation. 31 * 1. NONE is used for non-animated scenes. 32 * 2. TRANSLATE_ZERO & TRANSLATE_HEIGHT are used for animated scenes. 33 * 34 * Taking NavDestination in STANDARD mode as example, there are several scenarios as follows: 35 * +=========+ 36 * | title | 37 * +=========+ 38 * +-------------+ +-------------+ 39 * | +=========+ | | +---------+ | 40 * | | title | | | | | | 41 * | +=========+ | <=> | | | | 42 * | +---------+ | | | content | | 43 * | | | | | | | | 44 * | | content | | | | | | 45 * | | | | | | | | 46 * | +---------+ | | +---------+ | 47 * +-------------+ +-------------+ 48 * <TRANSLATE_ZERO> <TRANSLATE_HEIGHT> 49 * 50 * 1. hide titleBar animation: 51 * from TRANSLATE_ZERO to TRANSLATE_HEIGHT 52 * 53 * 2. show titleBar animation: 54 * from TRANSLATE_HEIGHT to TRANSLATE_ZERO 55 */ 56 enum class BarTranslateState { 57 NONE = 0, 58 TRANSLATE_ZERO = 1, 59 TRANSLATE_HEIGHT = 2, 60 }; 61 62 class ACE_EXPORT NavDestinationLayoutPropertyBase : public LayoutProperty { 63 DECLARE_ACE_TYPE(NavDestinationLayoutPropertyBase, LayoutProperty); 64 65 public: 66 NavDestinationLayoutPropertyBase() = default; 67 ~NavDestinationLayoutPropertyBase() override = default; 68 Clone()69 RefPtr<LayoutProperty> Clone() const override 70 { 71 auto copy = MakeRefPtr<NavDestinationLayoutPropertyBase>(); 72 copy->LayoutProperty::UpdateLayoutProperty(DynamicCast<LayoutProperty>(this)); 73 copy->propHideTitleBar_ = CloneHideTitleBar(); 74 copy->propIsAnimatedTitleBar_ = CloneIsAnimatedTitleBar(); 75 copy->propTitleBarTranslateState_ = CloneTitleBarTranslateState(); 76 copy->propHideBackButton_ = CloneHideBackButton(); 77 copy->propHideToolBar_ = CloneHideToolBar(); 78 copy->propIsAnimatedToolBar_ = CloneIsAnimatedToolBar(); 79 copy->propToolBarTranslateState_ = CloneToolBarTranslateState(); 80 return copy; 81 } 82 Reset()83 void Reset() override 84 { 85 LayoutProperty::Reset(); 86 ResetHideTitleBar(); 87 ResetIsAnimatedTitleBar(); 88 ResetTitleBarTranslateState(); 89 ResetHideBackButton(); 90 ResetHideToolBar(); 91 ResetIsAnimatedToolBar(); 92 ResetToolBarTranslateState(); 93 } 94 95 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(HideTitleBar, bool, PROPERTY_UPDATE_MEASURE); 96 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(HideToolBar, bool, PROPERTY_UPDATE_MEASURE); 97 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(HideBackButton, bool, PROPERTY_UPDATE_MEASURE); 98 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IgnoreLayoutSafeArea, IgnoreLayoutSafeAreaOpts, PROPERTY_UPDATE_MEASURE); 99 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IsAnimatedTitleBar, bool, PROPERTY_UPDATE_MEASURE); 100 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IsAnimatedToolBar, bool, PROPERTY_UPDATE_MEASURE); 101 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(TitleBarTranslateState, BarTranslateState, PROPERTY_UPDATE_MEASURE); 102 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ToolBarTranslateState, BarTranslateState, PROPERTY_UPDATE_MEASURE); 103 104 protected: UpdateBaseLayoutProperty(const NavDestinationLayoutPropertyBase * layoutProperty)105 void UpdateBaseLayoutProperty(const NavDestinationLayoutPropertyBase* layoutProperty) 106 { 107 CHECK_NULL_VOID(layoutProperty); 108 LayoutProperty::UpdateLayoutProperty(layoutProperty); 109 propHideTitleBar_ = layoutProperty->GetHideTitleBar(); 110 propIsAnimatedTitleBar_ = layoutProperty->GetIsAnimatedTitleBar(); 111 propTitleBarTranslateState_ = layoutProperty->GetTitleBarTranslateState(); 112 propHideBackButton_ = layoutProperty->GetHideBackButton(); 113 propHideToolBar_ = layoutProperty->GetHideToolBar(); 114 propIsAnimatedToolBar_ = layoutProperty->GetIsAnimatedToolBar(); 115 propToolBarTranslateState_ = layoutProperty->GetToolBarTranslateState(); 116 } 117 }; 118 119 } // namespace OHOS::Ace::NG 120 121 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_NAVIGATION_NAVDESTINATION_LAYOUT_PROPERTY_BASE_H 122