• 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
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     }
69 
OnDisappear()70     void OnDisappear() {
71         if (onDisappear_) {
72             onDisappear_();
73         }
74     }
75 
GetFocusPattern()76     FocusPattern GetFocusPattern() const override
77     {
78         return { FocusType::SCOPE, true };
79     }
80 
81 private:
82     void OnAttachToFrameNode() override;
83     int32_t targetId_ = -1;
84     ModalTransition type_ = ModalTransition::DEFAULT;
85     std::function<void(const std::string&)> callback_;
86     std::function<void()> onDisappear_;
87 
88     ACE_DISALLOW_COPY_AND_MOVE(ModalPresentationPattern);
89 };
90 } // namespace OHOS::Ace::NG
91 
92 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_MODAL_PRESENTATION_PATTERN_H
93