• 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 
28 namespace OHOS::Ace::Framework {
29 
30 
Create(const std::string & compilerGenId,const OHOS::Ace::ForEachFunc & ForEachFunc)31 void ForEachModelImpl::Create(const std::string& compilerGenId, const OHOS::Ace::ForEachFunc& ForEachFunc)
32 {
33     if (compilerGenId == "") {
34         LOGE("Missing ForEach id");
35         return;
36     }
37     if (!ForEachFunc.idGenFunc_ || !ForEachFunc.itemGenFunc_) {
38         LOGE("for each func is nullptr");
39         return;
40     }
41 
42     auto* viewStack = ViewStackProcessor::GetInstance();
43     std::string viewId = viewStack->ProcessViewId(compilerGenId);
44     viewStack->Push(AceType::MakeRefPtr<ForEachComponent>(viewId, "ForEach"));
45 
46     std::vector<std::string> keys = ForEachFunc.idGenFunc_();
47     for (size_t i = 0; i < keys.size(); i++) {
48         keys[i].insert(0, "-");
49         keys[i].insert(0, compilerGenId);
50         viewStack->PushKey(keys[i]);
51 
52         viewStack->Push(AceType::MakeRefPtr<MultiComposedComponent>(viewStack->GetKey(), "ForEachItem"));
53         ForEachFunc.itemGenFunc_(i);
54         viewStack->PopContainer();
55         viewStack->PopKey();
56     }
57 }
58 
Create()59 void ForEachModelImpl::Create() {
60     LOGE("Create (no params) unsupported by ForEachModelImpl");
61 }
62 
Pop()63 void ForEachModelImpl::Pop()
64 {
65     ViewStackProcessor::GetInstance()->PopContainer();
66 }
67 
GetCurrentIdList(int32_t nodeId)68 std::list<std::string> ForEachModelImpl::GetCurrentIdList(int32_t nodeId)
69 {
70     LOGE("GetCurrentIdList unsupported by ForEachModelImpl");
71     return {};
72 }
73 
SetNewIds(std::list<std::string> && newIds)74 void ForEachModelImpl::SetNewIds(std::list<std::string>&& newIds)
75 {
76     LOGE("SetNewIds unsupported by ForEachModelImpl");
77 }
78 
CreateNewChildStart(const std::string & id)79 void ForEachModelImpl::CreateNewChildStart(const std::string& id)
80 {
81     LOGE("CreateNewChildStart unsupported by ForEachModelImpl");
82 }
83 
CreateNewChildFinish(const std::string & id)84 void ForEachModelImpl::CreateNewChildFinish(const std::string& id)
85 {
86     LOGE("CreateNewChildFinish unsupported by ForEachModelImpl");
87 }
88 
89 } // namespace OHOS::Ace::Framework
90