• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_OVERLAY_SHEET_WRAPPER_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_SHEET_WRAPPER_PATTERN_H
18 
19 #include "core/components_ng/pattern/navrouter/navdestination_pattern.h"
20 #include "core/components_ng/pattern/overlay/popup_base_pattern.h"
21 #include "core/components_ng/pattern/overlay/sheet_wrapper_layout_algorithm.h"
22 #include "core/components_ng/pattern/overlay/sheet_wrapper_paint_method.h"
23 
24 namespace OHOS::Ace::NG {
25 class SheetWrapperPattern : virtual public PopupBasePattern {
26     DECLARE_ACE_TYPE(SheetWrapperPattern, PopupBasePattern);
27 
28 public:
29     SheetWrapperPattern() = default;
30     ~SheetWrapperPattern() override = default;
31 
GetFocusPattern()32     FocusPattern GetFocusPattern() const override
33     {
34         return { FocusType::SCOPE, true };
35     }
36 
CreateLayoutAlgorithm()37     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
38     {
39         return MakeRefPtr<SheetWrapperLayoutAlgorithm>();
40     }
41 
OnAttachToMainTree()42     void OnAttachToMainTree() override
43     {
44         auto host = GetHost();
45         CHECK_NULL_VOID(host);
46         auto rootNode = AceType::DynamicCast<FrameNode>(host->GetParent());
47         CHECK_NULL_VOID(rootNode);
48         if (rootNode->GetTag() != V2::NAVDESTINATION_VIEW_ETS_TAG) {
49             return;
50         }
51         auto wrapperRenderContext = host->GetRenderContext();
52         CHECK_NULL_VOID(wrapperRenderContext);
53         auto navDestinationPattern = rootNode->GetPattern<NavDestinationPattern>();
54         CHECK_NULL_VOID(navDestinationPattern);
55         auto zIndex = navDestinationPattern->GetTitlebarZIndex();
56 
57         // set the sheet to float on the NavDestination's titlebar when the sheet shows in NavDestination
58         wrapperRenderContext->UpdateZIndex(zIndex + 1);
59     }
60 
CreateNodePaintMethod()61     RefPtr<NodePaintMethod> CreateNodePaintMethod() override
62     {
63         return MakeRefPtr<SheetWrapperPaintMethod>();
64     }
65 
66 protected:
AvoidKeyboard()67     bool AvoidKeyboard() const override
68     {
69         return false;
70     }
71 
AvoidBottom()72     bool AvoidBottom() const override
73     {
74         return false;
75     }
76 
77 private:
78 
79     ACE_DISALLOW_COPY_AND_MOVE(SheetWrapperPattern);
80 };
81 } // namespace OHOS::Ace::NG
82 
83 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_SHEET_WRAPPER_PATTERN_H
84