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 HandleTouchUp();
65     void MarkDirtyNode(PropertyChangeFlag extraFlag);
66 
67 private:
68     void OnModifyDone() override;
69     void OnAttachToFrameNode() override;
70 
71     void InitClickEvent();
72     void InitTouchEvent(const RefPtr<GestureEventHub>& gestureHub);
73     void OnClick();
74     void CreatePropertyCallback();
75     void StopAnimation();
76 
77     RefPtr<TouchEventImpl> touchEvent_;
78     RefPtr<ClickEvent> clickListener_;
79 
80     OffsetF dragOffset_;
81     OffsetF downPoint_;
82     float dragOffsetX_ = 0.0f;
83     float dragOffsetY_ = 0.0f;
84     bool isDown_ = false;
85 
86     ClickArrowCallback clickArrowCallback_;
87 
88     RefPtr<NodeAnimatablePropertyFloat> property_;
89 
90     ACE_DISALLOW_COPY_AND_MOVE(SheetDragBarPattern);
91 };
92 } // namespace OHOS::Ace::NG
93 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_SHEET_DRAG_BAR_PATTERN_H