• 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 "frameworks/bridge/declarative_frontend/jsview/models/if_else_model_impl.h"
17 
18 #include "base/log/ace_trace.h"
19 #include "bridge/declarative_frontend/view_stack_processor.h"
20 #include "core/components/ifelse/if_else_component.h"
21 #include "core/components/ifelse/if_else_element.h"
22 #include "core/components_v2/common/element_proxy.h"
23 
24 namespace OHOS::Ace::Framework {
25 
Create()26 void IfElseModelImpl::Create()
27 {
28     LOGD("IfElse::Create with OG");
29     auto component = AceType::MakeRefPtr<IfElseComponent>(std::string(), "IfElse");
30     ViewStackProcessor::GetInstance()->ClaimElementId(component);
31     ViewStackProcessor::GetInstance()->Push(component);
32 }
33 
Pop()34 void IfElseModelImpl::Pop()
35 {
36     ViewStackProcessor::GetInstance()->PopContainer();
37 }
38 
SetBranchId(int32_t value)39 void IfElseModelImpl::SetBranchId(int32_t value)
40 {
41     auto component = AceType::DynamicCast<IfElseComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
42     component->SetBranchId(value);
43 }
44 
GetBranchId()45 int32_t IfElseModelImpl::GetBranchId()
46 {
47     auto component = AceType::DynamicCast<IfElseComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
48 
49     auto forEachElement = (component != nullptr) ? ElementRegister::GetInstance()->GetSpecificItemById<IfElseElement>(
50                                                        component->GetElementId())
51                                                  : nullptr;
52 
53     return (forEachElement != nullptr) ? forEachElement->GetBranchId() : -1;
54 }
55 
56 } // namespace OHOS::Ace::Framework
57