1 /* 2 * Copyright (c) 2024 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_OVERLAY_SHEET_MANAGER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_SHEET_MANAGER_H 18 19 #include "base/utils/singleton.h" 20 #include "core/components_ng/pattern/overlay/overlay_manager.h" 21 22 namespace OHOS::Ace::NG { 23 class ACE_FORCE_EXPORT SheetManager : public Singleton<SheetManager> { 24 DECLARE_SINGLETON(SheetManager); 25 public: 26 static RefPtr<OverlayManager> FindPageNodeOverlay( 27 const RefPtr<FrameNode>& targetNode, bool isShow, bool isStartByUIContext = false); 28 static RefPtr<OverlayManager> GetOverlayFromPage(int32_t rootNodeId, RootNodeType rootNodeType); 29 30 int32_t OpenBindSheetByUIContext(const RefPtr<NG::FrameNode>& sheetContentNode, 31 std::function<void()>&& titleBuildFunc, NG::SheetStyle& sheetStyle, 32 std::function<void()>&& onAppear, std::function<void()>&& onDisappear, std::function<void()>&& shouldDismiss, 33 std::function<void(const int32_t info)>&& onWillDismiss, std::function<void()>&& onWillAppear, 34 std::function<void()>&& onWillDisappear, std::function<void(const float)>&& onHeightDidChange, 35 std::function<void(const float)>&& onDetentsDidChange, std::function<void(const float)>&& onWidthDidChange, 36 std::function<void(const float)>&& onTypeDidChange, std::function<void()>&& sheetSpringBack, 37 int32_t currentInstanceId, int32_t targetId); 38 int32_t UpdateBindSheetByUIContext( 39 const RefPtr<NG::FrameNode>& sheetContentNode, NG::SheetStyle& sheetStyle, bool isPartialUpdate, 40 int32_t currentInstanceId); 41 int32_t CloseBindSheetByUIContext(const RefPtr<NG::FrameNode>& sheetContentNode, int32_t currentInstanceId); CleanBindSheetMap(int32_t instanceId,int32_t sheetContentNodeId)42 void CleanBindSheetMap(int32_t instanceId, int32_t sheetContentNodeId) 43 { 44 overlayManagerMap_.erase(SheetContentKey(instanceId, sheetContentNodeId)); 45 targetIdMap_.erase(SheetContentKey(instanceId, sheetContentNodeId)); 46 } 47 SetDismissSheet(int32_t dismissId)48 void SetDismissSheet(int32_t dismissId) 49 { 50 sheetDismissId_ = dismissId; 51 } 52 GetDismissSheet()53 int32_t GetDismissSheet() 54 { 55 return sheetDismissId_; 56 } 57 58 void DeleteOverlayForWindowScene(int32_t rootNodeId, RootNodeType rootNodeType); 59 60 private: 61 struct SheetContentKey { SheetContentKeySheetContentKey62 SheetContentKey() {} SheetContentKeySheetContentKey63 SheetContentKey(int32_t inputInstanceId, int32_t inputContentNodeId) 64 : instanceId(inputInstanceId), contentNodeId(inputContentNodeId) {} 65 int32_t instanceId; 66 int32_t contentNodeId; 67 bool operator<(const SheetContentKey& other) const { 68 if (instanceId == other.instanceId) { 69 return contentNodeId < other.contentNodeId; 70 } 71 return instanceId < other.instanceId; 72 } 73 }; 74 75 int32_t sheetDismissId_ = 0; 76 std::map<SheetContentKey, RefPtr<OverlayManager>> overlayManagerMap_; 77 // Value: The uniqueId of the FrameNode to which BindSheet is attached 78 std::map<SheetContentKey, int32_t> targetIdMap_; 79 }; 80 } // namespace OHOS::Ace::NG 81 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_SHEET_MANAGER_H 82