1 /* 2 * Copyright (c) 2024 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_WATERFLOW_WATER_FLOW_LAYOUT_BASE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WATERFLOW_WATER_FLOW_LAYOUT_BASE_H 18 #include "core/components_ng/base/frame_node.h" 19 #include "core/components_ng/layout/layout_algorithm.h" 20 #include "core/components_ng/pattern/waterflow/layout/water_flow_layout_info_base.h" 21 #include "core/components_ng/property/layout_constraint.h" 22 23 namespace OHOS::Ace::NG { 24 class WaterFlowLayoutBase : public LayoutAlgorithm { 25 DECLARE_ACE_TYPE(WaterFlowLayoutBase, LayoutAlgorithm); 26 27 public: 28 virtual void SetCanOverScroll(bool canOverScroll) = 0; 29 StartCacheLayout()30 virtual void StartCacheLayout() 31 { /* callback when cache layout starts */ 32 } 33 /** 34 * @brief Measure the cache item and append it to a lane. 35 * 36 * @param itemIdx index of the cache item to add. 37 * @param deadline of the preload task. Return early if deadline is reached. 38 * @return true if the item is actually created and appended in lane. 39 */ 40 virtual bool AppendCacheItem(LayoutWrapper* host, int32_t itemIdx, int64_t deadline) = 0; EndCacheLayout()41 virtual void EndCacheLayout() 42 { /* callback when cache layout ends */ 43 } 44 45 protected: 46 /** 47 * @brief Register an IdleTask to preload (create/measure/layout) items in cache range. 48 */ 49 void PreloadItems(LayoutWrapper* host, const RefPtr<WaterFlowLayoutInfoBase>& info, int32_t cacheCount); 50 51 static int32_t GetUpdateIdx(LayoutWrapper* host, int32_t footerIdx); 52 53 private: 54 static std::list<int32_t> GeneratePreloadList( 55 const RefPtr<WaterFlowLayoutInfoBase>& info, LayoutWrapper* host, int32_t cacheCount); 56 static void PostIdleTask(const RefPtr<FrameNode>& frameNode); 57 }; 58 59 enum class WaterFlowLayoutMode { TOP_DOWN = 0, SLIDING_WINDOW = 1 }; 60 } // namespace OHOS::Ace::NG 61 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WATERFLOW_WATER_FLOW_LAYOUT_BASE_H