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 
23 namespace OHOS::Ace::NG {
24 class SheetWrapperPattern : virtual public PopupBasePattern {
25     DECLARE_ACE_TYPE(SheetWrapperPattern, PopupBasePattern);
26 
27 public:
28     SheetWrapperPattern() = default;
29     ~SheetWrapperPattern() override = default;
30 
GetFocusPattern()31     FocusPattern GetFocusPattern() const override
32     {
33         return { FocusType::SCOPE, true };
34     }
35 
CreateLayoutAlgorithm()36     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
37     {
38         return MakeRefPtr<SheetWrapperLayoutAlgorithm>();
39     }
40 
OnAttachToMainTree()41     void OnAttachToMainTree() override
42     {
43         auto host = GetHost();
44         CHECK_NULL_VOID(host);
45         auto rootNode = AceType::DynamicCast<FrameNode>(host->GetParent());
46         CHECK_NULL_VOID(rootNode);
47         if (rootNode->GetTag() != V2::NAVDESTINATION_VIEW_ETS_TAG) {
48             return;
49         }
50         auto wrapperRenderContext = host->GetRenderContext();
51         CHECK_NULL_VOID(wrapperRenderContext);
52         auto navDestinationPattern = rootNode->GetPattern<NavDestinationPattern>();
53         CHECK_NULL_VOID(navDestinationPattern);
54         auto zIndex = navDestinationPattern->GetTitlebarZIndex();
55 
56         // set the sheet to float on the NavDestination's titlebar when the sheet shows in NavDestination
57         wrapperRenderContext->UpdateZIndex(zIndex + 1);
58     }
59 protected:
AvoidKeyboard()60     bool AvoidKeyboard() const override
61     {
62         return false;
63     }
64 
AvoidBottom()65     bool AvoidBottom() const override
66     {
67         return false;
68     }
69 
70 private:
71 
72     ACE_DISALLOW_COPY_AND_MOVE(SheetWrapperPattern);
73 };
74 } // namespace OHOS::Ace::NG
75 
76 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_SHEET_WRAPPER_PATTERN_H
77