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_layout_algorithm.h"
22 #include "core/components_ng/pattern/navigation/nav_bar_layout_property.h"
23 #include "core/components_ng/pattern/navigation/nav_bar_node.h"
24 #include "core/components_ng/pattern/navigation/navdestination_pattern_base.h"
25 #include "core/components_ng/pattern/navigation/navigation_event_hub.h"
26 #include "core/components_ng/pattern/navigation/navigation_layout_algorithm.h"
27 #include "core/components_ng/pattern/navigation/title_bar_layout_property.h"
28 #include "core/components_ng/pattern/pattern.h"
29 
30 namespace OHOS::Ace::NG {
31 
32 class NavBarPattern : public NavDestinationPatternBase {
33     DECLARE_ACE_TYPE(NavBarPattern, NavDestinationPatternBase);
34 
35 public:
36     NavBarPattern() = default;
37     ~NavBarPattern() override = default;
38 
CreateLayoutProperty()39     RefPtr<LayoutProperty> CreateLayoutProperty() override
40     {
41         return MakeRefPtr<NavBarLayoutProperty>();
42     }
43 
CreateLayoutAlgorithm()44     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
45     {
46         return MakeRefPtr<NavBarLayoutAlgorithm>();
47     }
48 
49     void OnCoordScrollStart();
50     float OnCoordScrollUpdate(float offset);
51     void OnCoordScrollEnd();
52     bool CanCoordScrollUp(float offset) const;
53 
54     void OnAttachToFrameNode() override;
OnWindowFocused()55     void OnWindowFocused() override
56     {
57         WindowFocus(true);
58     }
59 
OnWindowUnfocused()60     void OnWindowUnfocused() override
61     {
62         WindowFocus(false);
63     }
64 
NeedCoordWithScroll()65     bool NeedCoordWithScroll()
66     {
67         return !isHideTitlebar_ && titleMode_ == NavigationTitleMode::FREE;
68     }
69     OffsetF GetShowMenuOffset(const RefPtr<BarItemNode> barItemNode, RefPtr<FrameNode> menuNode);
70 
71     float GetTitleBarHeightLessThanMaxBarHeight() const;
72 
73 protected:
74     void OnDetachFromFrameNode(FrameNode* frameNode) override;
75 
76     void MountTitleBar(const RefPtr<FrameNode>& host, bool& needRunTitleBarAnimation);
77 
78 private:
79     void WindowFocus(bool isFocus);
80     void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) override;
81     void OnModifyDone() override;
82     void OnColorConfigurationUpdate() override;
83     void SetNavBarMask(bool isWindowFocus);
84 
85     RefPtr<PanEvent> panEvent_;
86     WeakPtr<FrameNode> scrollableNode_;
87     RefPtr<FrictionMotion> motion_;
88     RefPtr<Animator> controller_;
89     NavigationTitleMode titleMode_ = NavigationTitleMode::FREE;
90     bool isWindowFocus_ = true;
91 };
92 
93 } // namespace OHOS::Ace::NG
94 
95 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_NAV_BAR_PATTERN_H