1 /* 2 * Copyright (c) 2022 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_PATTERN_PANEL_DRAG_BAR_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PANEL_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/panel/drag_bar_layout_algorithm.h" 26 #include "core/components_ng/pattern/panel/drag_bar_layout_property.h" 27 #include "core/components_ng/pattern/panel/drag_bar_paint_method.h" 28 #include "core/components_ng/pattern/panel/drag_bar_paint_property.h" 29 #include "core/components_ng/pattern/pattern.h" 30 31 namespace OHOS::Ace::NG { 32 33 using ClickArrowCallback = std::function<void()>; 34 35 class DragBarPattern : public Pattern { 36 DECLARE_ACE_TYPE(DragBarPattern, Pattern); 37 38 public: 39 DragBarPattern() = default; 40 ~DragBarPattern() override = default; 41 CreateLayoutProperty()42 RefPtr<LayoutProperty> CreateLayoutProperty() override 43 { 44 return MakeRefPtr<DragBarLayoutProperty>(); 45 } 46 CreateLayoutAlgorithm()47 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 48 { 49 auto layoutAlgorithm = MakeRefPtr<DragBarLayoutAlgorithm>(); 50 iconOffset_ = layoutAlgorithm->GetIconOffset(); 51 return layoutAlgorithm; 52 } 53 CreatePaintProperty()54 RefPtr<PaintProperty> CreatePaintProperty() override 55 { 56 return MakeRefPtr<DragBarPaintProperty>(); 57 } 58 CreateNodePaintMethod()59 RefPtr<NodePaintMethod> CreateNodePaintMethod() override 60 { 61 auto paintMethod = MakeRefPtr<DragBarPaintMethod>(); 62 paintMethod->SetIconOffset(iconOffset_); 63 paintMethod->SetScaleWidth(scaleWidth_); 64 paintMethod->SetPanelMode(showMode_); 65 return paintMethod; 66 } 67 GetPanelMode()68 PanelMode GetPanelMode() const 69 { 70 return showMode_; 71 } 72 GetStatusBarHeight()73 float GetStatusBarHeight() const 74 { 75 return statusBarHeight_.Value(); 76 } 77 HasClickArrowCallback()78 bool HasClickArrowCallback() const 79 { 80 return (clickArrowCallback_ != nullptr); 81 } 82 SetClickArrowCallback(const ClickArrowCallback & callback)83 void SetClickArrowCallback(const ClickArrowCallback& callback) 84 { 85 clickArrowCallback_ = callback; 86 } 87 SetIsFirstUpdate(bool isFirstUpdate)88 void SetIsFirstUpdate(bool isFirstUpdate) 89 { 90 isFirstUpdate_ = isFirstUpdate; 91 } 92 93 void InitProps(); 94 void ShowArrow(bool show); 95 void ShowInPanelMode(PanelMode mode); 96 void UpdateDrawPoint(); 97 98 void HandleTouchEvent(const TouchEventInfo& info); 99 void HandleTouchDown(const TouchLocationInfo& info); 100 void HandleTouchMove(const TouchLocationInfo& info); 101 void HandleTouchUp(); 102 void MarkDirtyNode(PropertyChangeFlag extraFlag); 103 104 private: 105 void OnModifyDone() override; 106 void OnAttachToFrameNode() override; 107 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 108 109 void InitClickEvent(); 110 void InitTouchEvent(const RefPtr<GestureEventHub>& gestureHub); 111 void OnClick(); 112 void DoStyleAnimation( 113 const OffsetT<Dimension>& left, const OffsetT<Dimension>& center, const OffsetT<Dimension>& right); 114 115 RefPtr<TouchEventImpl> touchEvent_; 116 RefPtr<ClickEvent> clickListener_; 117 OffsetF iconOffset_; 118 OffsetF barLeftPoint_; 119 OffsetF barCenterPoint_; 120 OffsetF barRightPoint_; 121 122 Dimension statusBarHeight_ = 0.0_vp; // height in vp 123 OffsetF dragOffset_; 124 OffsetF downPoint_; 125 float dragRangeX_ = 0.0f; 126 float dragRangeY_ = 0.0f; 127 float scaleWidth_ = 1.0f; 128 129 PanelMode showMode_ = PanelMode::HALF; 130 bool isFirstUpdate_ = true; 131 ClickArrowCallback clickArrowCallback_; 132 133 RefPtr<Animator> animator_; 134 RefPtr<Animator> barTouchAnimator_; 135 RefPtr<Animator> barRangeAnimator_; 136 RefPtr<Animator> barStyleAnimator_; 137 138 ACE_DISALLOW_COPY_AND_MOVE(DragBarPattern); 139 }; 140 141 } // namespace OHOS::Ace::NG 142 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PANEL_DRAG_BAR_PATTERN_H