1 /* 2 * Copyright (c) 2025 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_NG_BASE_CUSTOM_APP_BAR_NODE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_CUSTOM_APP_BAR_NODE_H 18 19 #include "core/components_ng/pattern/custom/custom_node.h" 20 21 namespace OHOS::Ace::NG { 22 23 const std::string ARKUI_APP_BAR_COLOR_CONFIGURATION = "arkui_app_bar_color_configuration"; 24 const std::string ARKUI_APP_BAR_MENU_SAFE_AREA = "arkui_app_bar_menu_safe_area"; 25 const std::string ARKUI_APP_BAR_CONTENT_SAFE_AREA = "arkui_app_bar_content_safe_area"; 26 const std::string ARKUI_APP_BAR_BAR_INFO = "arkui_app_bar_info"; 27 const std::string ARKUI_APP_BAR_SCREEN = "arkui_app_bar_screen"; 28 const std::string ARKUI_APP_BG_COLOR = "arkui_app_bg_color"; 29 30 class ACE_EXPORT CustomAppBarNode : public CustomNode { 31 DECLARE_ACE_TYPE(CustomAppBarNode, CustomNode); 32 33 public: 34 static RefPtr<CustomAppBarNode> CreateCustomAppBarNode(int32_t nodeId, const std::string& viewKey); 35 36 CustomAppBarNode(int32_t nodeId, const std::string& viewKey); 37 ~CustomAppBarNode() override = default; 38 SetCustomCallback(const std::function<void (const std::string & eventName,const std::string & param)> & callback)39 void SetCustomCallback(const std::function<void(const std::string& eventName, const std::string& param)>& callback) 40 { 41 customCallback_ = callback; 42 } 43 FireCustomCallback(const std::string & eventName,const std::string & param)44 void FireCustomCallback(const std::string& eventName, const std::string& param) 45 { 46 if (customCallback_) { 47 TAG_LOGI(AceLogTag::ACE_APPBAR, "app bar FireCustomCallback eventName =%{public}s, param = %{public}s", 48 eventName.c_str(), param.c_str()); 49 customCallback_(eventName, param); 50 } 51 } 52 FireCustomCallback(const std::string & eventName,bool value)53 void FireCustomCallback(const std::string& eventName, bool value) 54 { 55 if (customCallback_) { 56 customCallback_(eventName, BoolToString(value)); 57 } 58 } 59 SetAppIconCallback(const std::function<void (const RefPtr<PixelMap> &)> & callback)60 void SetAppIconCallback(const std::function<void(const RefPtr<PixelMap>&)>& callback) 61 { 62 appIconCallback_ = callback; 63 } 64 FireAppIconCallback(const RefPtr<PixelMap> & icon)65 void FireAppIconCallback(const RefPtr<PixelMap>& icon) 66 { 67 if (appIconCallback_) { 68 appIconCallback_(icon); 69 } 70 } 71 72 private: BoolToString(bool value)73 std::string BoolToString(bool value) 74 { 75 return value ? "true" : "false"; 76 } 77 std::function<void(const std::string&, const std::string&)> customCallback_ = nullptr; 78 std::function<void(const RefPtr<PixelMap>&)> appIconCallback_ = nullptr; 79 }; 80 } // namespace OHOS::Ace::NG 81 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_CUSTOM_APP_BAR_NODE_H