1 /* 2 * Copyright (c) 2021-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_V2_INDEXER_RENDER_POPUP_LIST_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_INDEXER_RENDER_POPUP_LIST_H 18 19 #include "core/components/scroll/scroll_edge_effect.h" 20 #include "core/components/scroll/scrollable.h" 21 #include "core/components_v2/indexer/indexer_event_info.h" 22 #include "core/components_v2/indexer/popup_list_component.h" 23 #include "core/components_v2/indexer/render_popup_list_item.h" 24 #include "core/gestures/raw_recognizer.h" 25 #include "core/pipeline/base/render_node.h" 26 27 namespace OHOS::Ace::V2 { 28 inline constexpr size_t INVALID_POPUP_INDEX = std::numeric_limits<size_t>::max(); 29 inline constexpr int32_t INVALID_POPUP_SELECTED = -1; 30 inline constexpr size_t POPUP_ITEM_VIEW_MAX_COUNT = 5; // not support scroll now. 31 inline constexpr int32_t POPUP_ITEM_VIEW_LAST_POS = POPUP_ITEM_VIEW_MAX_COUNT - 1; 32 inline constexpr int32_t POPUP_ITEM_VIEW_CONTENT_MAX_COUNT = 7; 33 inline constexpr int32_t POPUP_ITEM_DATA_MAX_COUNT = 50; // the part which over 50 abandoned immediate 34 35 class RenderPopupList : public RenderNode { 36 DECLARE_ACE_TYPE(V2::RenderPopupList, RenderNode); 37 38 public: 39 using OnPopupSelectedFunc = std::function<void(std::shared_ptr<IndexerEventInfo>&)>; 40 static RefPtr<RenderNode> Create(); 41 42 RenderPopupList() = default; 43 ~RenderPopupList() = default; 44 45 void Update(const RefPtr<Component>& component) override; 46 void PerformLayout() override; 47 bool TouchTest(const Point& globalPoint, const Point& parentLocalPoint, const TouchRestrict& touchRestrict, 48 TouchTestResult& result) override; 49 void OnTouchTestHit( 50 const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override; 51 52 void OnRequestPopupDataSelected(std::vector<std::string>& data); 53 void OnPopupSelected(int32_t selected) const; 54 55 protected: 56 std::list<RefPtr<RenderPopupListItem>> items_; 57 RefPtr<RenderBox> renderBox_; 58 59 private: 60 void CalTouchPoint(const Point& globalPoint, int32_t& selected); 61 double ApplyLayoutParam(); 62 double LayoutOrRecycleCurrentItems(const LayoutParam& layoutParam); 63 RefPtr<RenderPopupListItem> RequestAndLayoutNewItem(size_t index, const LayoutParam& layoutParam); 64 void CalculateMainScrollExtent(double curMainPos); 65 void SetItemsPosition(); 66 double GetCurrentPosition() const; 67 bool IsOutOfBoundary() const; 68 69 // receive callback of srcoll and update position 70 void AdjustOffset(Offset& delta, int32_t source); 71 bool UpdateScrollPosition(double offset, int32_t source); 72 73 // scroll effect 74 void ResetEdgeEffect(); 75 void SetEdgeEffectAttribute(); 76 77 size_t startIndex_ = 0; 78 int32_t popupSelected_ = INVALID_POPUP_SELECTED; 79 bool reachStart_ = false; 80 bool reachEnd_ = false; 81 bool isOutOfBoundary_ = false; 82 double viewPortHeight_ = 0.0; 83 double viewPortWidth_ = 0.0; 84 double startMainPos_ = 0.0; 85 double endMainPos_ = 0.0; 86 double currentOffset_ = 0.0; 87 double mainScrollExtent_ = 0.0; 88 RefPtr<Scrollable> scrollable_; 89 RefPtr<ScrollEdgeEffect> scrollEffect_; 90 RefPtr<PopupListComponent> component_; 91 RefPtr<BoxComponent> boxComponent_; 92 std::vector<std::string> datas_; 93 94 OnPopupSelectedFunc popupSelectedEventFun_; 95 96 ACE_DISALLOW_COPY_AND_MOVE(RenderPopupList); 97 }; 98 } // namespace OHOS::Ace::V2 99 100 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_INDEXER_RENDER_POPUP_LIST_H 101