• 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_SHEET_PRESENTATION_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_SHEET_PRESENTATION_PATTERN_H
18 
19 #include <functional>
20 #include <utility>
21 
22 #include "base/memory/ace_type.h"
23 #include "base/memory/referenced.h"
24 #include "core/components/common/properties/alignment.h"
25 #include "core/components_ng/pattern/linear_layout/linear_layout_algorithm.h"
26 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
27 #include "core/components_ng/pattern/linear_layout/linear_layout_property.h"
28 #include "core/components_ng/pattern/overlay/popup_base_pattern.h"
29 #include "core/components_ng/pattern/overlay/sheet_presentation_property.h"
30 #include "core/components_ng/pattern/overlay/sheet_style.h"
31 
32 namespace OHOS::Ace::NG {
33 class ACE_EXPORT SheetPresentationPattern : public LinearLayoutPattern, public PopupBasePattern {
34     DECLARE_ACE_TYPE(SheetPresentationPattern, LinearLayoutPattern, PopupBasePattern);
35 
36 public:
SheetPresentationPattern(int32_t targetId,std::function<void (const std::string &)> && callback)37     SheetPresentationPattern(int32_t targetId, std::function<void(const std::string&)>&& callback)
38         : LinearLayoutPattern(true)
39     {
40         targetId_ = targetId;
41         callback_ = std::move(callback);
42     }
43 
44     ~SheetPresentationPattern() override = default;
45 
IsMeasureBoundary()46     bool IsMeasureBoundary() const override
47     {
48         return true;
49     }
50 
IsAtomicNode()51     bool IsAtomicNode() const override
52     {
53         return false;
54     }
55 
CreateLayoutAlgorithm()56     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
57     {
58         return MakeRefPtr<LinearLayoutAlgorithm>();
59     }
60 
CreateLayoutProperty()61     RefPtr<LayoutProperty> CreateLayoutProperty() override
62     {
63         return MakeRefPtr<SheetPresentationProperty>();
64     }
65 
GetTargetId()66     int32_t GetTargetId() const
67     {
68         return targetId_;
69     }
70 
FireCallback(const std::string & value)71     void FireCallback(const std::string& value)
72     {
73         if (callback_) {
74             callback_(value);
75         }
76     }
77 
UpdateOnDisappear(std::function<void ()> && onDisappear)78     void UpdateOnDisappear(std::function<void()>&& onDisappear)
79     {
80         onDisappear_ = std::move(onDisappear);
81     }
82 
OnDisappear()83     void OnDisappear()
84     {
85         if (onDisappear_) {
86             onDisappear_();
87         }
88     }
89 
90     void InitialLayoutProps();
91 
92     // initial drag gesture event
93     void InitPanEvent();
94 
95     void HandleDragUpdate(const GestureEvent& info);
96 
97     void HandleDragEnd(float dragVelocity);
98 
99     void SheetTransition(bool isTransitionIn);
100 
SetCurrentOffset(float currentOffset)101     void SetCurrentOffset(float currentOffset)
102     {
103         currentOffset_ = currentOffset;
104     }
105 
GetFocusPattern()106     FocusPattern GetFocusPattern() const override
107     {
108         return { FocusType::SCOPE, true };
109     }
110 
111 private:
112     void OnModifyDone() override;
113     void OnAttachToFrameNode() override;
114     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
115 
116     void InitPageHeight();
117 
118     int32_t targetId_ = -1;
119     std::function<void(const std::string&)> callback_;
120     std::function<void()> onDisappear_;
121     RefPtr<PanEvent> panEvent_;
122     float currentOffset_ = 0.0f;
123     float height_ = 0.0f;
124     float heightBoundary_ = 0.0f;
125     float pageHeight_ = 0.0f;
126 
127     ACE_DISALLOW_COPY_AND_MOVE(SheetPresentationPattern);
128 };
129 } // namespace OHOS::Ace::NG
130 
131 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_SHEET_PRESENTATION_PATTERN_H
132