• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_DIALOG_JS_CUSTOM_DIALOG_CONTROLLER_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_DIALOG_JS_CUSTOM_DIALOG_CONTROLLER_H
18 
19 #include "core/components/dialog/dialog_component.h"
20 #include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h"
21 #include "frameworks/bridge/declarative_frontend/jsview/js_view.h"
22 
23 namespace OHOS::Ace::Framework {
24 
25 enum class DialogOperation {
26     DIALOG_OPEN = 0,
27     DIALOG_CLOSE,
28 };
29 
30 class JSCustomDialogController {
31 public:
JSCustomDialogController(JSView * ownerView)32     explicit JSCustomDialogController(JSView* ownerView) : ownerView_(ownerView) {}
33     ~JSCustomDialogController() = default;
34 
35     static void JSBind(BindingTarget object);
36     static void ConstructorCallback(const JSCallbackInfo& args);
37     static void DestructorCallback(JSCustomDialogController* instance);
38 
39     void JsOpenDialog(const JSCallbackInfo& info);
40     void JsCloseDialog(const JSCallbackInfo& info);
41 
42 private:
43     void ShowDialog();
44     void CloseDialog();
45     void NotifyDialogOperation(DialogOperation operation);
46 
47     static bool ParseAnimation(
48         const JsiExecutionContext& execContext, const JsiRef<JsiValue>& jsiValue, AnimationOption& result);
49 
50     JSView* ownerView_ = nullptr;
51     bool isShown_ = false;
52     bool pending_ = false;
53 
54     // NG
55     std::vector<WeakPtr<NG::FrameNode>> dialogs_;
56 
57     DialogProperties dialogProperties_;
58     RefPtr<JsFunction> jsBuilderFunction_;
59     RefPtr<JsFunction> jsCancelFunction_;
60     RefPtr<Component> customDialog_;
61     RefPtr<DialogComponent> dialogComponent_;
62     std::list<DialogOperation> dialogOperation_;
63 };
64 
65 } // namespace OHOS::Ace::Framework
66 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_DIALOG_JS_CUSTOM_DIALOG_CONTROLLER_H
67