• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "core/components_ng/pattern/navigation/navigation_pattern.h"
17 
18 #include "core/components_ng/pattern/navigation/navigation_event_hub.h"
19 #include "core/components_ng/pattern/navigation/nav_bar_layout_property.h"
20 #include "core/components_ng/pattern/navigation/nav_bar_node.h"
21 #include "core/components_ng/pattern/navrouter/navdestination_group_node.h"
22 #include "core/components_ng/pattern/navrouter/navdestination_layout_property.h"
23 #include "core/components_ng/pattern/navrouter/navrouter_group_node.h"
24 
25 namespace OHOS::Ace::NG {
26 
27 namespace {
28 
MountNavBar(const RefPtr<NavigationGroupNode> & hostNode)29 void MountNavBar(const RefPtr<NavigationGroupNode>& hostNode)
30 {
31     auto navigationLayoutProperty = hostNode->GetLayoutProperty<NavigationLayoutProperty>();
32     CHECK_NULL_VOID(navigationLayoutProperty);
33     auto navBarNode = AceType::DynamicCast<NavBarNode>(hostNode->GetNavBarNode());
34     CHECK_NULL_VOID(navBarNode);
35     auto navBarLayoutProperty = navBarNode->GetLayoutProperty<NavBarLayoutProperty>();
36     CHECK_NULL_VOID(navBarLayoutProperty);
37     auto eventHub = hostNode->GetEventHub<NavigationEventHub>();
38     CHECK_NULL_VOID(eventHub);
39     if (navigationLayoutProperty->GetHideNavBar().value_or(false)) {
40         navBarLayoutProperty->UpdateVisibility(VisibleType::GONE);
41         eventHub->FireNavBarStateChangeEvent(false);
42     } else {
43         navBarLayoutProperty->UpdateVisibility(VisibleType::VISIBLE);
44         eventHub->FireNavBarStateChangeEvent(true);
45     }
46     navBarNode->MarkModifyDone();
47 }
48 
49 }
50 
OnModifyDone()51 void NavigationPattern::OnModifyDone()
52 {
53     auto hostNode = AceType::DynamicCast<NavigationGroupNode>(GetHost());
54     CHECK_NULL_VOID(hostNode);
55     MountNavBar(hostNode);
56     auto navBarNode = AceType::DynamicCast<NavBarNode>(hostNode->GetNavBarNode());
57     CHECK_NULL_VOID(navBarNode);
58     navBarNode->MarkModifyDone();
59 }
60 
OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper> & dirty,const DirtySwapConfig & config)61 bool NavigationPattern::OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config)
62 {
63     if (config.skipMeasure && config.skipLayout) {
64         return false;
65     }
66     auto layoutAlgorithmWrapper = DynamicCast<LayoutAlgorithmWrapper>(dirty->GetLayoutAlgorithm());
67     CHECK_NULL_RETURN(layoutAlgorithmWrapper, false);
68     auto navigationLayoutAlgorithm =
69         DynamicCast<NavigationLayoutAlgorithm>(layoutAlgorithmWrapper->GetLayoutAlgorithm());
70     CHECK_NULL_RETURN(navigationLayoutAlgorithm, false);
71     auto hostNode = AceType::DynamicCast<NavigationGroupNode>(GetHost());
72     CHECK_NULL_RETURN(hostNode, false);
73     auto navigationLayoutProperty = AceType::DynamicCast<NavigationLayoutProperty>(hostNode->GetLayoutProperty());
74     CHECK_NULL_RETURN(navigationLayoutProperty, false);
75     navigationLayoutProperty->UpdateNavigationMode(navigationLayoutAlgorithm->GetNavigationMode());
76     return false;
77 }
78 
79 } // namespace OHOS::Ace::NG