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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_STAGE_STAGE_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_STAGE_STAGE_COMPONENT_H 18 19 #include "base/utils/system_properties.h" 20 #include "core/components/stack/stack_component.h" 21 #include "core/components/stage/render_stage.h" 22 #include "core/components/stage/stage_element.h" 23 24 namespace OHOS::Ace { 25 26 class StageComponent : public StackComponent { 27 DECLARE_ACE_TYPE(StageComponent, StackComponent); 28 29 public: StageComponent(const std::list<RefPtr<Component>> & children)30 explicit StageComponent(const std::list<RefPtr<Component>>& children) 31 : StackComponent(Alignment::TOP_LEFT, StackFit::INHERIT, Overflow::OBSERVABLE, children) 32 {} StageComponent(const std::list<RefPtr<Component>> & children,bool isSectionStage)33 StageComponent(const std::list<RefPtr<Component>>& children, bool isSectionStage) 34 : StackComponent(Alignment::TOP_LEFT, StackFit::INHERIT, Overflow::OBSERVABLE, children), 35 isSectionStage_(isSectionStage) 36 {} 37 ~StageComponent() override = default; 38 CreateElement()39 RefPtr<Element> CreateElement() override 40 { 41 if (isSectionStage_) { 42 return AceType::MakeRefPtr<SectionStageElement>(); 43 } else { 44 return AceType::MakeRefPtr<StageElement>(); 45 } 46 } 47 CreateRenderNode()48 RefPtr<RenderNode> CreateRenderNode() override 49 { 50 if (SystemProperties::GetDeviceType() == DeviceType::WATCH) { 51 LOGI("device type is watch, create stage render node."); 52 return RenderStage::Create(); 53 } 54 return RenderStack::Create(); 55 } 56 57 private: 58 bool isSectionStage_ = false; 59 }; 60 61 } // namespace OHOS::Ace 62 63 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_STAGE_STAGE_COMPONENT_H 64