1 /* 2 * Copyright (c) 2021 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_PANEL_RENDER_SLIDING_PANEL_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PANEL_RENDER_SLIDING_PANEL_H 18 19 #include "core/animation/animator.h" 20 #include "core/components/box/render_box.h" 21 #include "core/components/drag_bar/render_drag_bar.h" 22 #include "core/components/panel/sliding_panel_component.h" 23 #include "core/components/scroll/render_single_child_scroll.h" 24 #include "core/gestures/click_recognizer.h" 25 #include "core/gestures/drag_recognizer.h" 26 #include "core/pipeline/base/render_node.h" 27 28 namespace OHOS::Ace { 29 30 class RenderSlidingPanel : public RenderNode { 31 DECLARE_ACE_TYPE(RenderSlidingPanel, RenderNode); 32 33 public: 34 static RefPtr<RenderNode> Create(); 35 void Update(const RefPtr<Component>& component) override; 36 void OnPaintFinish() override; 37 void PerformLayout() override; 38 bool TouchTest(const Point& globalPoint, const Point& parentLocalPoint, const TouchRestrict& touchRestrict, 39 TouchTestResult& result) override; 40 41 void ResetContentHeight(); 42 void OnAnimationStop(); 43 GetBlankHeight()44 double GetBlankHeight() const 45 { 46 return blankHeight_; 47 } 48 GetDragBar()49 const RefPtr<RenderDragBar>& GetDragBar() const 50 { 51 return dragBar_; 52 } 53 54 // used for inspector node in PC preview GetPanelId()55 int32_t GetPanelId() const 56 { 57 return panelId_; 58 } 59 SetPanelId(int32_t panelId)60 void SetPanelId(int32_t panelId) 61 { 62 panelId_ = panelId; 63 } 64 GetPanelType()65 PanelType GetPanelType() const 66 { 67 return type_; 68 } 69 GetPanelMode()70 PanelMode GetPanelMode() const 71 { 72 return mode_; 73 } 74 HasDragBar()75 bool HasDragBar() const 76 { 77 if (dragBar_) { 78 return true; 79 } 80 return false; 81 } 82 GetFullHeight()83 const Dimension& GetFullHeight() const 84 { 85 return fullHeight_.first; 86 } 87 GetHalfHeight()88 const Dimension& GetHalfHeight() const 89 { 90 return halfHeight_.first; 91 } 92 GetMiniHeight()93 const Dimension& GetMiniHeight() const 94 { 95 return miniHeight_.first; 96 } 97 98 void UpdateTouchRect() override; 99 100 void Dump() override; 101 102 void LiftPanelForVirtualKeyboard(double offsetY); 103 104 void UpdatePanelHeightByCurrentMode(); 105 GetOnHeightChange()106 const std::function<void(int32_t)>& GetOnHeightChange() const 107 { 108 return onHeightChange_; 109 } 110 SetOnHeightChange(std::function<void (int32_t)> & onHeightChange)111 void SetOnHeightChange(std::function<void(int32_t)>& onHeightChange) 112 { 113 onHeightChange_ = onHeightChange; 114 } 115 116 protected: 117 void OnTouchTestHit( 118 const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override; 119 120 RefPtr<RenderDragBar> dragBar_; 121 double blankHeight_ = 0.0; 122 PanelMode mode_ = PanelMode::FULL; 123 PanelMode previousMode_ = PanelMode::HALF; 124 PanelType type_ = PanelType::FOLDABLE_BAR; 125 bool hasBoxStyle_ = false; 126 std::function<void(const std::shared_ptr<BaseEventInfo>&)> onSizeChange_; 127 std::function<void(int32_t)> onHeightChange_; 128 129 private: 130 void InitializeRecognizer(); 131 bool InitializeLayoutProps(); 132 void SetDragBarCallBack(); 133 void FireSizeChangeEvent(); 134 void FireHeightChangeEvent(); 135 void HandleDragStart(const Offset& startPoint); 136 void HandleDragUpdate(const Offset& currentPoint); 137 void HandleDragEnd(const Offset& endPoint, double velocity); 138 void CalculateModeTypeMini(double dragLen, double velocity); 139 void CalculateModeTypeFold(double dragLen, double velocity); 140 void CalculateModeTypeTemp(double dragLen, double velocity); 141 void AnimateTo(double blankHeight, PanelMode mode); 142 void AppendBlankHeightAnimation(double blankHeight, PanelMode mode); 143 void InnerLayout(); 144 void CheckHeightValidity(); 145 146 RefPtr<RenderNode> boxForBlank_; 147 RefPtr<Animator> animator_; 148 RefPtr<DragRecognizer> dragDetector_; 149 std::unordered_map<PanelMode, double> defaultBlankHeights_; 150 double minBlankHeight_ = 0.0; 151 bool isFirstUpdate_ = true; 152 bool isFirstLayout_ = true; 153 Offset dragStartPoint_; 154 double dragStartBlankHeight_ = 0.0; 155 bool isAnimating_ = false; 156 double fullHalfBoundary_ = 0.0; 157 double halfMiniBoundary_ = 0.0; 158 double fullMiniBoundary_ = 0.0; 159 bool visible = false; 160 // used for inspector node in PC preview 161 int32_t panelId_ = -1; 162 std::pair<Dimension, bool> miniHeight_ = { 0.0_vp, false }; 163 std::pair<Dimension, bool> halfHeight_ = { 0.0_vp, false }; 164 std::pair<Dimension, bool> fullHeight_ = { 0.0_vp, false }; 165 Size previousSize_; 166 }; 167 168 } // namespace OHOS::Ace 169 170 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PANEL_RENDER_SLIDING_PANEL_H 171