• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ON_BACK_PRESSED = "arkui_app_bar_on_back_pressed";
27 const std::string ARKUI_APP_BAR_BAR_INFO = "arkui_app_bar_info";
28 const std::string ARKUI_APP_BAR_SCREEN = "arkui_app_bar_screen";
29 const std::string ARKUI_APP_BG_COLOR = "arkui_app_bg_color";
30 
31 class ACE_EXPORT CustomAppBarNode : public CustomNode {
32     DECLARE_ACE_TYPE(CustomAppBarNode, CustomNode);
33 
34 public:
35     static RefPtr<CustomAppBarNode> CreateCustomAppBarNode(int32_t nodeId, const std::string& viewKey);
36 
37     CustomAppBarNode(int32_t nodeId, const std::string& viewKey);
38     ~CustomAppBarNode() override = default;
39 
SetCustomCallback(const std::function<void (const std::string & eventName,const std::string & param)> & callback)40     void SetCustomCallback(const std::function<void(const std::string& eventName, const std::string& param)>& callback)
41     {
42         customCallback_ = callback;
43     }
44 
FireCustomCallback(const std::string & eventName,const std::string & param)45     void FireCustomCallback(const std::string& eventName, const std::string& param)
46     {
47         if (customCallback_) {
48             TAG_LOGI(AceLogTag::ACE_APPBAR, "app bar FireCustomCallback eventName =%{public}s, param = %{public}s",
49                 eventName.c_str(), param.c_str());
50             customCallback_(eventName, param);
51         }
52     }
53 
FireCustomCallback(const std::string & eventName,bool value)54     void FireCustomCallback(const std::string& eventName, bool value)
55     {
56         if (customCallback_) {
57             customCallback_(eventName, BoolToString(value));
58         }
59     }
60 
SetAppIconCallback(const std::function<void (const RefPtr<PixelMap> &)> & callback)61     void SetAppIconCallback(const std::function<void(const RefPtr<PixelMap>&)>& callback)
62     {
63         appIconCallback_ = callback;
64     }
65 
FireAppIconCallback(const RefPtr<PixelMap> & icon)66     void FireAppIconCallback(const RefPtr<PixelMap>& icon)
67     {
68         if (appIconCallback_) {
69             appIconCallback_(icon);
70         }
71     }
72 
73 private:
BoolToString(bool value)74     std::string BoolToString(bool value)
75     {
76         return value ? "true" : "false";
77     }
78     std::function<void(const std::string&, const std::string&)> customCallback_ = nullptr;
79     std::function<void(const RefPtr<PixelMap>&)> appIconCallback_ = nullptr;
80 };
81 } // namespace OHOS::Ace::NG
82 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_CUSTOM_APP_BAR_NODE_H