• 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_DRAG_BAR_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_SHEET_DRAG_BAR_PATTERN_H
18 
19 #include <optional>
20 
21 #include "base/geometry/axis.h"
22 #include "base/memory/referenced.h"
23 #include "core/components/common/layout/constants.h"
24 #include "core/components_ng/event/event_hub.h"
25 #include "core/components_ng/pattern/overlay/sheet_drag_bar_paint_method.h"
26 #include "core/components_ng/pattern/overlay/sheet_drag_bar_paint_property.h"
27 #include "core/components_ng/pattern/pattern.h"
28 
29 namespace OHOS::Ace::NG {
30 using ClickArrowCallback = std::function<void()>;
31 
32 class ACE_EXPORT SheetDragBarPattern : public Pattern {
33     DECLARE_ACE_TYPE(SheetDragBarPattern, Pattern);
34 
35 public:
36     SheetDragBarPattern() = default;
37     ~SheetDragBarPattern() override = default;
38 
CreatePaintProperty()39     RefPtr<PaintProperty> CreatePaintProperty() override
40     {
41         return MakeRefPtr<SheetDragBarPaintProperty>();
42     }
43 
CreateNodePaintMethod()44     RefPtr<NodePaintMethod> CreateNodePaintMethod() override
45     {
46         return MakeRefPtr<SheetDragBarPaintMethod>();
47     }
48 
HasClickArrowCallback()49     bool HasClickArrowCallback() const
50     {
51         return (clickArrowCallback_ != nullptr);
52     }
53 
SetClickArrowCallback(const ClickArrowCallback & callback)54     void SetClickArrowCallback(const ClickArrowCallback& callback)
55     {
56         clickArrowCallback_ = callback;
57     }
58 
59     void UpdateDrawPoint();
60 
61     void ScaleAnimation(bool isDown);
62     void HandleTouchEvent(const TouchEventInfo& info);
63     void HandleTouchDown(const TouchLocationInfo& info);
64     void HandleTouchMove(const TouchLocationInfo& info);
65     void HandleTouchUp();
66     void MarkDirtyNode(PropertyChangeFlag extraFlag);
67 
68 private:
69     void OnModifyDone() override;
70     void OnAttachToFrameNode() override;
71 
72     void InitClickEvent();
73     void InitTouchEvent(const RefPtr<GestureEventHub>& gestureHub);
74     void OnClick();
75 
76     RefPtr<TouchEventImpl> touchEvent_;
77     RefPtr<ClickEvent> clickListener_;
78 
79     OffsetF dragOffset_;
80     OffsetF downPoint_;
81     float dragOffsetX_ = 0.0f;
82     float dragOffsetY_ = 0.0f;
83 
84     ClickArrowCallback clickArrowCallback_;
85 
86     ACE_DISALLOW_COPY_AND_MOVE(SheetDragBarPattern);
87 };
88 } // namespace OHOS::Ace::NG
89 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_SHEET_DRAG_BAR_PATTERN_H