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 INTERFACES_NAPI_KITS_PROMPT_ACTION_PROMPT_CONTROLLER_H 17 #define INTERFACES_NAPI_KITS_PROMPT_ACTION_PROMPT_CONTROLLER_H 18 19 #include "core/components_ng/base/frame_node.h" 20 #include "core/components/dialog/dialog_properties.h" 21 #include "core/components_ng/pattern/dialog/dialog_pattern.h" 22 23 namespace OHOS::Ace::Napi { 24 25 class PromptController { 26 public: 27 PromptController() = default; 28 virtual ~PromptController() = default; 29 SetNode(const WeakPtr<NG::FrameNode> node)30 void SetNode(const WeakPtr<NG::FrameNode> node) 31 { 32 node_ = node; 33 auto dialogNode = node_.Upgrade(); 34 CHECK_NULL_VOID(dialogNode); 35 auto pattern = dialogNode->GetPattern<NG::DialogPattern>(); 36 CHECK_NULL_VOID(pattern); 37 if (PromptActionCommonState::UNINITIALIZED == pattern->GetState()) { 38 pattern->SetState(PromptActionCommonState::INITIALIZED); 39 TAG_LOGI(AceLogTag::ACE_DIALOG, "The current state of the dialog is INITIALIZED."); 40 } 41 hasBind_ = true; 42 } Close()43 virtual void Close() {}; 44 GetState()45 virtual PromptActionCommonState GetState() 46 { 47 return PromptActionCommonState::UNINITIALIZED; 48 } 49 protected: 50 WeakPtr<NG::FrameNode> node_; 51 bool hasBind_ = false; 52 }; 53 54 class PromptDialogController : public PromptController { 55 public: 56 PromptDialogController() = default; 57 ~PromptDialogController() override = default; 58 59 void Close() override; 60 PromptActionCommonState GetState() override; 61 }; 62 } // namespace OHOS::Ace::Napi 63 #endif // #define INTERFACES_NAPI_KITS_PROMPT_ACTION_PROMPT_CONTROLLER_H