• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <string>
17 
18 #include "bridge/declarative_frontend/jsview/models/for_each_model_impl.h"
19 
20 #include "base/memory/referenced.h"
21 #include "bridge/declarative_frontend/engine/functions/js_foreach_function.h"
22 #include "bridge/declarative_frontend/view_stack_processor.h"
23 #include "core/components/foreach/for_each_component.h"
24 #include "core/components_part_upd/foreach/foreach_component.h"
25 #include "core/components_part_upd/foreach/foreach_element.h"
26 #include "core/components_v2/common/element_proxy.h"
27 #include "uicast_interface/uicast_impl.h"
28 
29 namespace OHOS::Ace::Framework {
30 
31 
Create(const std::string & compilerGenId,const OHOS::Ace::ForEachFunc & ForEachFunc)32 void ForEachModelImpl::Create(const std::string& compilerGenId, const OHOS::Ace::ForEachFunc& ForEachFunc)
33 {
34     if (compilerGenId == "") {
35         LOGE("Missing ForEach id");
36         return;
37     }
38     if (!ForEachFunc.idGenFunc_ || !ForEachFunc.itemGenFunc_) {
39         LOGE("for each func is nullptr");
40         return;
41     }
42 
43     auto* viewStack = ViewStackProcessor::GetInstance();
44     std::string viewId = viewStack->ProcessViewId(compilerGenId);
45     viewStack->Push(AceType::MakeRefPtr<ForEachComponent>(viewId, "ForEach"));
46 
47     std::vector<std::string> keys = ForEachFunc.idGenFunc_();
48     {
49         UICastImpl::CacheCmd("UICast::ForEach::start", viewId);
50     }
51     for (size_t i = 0; i < keys.size(); i++) {
52         keys[i].insert(0, "-");
53         keys[i].insert(0, compilerGenId);
54         {
55             UICastImpl::CacheCmd("UICast::ForEachItem::start", keys[i]);
56         }
57         viewStack->PushKey(keys[i]);
58 
59         viewStack->Push(AceType::MakeRefPtr<MultiComposedComponent>(viewStack->GetKey(), "ForEachItem"));
60         ForEachFunc.itemGenFunc_(i);
61         {
62             UICastImpl::CacheCmd("UICast::ForEachItem::end");
63         }
64         viewStack->PopContainer();
65         viewStack->PopKey();
66     }
67 }
68 
Create()69 void ForEachModelImpl::Create() {
70     LOGE("Create (no params) unsupported by ForEachModelImpl");
71 }
72 
Pop()73 void ForEachModelImpl::Pop()
74 {
75     ViewStackProcessor::GetInstance()->PopContainer();
76 }
77 
GetCurrentIdList(int32_t nodeId)78 const std::list<std::string>& ForEachModelImpl::GetCurrentIdList(int32_t nodeId)
79 {
80     LOGE("GetCurrentIdList unsupported by ForEachModelImpl");
81     return {};
82 }
83 
SetNewIds(std::list<std::string> && newIds)84 void ForEachModelImpl::SetNewIds(std::list<std::string>&& newIds)
85 {
86     LOGE("SetNewIds unsupported by ForEachModelImpl");
87 }
88 
CreateNewChildStart(const std::string & id)89 void ForEachModelImpl::CreateNewChildStart(const std::string& id)
90 {
91     LOGE("CreateNewChildStart unsupported by ForEachModelImpl");
92 }
93 
CreateNewChildFinish(const std::string & id)94 void ForEachModelImpl::CreateNewChildFinish(const std::string& id)
95 {
96     LOGE("CreateNewChildFinish unsupported by ForEachModelImpl");
97 }
98 
99 } // namespace OHOS::Ace::Framework
100