1 /*
2  * Copyright (c) 2023 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_PATTERN_FOLDER_STACK_EVENT_HUB_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FOLDER_STACK_EVENT_HUB_H
18 
19 #include "base/memory/ace_type.h"
20 #include "core/components_ng/event/event_hub.h"
21 #include "core/components_ng/pattern/folder_stack/folder_stack_event_info.h"
22 
23 namespace OHOS::Ace::NG {
24 using ChangeEvent = std::function<void(const FolderEventInfo& folderEventInfo)>;
25 using HoverStatusChangeEvent = std::function<void(const FolderEventInfo& folderEventInfo)>;
26 
27 class FolderStackEventHub : public EventHub {
DECLARE_ACE_TYPE(FolderStackEventHub,EventHub)28     DECLARE_ACE_TYPE(FolderStackEventHub, EventHub)
29 
30 public:
31     void SetOnFolderStateChange(ChangeEvent&& changeEvent)
32     {
33         changeEvent_ = std::move(changeEvent);
34     }
35 
SetOnHoverStatusChange(HoverStatusChangeEvent && hoverStatusChangeEvent)36     void SetOnHoverStatusChange(HoverStatusChangeEvent&& hoverStatusChangeEvent)
37     {
38         hoverStatusChangeEvent_ = std::move(hoverStatusChangeEvent);
39     }
40 
OnFolderStateChange(const FolderEventInfo & folderEventInfo)41     void OnFolderStateChange(const FolderEventInfo& folderEventInfo) const
42     {
43         if (changeEvent_) {
44             changeEvent_(std::move(folderEventInfo));
45         }
46     }
47 
OnHoverStatusChange(const FolderEventInfo && folderEventInfo)48     void OnHoverStatusChange(const FolderEventInfo&& folderEventInfo) const
49     {
50         if (hoverStatusChangeEvent_) {
51             hoverStatusChangeEvent_(folderEventInfo);
52         }
53     }
54 
55 private:
56     ChangeEvent changeEvent_;
57     HoverStatusChangeEvent hoverStatusChangeEvent_;
58 };
59 } // namespace OHOS::Ace::NG
60 
61 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FOLDER_STACK_EVENT_HUB.H