• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SYNTAX_FOR_EACH_FOR_EACH_MODEL_NG_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SYNTAX_FOR_EACH_FOR_EACH_MODEL_NG_H
18 
19 #include "base/memory/ace_type.h"
20 #include "base/utils/macros.h"
21 #include "core/components_ng/base/view_stack_processor.h"
22 #include "core/components_ng/syntax/lazy_for_each_builder.h"
23 #include "core/components_ng/syntax/lazy_for_each_model.h"
24 #include "core/components_ng/syntax/lazy_for_each_node.h"
25 
26 namespace OHOS::Ace::NG {
27 class ACE_EXPORT LazyForEachModelNG : public LazyForEachModel {
28 public:
Create(const RefPtr<LazyForEachActuator> & actuator)29     void Create(const RefPtr<LazyForEachActuator>& actuator) override
30     {
31         auto builder = AceType::DynamicCast<LazyForEachBuilder>(actuator);
32         Create(builder);
33     }
34 
OnMove(std::function<void (int32_t,int32_t)> && onMove)35     void OnMove(std::function<void(int32_t, int32_t)>&& onMove) override
36     {
37         auto* stack = ViewStackProcessor::GetInstance();
38         auto node = AceType::DynamicCast<LazyForEachNode>(stack->GetMainElementNode());
39         CHECK_NULL_VOID(node);
40         node->SetOnMove(std::move(onMove));
41     }
42 
SetItemDragHandler(std::function<void (int32_t)> && onLongPress,std::function<void (int32_t)> && onDragStart,std::function<void (int32_t,int32_t)> && onMoveThrough,std::function<void (int32_t)> && onDrop)43     void SetItemDragHandler(std::function<void(int32_t)>&& onLongPress, std::function<void(int32_t)>&& onDragStart,
44         std::function<void(int32_t, int32_t)>&& onMoveThrough, std::function<void(int32_t)>&& onDrop) override
45     {
46         auto* stack = ViewStackProcessor::GetInstance();
47         auto node = AceType::DynamicCast<LazyForEachNode>(stack->GetMainElementNode());
48         CHECK_NULL_VOID(node);
49         node->SetItemDragHandler(
50             std::move(onLongPress), std::move(onDragStart), std::move(onMoveThrough), std::move(onDrop));
51     }
52 
53 private:
Create(const RefPtr<LazyForEachBuilder> & forEachBuilder)54     void Create(const RefPtr<LazyForEachBuilder>& forEachBuilder)
55     {
56         auto* stack = ViewStackProcessor::GetInstance();
57         auto nodeId = stack->ClaimNodeId();
58 
59         if (stack->GetMainFrameNode() && stack->GetMainFrameNode()->GetTag() == V2::TABS_ETS_TAG) {
60             forEachBuilder->ExpandChildrenOnInitial();
61             return;
62         }
63 
64         auto lazyForEach = LazyForEachNode::GetOrCreateLazyForEachNode(nodeId, forEachBuilder);
65         stack->Push(lazyForEach);
66     }
67 };
68 } // namespace OHOS::Ace::NG
69 
70 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SYNTAX_FOR_EACH_FOR_EACH_MODEL_NG_H
71