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_RENDER_DISPLAY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DISPLAY_RENDER_DISPLAY_H 18 19 #include "core/animation/animator.h" 20 #include "core/components/display/display_component.h" 21 #include "core/pipeline/base/render_node.h" 22 23 namespace OHOS::Ace { 24 25 class RenderDisplay : public RenderNode { 26 DECLARE_ACE_TYPE(RenderDisplay, RenderNode); 27 28 public: 29 static RefPtr<RenderNode> Create(); 30 void Update(const RefPtr<Component>& component) override; 31 void PerformLayout() override; 32 33 void Dump() override; 34 OnAttachContext()35 void OnAttachContext() override 36 { 37 animatableOpacity_.SetContextAndCallback( 38 context_, std::bind(&RenderDisplay::OnOpacityAnimationCallback, this)); 39 } 40 UpdateVisibleType(VisibleType type)41 void UpdateVisibleType(VisibleType type) 42 { 43 if (visible_ != type) { 44 visible_ = type; 45 SetVisible(visible_ == VisibleType::VISIBLE); 46 MarkNeedLayout(); 47 } 48 } 49 UpdateHidden(bool hidden)50 void UpdateHidden(bool hidden) 51 { 52 if (GetHidden() != hidden) { 53 SetSelfHidden(hidden); 54 MarkNeedLayout(); 55 } 56 } 57 UpdateOpacity()58 void UpdateOpacity() 59 { 60 auto display = displayComponent_.Upgrade(); 61 if (display) { 62 display->SetOpacity(transitionOpacity_); 63 } 64 } 65 UpdateOpacity(uint8_t opacity)66 void UpdateOpacity(uint8_t opacity) override 67 { 68 if (disableLayer_) { 69 for (auto& callback : opacityCallbacks_) { 70 callback(opacity); 71 } 72 return; 73 } 74 if (opacity_ != opacity) { 75 opacity_ = opacity; 76 MarkNeedRender(); 77 } 78 } 79 GetTransitionOpacity()80 double GetTransitionOpacity() const 81 { 82 return transitionOpacity_; 83 } 84 GetVisibleType()85 VisibleType GetVisibleType() 86 { 87 return visible_; 88 } 89 90 void GetOpacityCallbacks(); 91 92 bool GetVisible() const override; 93 94 void OnStatusStyleChanged(VisualState style) override; 95 96 void OnTransition(TransitionType type, int32_t id) override; 97 98 bool HasDisappearingTransition(int32_t nodeId) override; 99 GetStateAttributes()100 RefPtr<StateAttributes<DisplayStateAttribute>> GetStateAttributes() 101 { 102 if (stateAttributeList_ == nullptr) { 103 stateAttributeList_ = MakeRefPtr<StateAttributes<DisplayStateAttribute>>(); 104 } 105 return stateAttributeList_; 106 } 107 108 HasStateAttributes()109 bool HasStateAttributes() 110 { 111 return stateAttributeList_ != nullptr; 112 } 113 114 protected: 115 void OnOpacityAnimationCallback(); 116 void OnOpacityDisappearingCallback(); 117 void ClearRenderObject() override; 118 int32_t GetCardAppearingDuration(); 119 void CreateAppearingAnimation(uint8_t opacity, int32_t limit); 120 void ResetAppearingAnimation(); 121 122 int32_t duration_ = 0; 123 double transitionOpacity_ = 0.0; 124 VisibleType visible_ = VisibleType::VISIBLE; 125 AnimatableDouble animatableOpacity_ = AnimatableDouble(1.0); 126 double appearingOpacity_ = 0.0; 127 double disappearingOpacity_ = 0.0; 128 bool hasDisappearTransition_ = false; 129 bool hasAppearTransition_ = false; 130 bool pendingAppearing_ = false; 131 bool disableLayer_ = false; 132 std::list<OpacityCallback> opacityCallbacks_; 133 WeakPtr<DisplayComponent> displayComponent_; 134 RefPtr<CurveAnimation<uint8_t>> appearingAnimation_; 135 RefPtr<Animator> animator_; 136 RefPtr<StateAttributes<DisplayStateAttribute>> stateAttributeList_; 137 }; 138 139 } // namespace OHOS::Ace 140 141 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DISPLAY_RENDER_DISPLAY_H 142