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