• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_MODAL_PRESENTATION_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_MODAL_PRESENTATION_PATTERN_H
18 
19 #include "base/memory/ace_type.h"
20 #include "base/memory/referenced.h"
21 #include "core/components_ng/pattern/overlay/modal_style.h"
22 #include "core/components_ng/pattern/overlay/popup_base_pattern.h"
23 
24 namespace OHOS::Ace::NG {
25 class ACE_EXPORT ModalPresentationPattern : public PopupBasePattern {
26     DECLARE_ACE_TYPE(ModalPresentationPattern, PopupBasePattern);
27 
28 public:
ModalPresentationPattern(int32_t targetId,ModalTransition type,std::function<void (const std::string &)> && callback)29     ModalPresentationPattern(int32_t targetId, ModalTransition type, std::function<void(const std::string&)>&& callback)
30         : targetId_(targetId), type_(type), callback_(std::move(callback))
31     {}
32     ~ModalPresentationPattern() override = default;
33 
IsMeasureBoundary()34     bool IsMeasureBoundary() const override
35     {
36         return true;
37     }
38 
IsAtomicNode()39     bool IsAtomicNode() const override
40     {
41         return false;
42     }
43 
GetTargetId()44     int32_t GetTargetId() const override
45     {
46         return targetId_;
47     }
48 
GetType()49     ModalTransition GetType() const
50     {
51         return type_;
52     }
53 
SetType(ModalTransition type)54     void SetType(ModalTransition type)
55     {
56         type_ = type;
57     }
58 
FireCallback(const std::string & value)59     void FireCallback(const std::string& value)
60     {
61         if (callback_) {
62             callback_(value);
63         }
64     }
65 
UpdateOnDisappear(std::function<void ()> && onDisappear)66     void UpdateOnDisappear(std::function<void()>&& onDisappear) {
67         onDisappear_ = std::move(onDisappear);
68         isExecuteOnDisappear_ = false;
69     }
70 
OnDisappear()71     void OnDisappear() {
72         if (onDisappear_) {
73             isExecuteOnDisappear_ = true;
74             onDisappear_();
75         }
76     }
77 
GetFocusPattern()78     FocusPattern GetFocusPattern() const override
79     {
80         return { FocusType::SCOPE, true };
81     }
82 
IsExecuteOnDisappear()83     bool IsExecuteOnDisappear() const
84     {
85         return isExecuteOnDisappear_;
86     }
87 
AvoidKeyboard()88     bool AvoidKeyboard() const override
89     {
90         // If UIExtensionComponent uses ModalPage, ModalPage will avoid KeyBoard.
91         return isUIExtension_;
92     }
93 
UpdateUIExtensionMode(bool isUIExtension)94     void UpdateUIExtensionMode(bool isUIExtension)
95     {
96         isUIExtension_ = isUIExtension;
97     }
98 
AvoidBottom()99     bool AvoidBottom() const override
100     {
101         // If UIExtensionComponent uses ModalPage, ModalPage will not avoid bottom.
102         return !isUIExtension_;
103     }
104 
105 private:
106     void OnAttachToFrameNode() override;
107     bool isUIExtension_ = false;
108     int32_t targetId_ = -1;
109     ModalTransition type_ = ModalTransition::DEFAULT;
110     std::function<void(const std::string&)> callback_;
111     std::function<void()> onDisappear_;
112     bool isExecuteOnDisappear_ = false;
113 
114     ACE_DISALLOW_COPY_AND_MOVE(ModalPresentationPattern);
115 };
116 } // namespace OHOS::Ace::NG
117 
118 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_MODAL_PRESENTATION_PATTERN_H
119