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_PICKER_RENDER_PICKER_COLUMN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_RENDER_PICKER_COLUMN_H 18 19 #include "core/animation/animator.h" 20 #include "core/animation/curve_animation.h" 21 #include "core/common/vibrator/vibrator_proxy.h" 22 #include "core/components/clip/render_clip.h" 23 #include "core/components/display/render_display.h" 24 #include "core/components/flex/render_flex.h" 25 #include "core/components/picker/picker_column_component.h" 26 #include "core/components/picker/render_picker_option.h" 27 #include "core/components/scroll/render_scroll.h" 28 #include "core/gestures/drag_recognizer.h" 29 #include "core/pipeline/base/render_node.h" 30 31 namespace OHOS::Ace { 32 33 class RenderPickerColumn : public RenderNode { 34 DECLARE_ACE_TYPE(RenderPickerColumn, RenderNode); 35 36 public: 37 static RefPtr<RenderNode> Create(); 38 39 void Update(const RefPtr<Component>& component) override; 40 void PerformLayout() override; 41 IsUseOnly()42 bool IsUseOnly() override 43 { 44 return true; 45 } 46 UpdateOffset(double value)47 void UpdateOffset(double value) 48 { 49 xOffset_ = value; 50 MarkNeedLayout(); 51 } 52 GetXOffset()53 double GetXOffset() const 54 { 55 return xOffset_; 56 } 57 UpdateColumnOpacity(double value)58 void UpdateColumnOpacity(double value) 59 { 60 if (display_) { 61 display_->UpdateOpacity(static_cast<uint8_t>(value)); 62 } 63 } 64 65 bool RotationTest(const RotationEvent& event) override; 66 67 bool HandleScroll(bool isDown); 68 bool HandleFinished(bool success); 69 void HandleFocus(bool focus); 70 71 std::string GetColumnTag() const; 72 73 uint32_t GetWidthRatio() const; 74 75 void FlushCurrentOptions(); 76 77 void UpdateRenders(); 78 SetAdjustHeight(double value)79 void SetAdjustHeight(double value) 80 { 81 adjustHeight_ = value; 82 } 83 OnPaintFinish()84 void OnPaintFinish() override 85 { 86 UpdateAccessibility(); 87 } 88 GetFlexColumn()89 const RefPtr<RenderFlex>& GetFlexColumn() const 90 { 91 return column_; 92 } 93 94 void UpdateToss(double y); 95 96 void TossStoped(); 97 GetInnerColumnGlobalOffset()98 Offset GetInnerColumnGlobalOffset() const 99 { 100 if (!column_) { 101 return Offset(); 102 } 103 return column_->GetGlobalOffset(); 104 } 105 IsFocused()106 bool IsFocused() const 107 { 108 return focused_; 109 } 110 GetOptions()111 const std::vector<RefPtr<RenderPickerOption>>& GetOptions() const 112 { 113 return options_; 114 } 115 116 protected: 117 void OnTouchTestHit( 118 const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override; 119 120 private: 121 void HandleDragStart(const GestureEvent& event); 122 void HandleDragMove(const GestureEvent& event); 123 void HandleDragEnd(); 124 void GetRenders(const RefPtr<RenderNode>& render); 125 void GetRenders(); 126 void ClearRenders(); 127 void ScrollOption(double delta); 128 129 void CreateAnimation(); 130 RefPtr<CurveAnimation<double>> CreateAnimation(double from, double to); 131 void HandleCurveStopped(); 132 bool InnerHandleScroll(bool isDown); 133 134 void LayoutSplitter(); 135 136 void UpdateAccessibility(); 137 138 bool NotLoopOptions() const; 139 bool CanMove(bool isDown) const; 140 141 void UpdatePositionY(double y); 142 143 RefPtr<RenderClip> clip_; 144 RefPtr<RenderFlex> column_; 145 RefPtr<RenderDisplay> display_; 146 RefPtr<RenderText> splitter_; 147 std::vector<RefPtr<RenderPickerOption>> options_; 148 149 RefPtr<PickerColumnComponent> data_; 150 151 bool focused_ = false; 152 double rotateAngle_ = 0.0; 153 double rotateInterval_ = 0.0; 154 155 bool nodeHandlerSetted_ = false; 156 157 RefPtr<RawRecognizer> rawRecognizer_; 158 RefPtr<VerticalDragRecognizer> dragRecognizer_; 159 RefPtr<PanRecognizer> panRecognizer_; 160 double xOffset_ = 0.0; 161 double yOffset_ = 0.0; 162 double yLast_ = 0.0; 163 bool pressed_ = false; 164 Dimension jumpInterval_; 165 Dimension columnMargin_; 166 167 double adjustHeight_ = 0.0; 168 double scrollDelta_ = 0.0; 169 bool animationCreated_ = false; 170 RefPtr<Animator> toController_; 171 RefPtr<Animator> fromController_; 172 RefPtr<CurveAnimation<double>> toBottomCurve_; 173 RefPtr<CurveAnimation<double>> toTopCurve_; 174 RefPtr<CurveAnimation<double>> fromBottomCurve_; 175 RefPtr<CurveAnimation<double>> fromTopCurve_; 176 177 RefPtr<Vibrator> vibrator_; 178 bool needVibrate_ = true; 179 }; 180 181 } // namespace OHOS::Ace 182 183 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_RENDER_PICKER_COLUMN_H 184