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_DISPLAY_DISPLAY_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DISPLAY_DISPLAY_COMPONENT_H 18 19 #include "core/components/common/properties/animatable_double.h" 20 #include "core/components/common/properties/animation_option.h" 21 #include "core/components/display/display_element.h" 22 #include "core/pipeline/base/sole_child_component.h" 23 24 namespace OHOS::Ace { 25 26 enum class DisplayStateAttribute { 27 OPACITY, 28 }; 29 30 enum class VisibleType { 31 VISIBLE, 32 INVISIBLE, 33 GONE, 34 }; 35 36 class ACE_EXPORT DisplayComponent : public SoleChildComponent { 37 DECLARE_ACE_TYPE(DisplayComponent, SoleChildComponent); 38 39 public: 40 DisplayComponent() = default; DisplayComponent(const RefPtr<Component> & child)41 explicit DisplayComponent(const RefPtr<Component>& child) : SoleChildComponent(child) {} 42 ~DisplayComponent() override = default; 43 44 RefPtr<RenderNode> CreateRenderNode() override; 45 CreateElement()46 RefPtr<Element> CreateElement() override 47 { 48 return AceType::MakeRefPtr<DisplayElement>(); 49 } 50 GetVisible()51 VisibleType GetVisible() const 52 { 53 return visible_; 54 } 55 GetOpacity()56 double GetOpacity() const 57 { 58 return opacity_.GetValue(); 59 } 60 GetOpacityAnimationOption()61 AnimationOption GetOpacityAnimationOption() const 62 { 63 return opacity_.GetAnimationOption(); 64 } 65 SetVisible(VisibleType visible)66 void SetVisible(VisibleType visible) 67 { 68 visible_ = visible; 69 } 70 71 void SetOpacity(double opacity, const AnimationOption& animationOption = AnimationOption()) 72 { 73 opacity_ = AnimatableDouble(opacity, animationOption); 74 } 75 DisableLayer(bool disable)76 void DisableLayer(bool disable) 77 { 78 disableLayer_ = disable; 79 } 80 IsDisableLayer()81 bool IsDisableLayer() const 82 { 83 return disableLayer_; 84 } 85 SetShadow(const Shadow & shadow)86 void SetShadow(const Shadow& shadow) 87 { 88 shadow_ = shadow; 89 } 90 GetShadow()91 const Shadow& GetShadow() const 92 { 93 return shadow_; 94 } 95 SetTransition(TransitionType type,double opacity)96 void SetTransition(TransitionType type, double opacity) 97 { 98 if (type == TransitionType::DISAPPEARING) { 99 hasDisappearTransition_ = true; 100 disappearingOpacity_ = opacity; 101 } else if (type == TransitionType::APPEARING) { 102 hasAppearTransition_ = true; 103 appearingOpacity_ = opacity; 104 } else { 105 hasDisappearTransition_ = true; 106 hasAppearTransition_ = true; 107 disappearingOpacity_ = opacity; 108 appearingOpacity_ = opacity; 109 } 110 } 111 HasDisappearTransition()112 bool HasDisappearTransition() const 113 { 114 return hasDisappearTransition_; 115 } 116 HasAppearTransition()117 bool HasAppearTransition() const 118 { 119 return hasAppearTransition_; 120 } 121 GetAppearingOpacity()122 double GetAppearingOpacity() const 123 { 124 return appearingOpacity_; 125 } 126 GetDisappearingOpacity()127 double GetDisappearingOpacity() const 128 { 129 return disappearingOpacity_; 130 } 131 SetAppearingDuration(int32_t duration)132 void SetAppearingDuration(int32_t duration) 133 { 134 duration_ = duration; 135 } 136 137 // Duration in millisecond. GetAppearingDuration()138 int32_t GetAppearingDuration() const 139 { 140 return duration_; 141 } 142 GetStateAttributes()143 RefPtr<StateAttributes<DisplayStateAttribute>> GetStateAttributes() 144 { 145 if (stateAttributeList_ == nullptr) { 146 stateAttributeList_ = MakeRefPtr<StateAttributes<DisplayStateAttribute>>(); 147 } 148 return stateAttributeList_; 149 } 150 HasStateAttributes()151 bool HasStateAttributes() 152 { 153 return stateAttributeList_ != nullptr; 154 } 155 156 private: 157 VisibleType visible_ = VisibleType::VISIBLE; 158 Shadow shadow_; 159 AnimatableDouble opacity_ = AnimatableDouble(1.0); 160 double appearingOpacity_ = 0.0; 161 double disappearingOpacity_ = 0.0; 162 bool hasDisappearTransition_ = false; 163 bool hasAppearTransition_ = false; 164 bool disableLayer_ = false; 165 int32_t duration_ = 0; 166 RefPtr<StateAttributes<DisplayStateAttribute>> stateAttributeList_ = nullptr; 167 }; 168 169 } // namespace OHOS::Ace 170 171 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DISPLAY_DISPLAY_COMPONENT_H 172