1 /* 2 * Copyright (c) 2021-2022 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_NAVIGATION_BAR_NAVIGATION_BAR_COMPONENT_V2_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NAVIGATION_BAR_NAVIGATION_BAR_COMPONENT_V2_H 18 19 #include "core/components/menu/menu_component.h" 20 #include "core/components/navigation_bar/navigation_bar_component_base.h" 21 #include "core/components/navigation_bar/navigation_container_component.h" 22 #include "core/components/theme/theme_manager_impl.h" 23 #include "core/pipeline/base/composed_component.h" 24 25 namespace OHOS::Ace { 26 27 class NavigationBarBuilder : public NavigationBarComponentBase { 28 public: NavigationBarBuilder(const RefPtr<NavigationDeclaration> & declaration,ComposeId id,TextDirection direction)29 NavigationBarBuilder(const RefPtr<NavigationDeclaration>& declaration, ComposeId id, TextDirection direction) 30 : declaration_(declaration), theme_(AceType::MakeRefPtr<ThemeManagerImpl>()->GetTheme<NavigationBarTheme>()), 31 id_(id), direction_(direction), menuZoneSize_(theme_->GetMenuZoneSize()), 32 menuIconSize_(theme_->GetMenuIconSize()) 33 {} 34 ~NavigationBarBuilder() override = default; 35 Build(const WeakPtr<PipelineContext> & context,int32_t menuCount)36 RefPtr<Component> Build(const WeakPtr<PipelineContext>& context, int32_t menuCount) 37 { 38 context_ = context; 39 menuCount_ = menuCount; 40 RefPtr<Component> navigationBar; 41 if (declaration_->titleMode == NavigationTitleMode::MINI) { 42 navigationBar = BuildMiniLayer(); 43 } else if (declaration_->titleMode == NavigationTitleMode::FULL) { 44 navigationBar = BuildFullLayer(); 45 } else if (declaration_->titleMode == NavigationTitleMode::FREE) { 46 navigationBar = BuildFreeModeBar(); 47 } else { 48 LOGE("unknown navigation title mode"); 49 } 50 return navigationBar; 51 } 52 53 private: 54 RefPtr<Component> BuildMiniLayer(); 55 RefPtr<Component> BuildFullLayer(); 56 RefPtr<Component> BuildFreeModeBar(); 57 RefPtr<Component> BuildTitle(); 58 bool AddMenu(const RefPtr<ComponentGroup>& container); 59 RefPtr<Component> BuildAnimationContainer( 60 const RefPtr<Component>& content, const Dimension& height, const Edge& edge); 61 void BindMoreButtonClickEvent(); 62 void AddOption(const RefPtr<ToolBarItem>& menuItem); 63 64 RefPtr<NavigationDeclaration> declaration_; 65 RefPtr<NavigationBarTheme> theme_; 66 ComposeId id_; 67 TextDirection direction_ = TextDirection::LTR; 68 Dimension menuZoneSize_; 69 Dimension menuIconSize_; 70 71 RefPtr<ComposedComponent> titleComposed_; 72 RefPtr<ComposedComponent> subTitleComposed_; 73 RefPtr<ButtonComponent> moreButton_; 74 RefPtr<MenuComponent> menu_; 75 EventMarker backClickMarker_; 76 int32_t menuCount_ = 0; 77 }; 78 } // namespace OHOS::Ace 79 80 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NAVIGATION_BAR_NAVIGATION_BAR_COMPONENT_V2_H 81