1 /*
2  * Copyright (c) 2023 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_PATTERNS_NAVIGATION_NAVIGATION_MODEL_NG_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_NAVIGATION_MODEL_NG_H
18 
19 #include "core/components_ng/pattern/navigation/navigation_model.h"
20 #include "core/components_ng/pattern/navigation/nav_bar_node.h"
21 #include "core/components_ng/pattern/navigation/navigation_group_node.h"
22 #include "core/components_ng/base/navigation_register.h"
23 
24 namespace OHOS::Ace::NG {
25 class ACE_EXPORT NavigationModelNG : public OHOS::Ace::NavigationModel {
26 public:
27     void Create() override;
28     void SetNavigationStack() override;
29     void SetNavigationStack(const RefPtr<NG::NavigationStack>& navigationStack) override;
30     void SetNavigationStackWithCreatorAndUpdater(std::function<RefPtr<NG::NavigationStack>()> creator,
31         std::function<void(RefPtr<NG::NavigationStack>)> updater) override;
32     void SetNavigationStackProvided(bool provided) override;
33     void SetNavigationPathInfo(const std::string& moduleName, const std::string& pagePath) override;
34     bool ParseCommonTitle(bool hasSubTitle, bool hasMainTitle, const std::string& subtitle,
35         const std::string& title, bool ignoreMainTitle = false) override;
36     void SetTitle(const std::string& title, bool hasSubTitle = false) override;
37     void SetTitlebarOptions(NavigationTitlebarOptions&& opt) override;
38     void SetCustomTitle(const RefPtr<AceType>& customNode) override;
39     void SetTitleHeight(const Dimension& height, bool isValid = true) override;
40     void SetTitleMode(NG::NavigationTitleMode mode) override;
41     void SetSubtitle(const std::string& subtitle) override;
42     void SetHideTitleBar(bool hideTitleBar, bool animated = false) override;
43     void SetHideNavBar(bool hideNavBar) override;
44     void SetBackButtonIcon(const std::function<void(WeakPtr<NG::FrameNode>)>& symbolApply, const std::string& src,
45         const ImageOption& imageOption, RefPtr<PixelMap>& pixMap, const std::vector<std::string>& nameList) override;
46     void SetHideBackButton(bool hideBackButton) override;
47     void SetHideToolBar(bool hideToolBar, bool animated = false) override;
48     void SetCustomToolBar(const RefPtr<AceType>& customNode) override;
49     bool NeedSetItems() override;
50 
51     void SetToolBarItems(std::vector<NG::BarItem>&& toolBarItems) override;
52     void SetToolbarConfiguration(std::vector<NG::BarItem>&& toolBarItems) override;
53     void SetToolbarOptions(NavigationToolbarOptions&& opt) override;
54     void SetMenuItems(std::vector<NG::BarItem>&& menuItems) override;
55     void SetCustomMenu(const RefPtr<AceType>& customNode) override;
56     void SetOnTitleModeChange(std::function<void(NG::NavigationTitleMode)>&& onTitleModeChange,
57         std::function<void(const BaseEventInfo* baseInfo)>&& eventInfo) override;
58     void SetUsrNavigationMode(NG::NavigationMode mode) override;
59     void SetNavBarPosition(NG::NavBarPosition mode) override;
60     void SetNavBarWidth(const Dimension& value) override;
61     void SetMinNavBarWidth(const Dimension& value) override;
62     void SetMaxNavBarWidth(const Dimension& value) override;
63     void SetMinContentWidth(const Dimension& value) override;
64     void SetOnNavBarStateChange(std::function<void(bool)>&& onNavBarStateChange) override;
65     void SetNavigationMode(NG::NavigationMode mode) override;
66     void SetNavDestination(std::function<void(std::string)>&& builder) override;
67     RefPtr<NG::NavigationStack> GetNavigationStack() override;
68     void SetMenuCount(int32_t menuCount) override;
69     void SetOnNavigationModeChange(std::function<void(NG::NavigationMode)>&& onModeChange) override;
70     void SetCustomTransition(NavigationTransitionEvent&& animationTransition) override;
71     void SetIsCustomAnimation(bool isCustom) override;
72     void SetEnableDragBar(bool enableDragBar) override;
73     void SetRecoverable(bool recoverable) override;
74 
75     static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId);
76     static void SetNavigationStack(FrameNode* frameNode);
77     static void SetHideToolBar(FrameNode* frameNode, bool hideToolBar, bool animated);
78     static void SetMinContentWidth(FrameNode* frameNode, const Dimension& value);
79     static void SetMinNavBarWidth(FrameNode* frameNode, const Dimension& value);
80     static void SetMaxNavBarWidth(FrameNode* frameNode, const Dimension& value);
81     static void SetNavBarWidth(FrameNode* frameNode, const Dimension& value);
82     static void SetNavBarPosition(FrameNode* frameNode, NG::NavBarPosition mode);
83     static void SetUsrNavigationMode(FrameNode* frameNode, NavigationMode mode);
84     static void SetBackButtonIcon(FrameNode* frameNode, const std::function<void(WeakPtr<NG::FrameNode>)>& symbolApply,
85         const std::string& src, const ImageOption& imageOption, RefPtr<PixelMap>& pixMap);
86     static void SetHideNavBar(FrameNode* frameNode, bool hideNavBar);
87     static void SetHideTitleBar(FrameNode* frameNode, bool hideTitleBar, bool animated);
88     static void SetSubtitle(FrameNode* frameNode, const std::string& subtitle);
89     static void SetHideBackButton(FrameNode* frameNode, bool hideBackButton);
90     static void SetTitleMode(FrameNode* frameNode, NG::NavigationTitleMode mode);
91     static void SetEnableDragBar(FrameNode* frameNode, bool enableDragBar);
92     static void SetRecoverable(FrameNode* frameNode, bool recoverable);
93 
94     void SetIgnoreLayoutSafeArea(const NG::SafeAreaExpandOpts& opts) override;
95     static void SetIgnoreLayoutSafeArea(FrameNode* frameNode, const NG::SafeAreaExpandOpts& opts);
96     void SetSystemBarStyle(const RefPtr<SystemBarStyle>& style) override;
97     static void ParseCommonTitle(FrameNode* frameNode, const NG::NavigationTitleInfo& titleInfo,
98         bool ignoreMainTitle = false);
99     static void SetTitlebarOptions(FrameNode* frameNode, NavigationTitlebarOptions&& opt);
100     static void SetMenuItems(FrameNode* frameNode, std::vector<NG::BarItem>&& menuItems);
101     static void SetMenuItemAction(FrameNode* frameNode, std::function<void()>&& action, uint32_t index);
102     static void SetMenuItemSymbol(FrameNode* frameNode,
103         std::function<void(WeakPtr<NG::FrameNode>)>&& symbol, uint32_t index);
104 
105 private:
106     bool CreateNavBarNodeIfNeeded(const RefPtr<NavigationGroupNode>& navigationGroupNode);
107     bool CreateNavBarNodeChildsIfNeeded(const RefPtr<NavBarNode>& navBarNode);
108     bool CreateContentNodeIfNeeded(const RefPtr<NavigationGroupNode>& navigationGroupNode);
109     bool CreateDividerNodeIfNeeded(const RefPtr<NavigationGroupNode>& navigationGroupNode);
110     static void SetHideNavBarInner(const RefPtr<NavigationGroupNode>& navigationGroupNode, bool hideNavBar);
111 };
112 } // namespace OHOS::Ace::NG
113 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_NAVIGATION_MODEL_NG_H
114