• 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_NAV_BAR_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_NAV_BAR_PATTERN_H
18 
19 #include "base/memory/referenced.h"
20 #include "core/components_ng/base/ui_node.h"
21 #include "core/components_ng/pattern/navigation/nav_bar_event_hub.h"
22 #include "core/components_ng/pattern/navigation/nav_bar_layout_algorithm.h"
23 #include "core/components_ng/pattern/navigation/nav_bar_layout_property.h"
24 #include "core/components_ng/pattern/navigation/nav_bar_node.h"
25 #include "core/components_ng/pattern/navigation/navdestination_pattern_base.h"
26 #include "core/components_ng/pattern/navigation/navigation_event_hub.h"
27 #include "core/components_ng/pattern/navigation/navigation_layout_algorithm.h"
28 #include "core/components_ng/pattern/navigation/title_bar_layout_property.h"
29 #include "core/components_ng/pattern/pattern.h"
30 
31 namespace OHOS::Ace::NG {
32 
33 class NavBarPattern : public NavDestinationPatternBase {
34     DECLARE_ACE_TYPE(NavBarPattern, NavDestinationPatternBase);
35 
36 public:
37     NavBarPattern() = default;
38     ~NavBarPattern() override = default;
39 
IsEnableMatchParent()40     bool IsEnableMatchParent() override
41     {
42         return true;
43     }
44 
IsEnableFix()45     bool IsEnableFix() override
46     {
47         return true;
48     }
49 
IsEnableChildrenMatchParent()50     bool IsEnableChildrenMatchParent() override
51     {
52         return true;
53     }
54 
CreateLayoutProperty()55     RefPtr<LayoutProperty> CreateLayoutProperty() override
56     {
57         return MakeRefPtr<NavBarLayoutProperty>();
58     }
59 
CreateLayoutAlgorithm()60     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
61     {
62         return MakeRefPtr<NavBarLayoutAlgorithm>();
63     }
64 
CreateEventHub()65     RefPtr<EventHub> CreateEventHub() override
66     {
67         return MakeRefPtr<NavBarEventHub>();
68     }
69 
70     void OnCoordScrollStart() override;
71     float OnCoordScrollUpdate(float offset, float currentOffset) override;
72     void OnCoordScrollEnd() override;
73     bool CanCoordScrollUp(float offset) const override;
74 
75     void OnAttachToFrameNode() override;
76 
NeedCoordWithScroll()77     bool NeedCoordWithScroll() override
78     {
79         return !isHideTitlebar_ && (titleMode_ == NavigationTitleMode::FREE || IsNeedHandleScroll());
80     }
IsNeedHandleScroll()81     bool IsNeedHandleScroll() const override
82     {
83         auto eventHub = GetOrCreateEventHub<NavBarEventHub>();
84         if (eventHub && eventHub->HasOnCoordScrollStartAction()) {
85             return true;
86         }
87         return false;
88     }
89     OffsetF GetShowMenuOffset(const RefPtr<BarItemNode>& barItemNode, const RefPtr<FrameNode>& menuNode);
90 
91     float GetTitleBarHeightLessThanMaxBarHeight() const override;
92 
93     void BeforeCreateLayoutWrapper() override;
94 
95 protected:
96     void OnDetachFromFrameNode(FrameNode* frameNode) override;
97 
98     void MountTitleBar(const RefPtr<FrameNode>& host, bool& needRunTitleBarAnimation);
99 
100 private:
101     void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) override;
102     void OnModifyDone() override;
103     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
104 
105     RefPtr<PanEvent> panEvent_;
106     WeakPtr<FrameNode> scrollableNode_;
107     RefPtr<FrictionMotion> motion_;
108     RefPtr<Animator> controller_;
109     NavigationTitleMode titleMode_ = NavigationTitleMode::FREE;
110 };
111 
112 } // namespace OHOS::Ace::NG
113 
114 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_NAV_BAR_PATTERN_H