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 "core/pipeline/base/composed_component.h"
17
18 #include "core/pipeline/base/composed_element.h"
19
20 namespace OHOS::Ace {
21
ComposedComponent(const ComposeId & id,const std::string & name,const RefPtr<Component> & child)22 ComposedComponent::ComposedComponent(const ComposeId& id, const std::string& name, const RefPtr<Component>& child)
23 : BaseComposedComponent(id, name), SingleChild(child) {}
24
CreateElement()25 RefPtr<Element> ComposedComponent::CreateElement()
26 {
27 auto element = AceType::MakeRefPtr<ComposedElement>(GetId());
28
29 // elementFunction_ is true only for userdefined custom views
30 // in other case use default path in performBuild
31 if (elementFunction_) {
32 elementFunction_(element);
33 }
34
35 return element;
36 }
37
SetElementFunction(ElementFunction && func)38 void ComposedComponent::SetElementFunction(ElementFunction&& func)
39 {
40 elementFunction_ = std::move(func);
41 }
42
CallElementFunction(const RefPtr<Element> & element)43 void ComposedComponent::CallElementFunction(const RefPtr<Element>& element)
44 {
45 elementFunction_(AceType::DynamicCast<ComposedElement>(element));
46 }
47
48 } // namespace OHOS::Ace
49