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/components/list/list_item_component.h" 17 18 #include "core/components/list/list_item_element.h" 19 #include "core/components/list/render_list_item.h" 20 21 namespace OHOS::Ace { 22 ListItemComponent(const std::string & type,const RefPtr<Component> & child)23ListItemComponent::ListItemComponent(const std::string& type, const RefPtr<Component>& child) 24 : SoleChildComponent(child) 25 { 26 type_ = type; 27 } 28 CreateElement()29RefPtr<Element> ListItemComponent::CreateElement() 30 { 31 return AceType::MakeRefPtr<ListItemElement>(); 32 } 33 CreateRenderNode()34RefPtr<RenderNode> ListItemComponent::CreateRenderNode() 35 { 36 return RenderListItem::Create(); 37 } 38 GetListItem(const RefPtr<Component> & component)39RefPtr<ListItemComponent> ListItemComponent::GetListItem(const RefPtr<Component>& component) 40 { 41 RefPtr<Component> item = component; 42 while (item) { 43 auto itemComponent = AceType::DynamicCast<ListItemComponent>(item); 44 if (itemComponent) { 45 return itemComponent; 46 } 47 48 auto parent = AceType::DynamicCast<SingleChild>(item); 49 if (!parent) { 50 return nullptr; 51 } 52 item = parent->GetChild(); 53 } 54 return nullptr; 55 } 56 57 } // namespace OHOS::Ace