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_POPUP_POPUP_COMPONENT_V2_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_POPUP_POPUP_COMPONENT_V2_H 18 19 #include "core/components/popup/popup_component.h" 20 #include "core/components/popup/popup_theme.h" 21 22 namespace OHOS::Ace { 23 24 struct ButtonProperties { 25 bool showButton = false; 26 std::string value; 27 EventMarker actionId; 28 }; 29 30 class ACE_EXPORT PopupComponentV2 : public PopupComponent { 31 DECLARE_ACE_TYPE(PopupComponentV2, PopupComponent); 32 33 public: PopupComponentV2(const ComposeId & id,const std::string & name,const RefPtr<Component> & child)34 PopupComponentV2(const ComposeId& id, const std::string& name, const RefPtr<Component>& child) 35 : PopupComponent(id, name, child) {} PopupComponentV2(const ComposeId & id,const std::string & name)36 PopupComponentV2(const ComposeId& id, const std::string& name) : PopupComponent(id, name) {} 37 ~PopupComponentV2() override = default; 38 39 RefPtr<Element> CreateElement() override; 40 SetMessage(const std::string & message)41 void SetMessage(const std::string& message) 42 { 43 message_ = message; 44 } 45 GetMessage()46 std::string GetMessage() const 47 { 48 return message_; 49 } 50 GetOnStateChange()51 const EventMarker& GetOnStateChange() const 52 { 53 return onStateChange_; 54 } 55 SetOnStateChange(const EventMarker & onStateChange)56 void SetOnStateChange(const EventMarker& onStateChange) 57 { 58 onStateChange_ = onStateChange; 59 } 60 GetChangeEvent()61 const EventMarker& GetChangeEvent() const 62 { 63 return changeEvent_; 64 } 65 SetChangeEvent(const EventMarker & changeEvent)66 void SetChangeEvent(const EventMarker& changeEvent) 67 { 68 changeEvent_ = changeEvent; 69 } 70 71 void Initialization( 72 const RefPtr<ThemeManager>& themeManager, const WeakPtr<PipelineContext>& context); 73 SetPrimaryButtonProperties(const ButtonProperties & properties)74 void SetPrimaryButtonProperties(const ButtonProperties& properties) 75 { 76 primaryButtonProperties_ = properties; 77 } 78 GetPrimaryButtonValue()79 std::string GetPrimaryButtonValue() const 80 { 81 return primaryButtonProperties_.value; 82 } 83 SetSecondaryButtonProperties(const ButtonProperties & properties)84 void SetSecondaryButtonProperties(const ButtonProperties& properties) 85 { 86 secondaryButtonProperties_ = properties; 87 } 88 GetSecondaryButtonValue()89 std::string GetSecondaryButtonValue() const 90 { 91 return secondaryButtonProperties_.value; 92 } 93 SetPlacementOnTop(bool placementOnTop)94 void SetPlacementOnTop(bool placementOnTop) 95 { 96 placementOnTop_ = placementOnTop; 97 } 98 GetPlacementOnTop()99 bool GetPlacementOnTop() const 100 { 101 return placementOnTop_; 102 } 103 SetCustomComponent(const RefPtr<Component> & customComponent)104 void SetCustomComponent(const RefPtr<Component>& customComponent) 105 { 106 customComponent_ = customComponent; 107 } 108 GetCustomComponent()109 const RefPtr<Component>& GetCustomComponent() const 110 { 111 return customComponent_; 112 } 113 114 private: 115 const RefPtr<Component> CreateChild(); 116 const RefPtr<Component> CreateMessage(); 117 const RefPtr<Component> CreateButtons(); 118 const RefPtr<Component> CreateButton(const ButtonProperties& buttonProperties); 119 const RefPtr<Component> SetPadding(const RefPtr<Component>& component, const Edge& edge); 120 121 std::string message_; 122 bool hasInitialization_ = false; 123 bool placementOnTop_ = false; 124 EventMarker onStateChange_; 125 EventMarker changeEvent_; 126 RefPtr<PopupParam> popupParam_; 127 RefPtr<PopupController> popupController_; 128 RefPtr<ThemeManager> themeManager_; 129 RefPtr<Component> customComponent_; 130 WeakPtr<PipelineContext> context_; 131 132 ButtonProperties primaryButtonProperties_; // first button. 133 ButtonProperties secondaryButtonProperties_; // second button. 134 }; 135 136 } // namespace OHOS::Ace 137 138 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_POPUP_POPUP_COMPONENT_V2_H 139