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 #include "frameworks/bridge/declarative_frontend/jsview/models/ability_component_model_impl.h" 17 18 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h" 19 20 namespace OHOS::Ace::Framework { Create(const std::string & bundleName,const std::string & abilityName)21void AbilityComponentModelImpl::Create(const std::string& bundleName, const std::string& abilityName) 22 { 23 auto abilityComponent = AceType::MakeRefPtr<OHOS::Ace::V2::AbilityComponent>(); 24 ViewStackProcessor::GetInstance()->ClaimElementId(abilityComponent); 25 ViewStackProcessor::GetInstance()->Push(abilityComponent); 26 } 27 GetComponent()28RefPtr<OHOS::Ace::V2::AbilityComponent> AbilityComponentModelImpl::GetComponent() 29 { 30 auto* stack = ViewStackProcessor::GetInstance(); 31 if (!stack) { 32 return nullptr; 33 } 34 auto component = AceType::DynamicCast<OHOS::Ace::V2::AbilityComponent>(stack->GetMainComponent()); 35 return component; 36 } 37 SetWant(const std::string & want)38void AbilityComponentModelImpl::SetWant(const std::string& want) 39 { 40 auto component = GetComponent(); 41 CHECK_NULL_VOID(component); 42 43 component->SetWant(want); 44 } 45 SetWidth(Dimension value)46void AbilityComponentModelImpl::SetWidth(Dimension value) 47 { 48 auto component = GetComponent(); 49 CHECK_NULL_VOID(component); 50 51 component->SetWidth(value); 52 } 53 SetHeight(Dimension value)54void AbilityComponentModelImpl::SetHeight(Dimension value) 55 { 56 auto component = GetComponent(); 57 CHECK_NULL_VOID(component); 58 59 component->SetHeight(value); 60 } 61 SetOnConnect(std::function<void ()> && onConnect)62void AbilityComponentModelImpl::SetOnConnect(std::function<void()>&& onConnect) 63 { 64 auto component = GetComponent(); 65 CHECK_NULL_VOID(component); 66 component->SetOnConnected(std::move(onConnect)); 67 } 68 SetOnDisConnect(std::function<void ()> && onDisConnect)69void AbilityComponentModelImpl::SetOnDisConnect(std::function<void()>&& onDisConnect) 70 { 71 auto component = GetComponent(); 72 CHECK_NULL_VOID(component); 73 component->SetOnDisconnected(std::move(onDisConnect)); 74 } 75 76 } // namespace OHOS::Ace::Framework 77