1 /* 2 * Copyright (c) 2021-2022 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_POPUP_POPUP_ELEMENT_V2_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_POPUP_POPUP_ELEMENT_V2_H 18 19 #include "core/components/popup/popup_component_v2.h" 20 #include "core/components/popup/popup_element.h" 21 22 namespace OHOS::Ace { 23 24 class PopupElementV2 : public PopupElement { 25 DECLARE_ACE_TYPE(PopupElementV2, PopupElement); 26 27 public: PopupElementV2(const ComposeId & id)28 explicit PopupElementV2(const ComposeId& id) : PopupElement(id) {} 29 ~PopupElementV2() override = default; 30 31 void PerformBuild() override; 32 bool IsDeclarative(); 33 void OnStateChange(bool isVisible) override; 34 GetMessage()35 std::string GetMessage() const 36 { 37 auto popupComponentV2 = AceType::DynamicCast<PopupComponentV2>(popup_); 38 if (popupComponentV2) { 39 return popupComponentV2->GetMessage(); 40 } 41 return ""; 42 } 43 GetPlacementOnTop()44 bool GetPlacementOnTop() 45 { 46 auto popupComponentV2 = AceType::DynamicCast<PopupComponentV2>(popup_); 47 if (popupComponentV2) { 48 return popupComponentV2->GetPlacementOnTop(); 49 } 50 return false; 51 } 52 GetPrimaryButtonValue()53 std::string GetPrimaryButtonValue() const 54 { 55 auto popupComponentV2 = AceType::DynamicCast<PopupComponentV2>(popup_); 56 if (popupComponentV2) { 57 return popupComponentV2->GetPrimaryButtonValue(); 58 } 59 return ""; 60 } 61 GetSecondaryButtonValue()62 std::string GetSecondaryButtonValue() const 63 { 64 auto popupComponentV2 = AceType::DynamicCast<PopupComponentV2>(popup_); 65 if (popupComponentV2) { 66 return popupComponentV2->GetSecondaryButtonValue(); 67 } 68 return ""; 69 } 70 CanUpdate(const RefPtr<Component> & newComponent)71 bool CanUpdate(const RefPtr<Component>& newComponent) override 72 { 73 return Element::CanUpdate(newComponent); 74 } 75 76 private: 77 void HandleDeclarativePerformBuild(); 78 bool hasShown_ = false; 79 ComposeId showId_; 80 std::function<void(const std::string&)> onStateChange_; 81 std::function<void(const std::string&)> changeEvent_; 82 }; 83 84 } // namespace OHOS::Ace 85 86 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_POPUP_POPUP_ELEMENT_V2_H 87