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_NODE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SYNTAX_FOR_EACH_NODE_H 18 19 #include <cstdint> 20 #include <list> 21 #include <string> 22 #include <type_traits> 23 24 #include "base/utils/macros.h" 25 #include "core/components_ng/base/ui_node.h" 26 #include "core/components_v2/inspector/inspector_constants.h" 27 28 namespace OHOS::Ace::NG { 29 30 class ACE_EXPORT ForEachNode : public UINode { 31 DECLARE_ACE_TYPE(ForEachNode, UINode); 32 33 public: 34 static RefPtr<ForEachNode> GetOrCreateForEachNode(int32_t nodeId); 35 ForEachNode(int32_t nodeId)36 explicit ForEachNode(int32_t nodeId) : UINode(V2::JS_FOR_EACH_ETS_TAG, nodeId) {} 37 ~ForEachNode() override = default; 38 IsAtomicNode()39 bool IsAtomicNode() const override 40 { 41 return false; 42 } 43 44 void CreateTempItems(); 45 46 void CompareAndUpdateChildren(); 47 48 void FlushUpdateAndMarkDirty() override; 49 GetTempIds()50 const std::list<std::string>& GetTempIds() const 51 { 52 return tempIds_; 53 } 54 SetIds(std::list<std::string> && ids)55 void SetIds(std::list<std::string>&& ids) 56 { 57 ids_ = std::move(ids); 58 } 59 60 private: 61 std::list<std::string> ids_; 62 63 // temp items use to compare each update. 64 std::list<std::string> tempIds_; 65 std::list<RefPtr<UINode>> tempChildren_; 66 67 ACE_DISALLOW_COPY_AND_MOVE(ForEachNode); 68 }; 69 70 } // namespace OHOS::Ace::NG 71 72 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SYNTAX_FOR_EACH_NODE_H 73