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()26void IfElseModelImpl::Create() 27 { 28 auto component = AceType::MakeRefPtr<IfElseComponent>(std::string(), "IfElse"); 29 ViewStackProcessor::GetInstance()->ClaimElementId(component); 30 ViewStackProcessor::GetInstance()->Push(component); 31 } 32 Pop()33void IfElseModelImpl::Pop() 34 { 35 ViewStackProcessor::GetInstance()->PopContainer(); 36 } 37 SetBranchId(int32_t value,std::list<int32_t> & removedElmtId)38void IfElseModelImpl::SetBranchId(int32_t value, std::list<int32_t>& removedElmtId) 39 { 40 auto component = AceType::DynamicCast<IfElseComponent>(ViewStackProcessor::GetInstance()->GetMainComponent()); 41 component->SetBranchId(value); 42 } 43 GetBranchId()44int32_t IfElseModelImpl::GetBranchId() 45 { 46 auto component = AceType::DynamicCast<IfElseComponent>(ViewStackProcessor::GetInstance()->GetMainComponent()); 47 48 auto forEachElement = (component != nullptr) ? ElementRegister::GetInstance()->GetSpecificItemById<IfElseElement>( 49 component->GetElementId()) 50 : nullptr; 51 52 return (forEachElement != nullptr) ? forEachElement->GetBranchId() : -1; 53 } 54 55 } // namespace OHOS::Ace::Framework 56