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