1 /* 2 * Copyright (c) 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_NG_PATTERNS_BUBBLE_BUBBLE_EVENT_HUB_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_BUBBLE_BUBBLE_EVENT_HUB_H 18 19 #include <string> 20 21 #include "base/memory/ace_type.h" 22 #include "core/components_ng/event/event_hub.h" 23 #include "core/components_ng/event/gesture_event_hub.h" 24 #include "core/pipeline_ng/pipeline_context.h" 25 26 namespace OHOS::Ace::NG { 27 28 using StateChangeEvent = std::function<void(const std::string&)>; 29 30 class BubbleEventHub : public EventHub { 31 DECLARE_ACE_TYPE(BubbleEventHub, EventHub) 32 33 public: 34 BubbleEventHub() = default; 35 ~BubbleEventHub() override = default; 36 SetOnStateChange(StateChangeEvent && changeEvent)37 void SetOnStateChange(StateChangeEvent&& changeEvent) 38 { 39 changeEvent_ = std::move(changeEvent); 40 } 41 FireChangeEvent(bool isVisible)42 void FireChangeEvent(bool isVisible) 43 { 44 if (changeEvent_) { 45 auto json = JsonUtil::Create(true); 46 json->Put("isVisible", isVisible); 47 changeEvent_(json->ToString()); 48 } 49 } 50 51 private: 52 StateChangeEvent changeEvent_; 53 54 ACE_DISALLOW_COPY_AND_MOVE(BubbleEventHub); 55 }; 56 57 } // namespace OHOS::Ace::NG 58 59 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_BUBBLE_BUBBLE_EVENT_HUB_H