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 FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_NAVDESTINATION_CONTEXT_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_NAVDESTINATION_CONTEXT_H
18 
19 #include <optional>
20 #include <string>
21 
22 #include "base/memory/referenced.h"
23 #include "bridge/declarative_frontend/engine/bindings.h"
24 #include "bridge/declarative_frontend/engine/functions/js_function.h"
25 #include "bridge/declarative_frontend/engine/js_types.h"
26 #include "bridge/declarative_frontend/engine/js_ref_ptr.h"
27 #include "core/components_ng/pattern/navrouter/navdestination_context.h"
28 
29 namespace OHOS::Ace::Framework {
30 class JSNavPathInfo : public NG::NavPathInfo {
31     DECLARE_ACE_TYPE(JSNavPathInfo, NG::NavPathInfo)
32 public:
33     JSNavPathInfo() = default;
JSNavPathInfo(const std::string & name,JSRef<JSVal> param)34     JSNavPathInfo(const std::string& name, JSRef<JSVal> param) : NG::NavPathInfo(name), param_(param) {}
35     JSNavPathInfo(const std::string& name, JSRef<JSVal> param, JSRef<JSVal> onPop, bool isEntry = false)
36         : NG::NavPathInfo(name, isEntry), param_(param), onPop_(onPop) {}
37     ~JSNavPathInfo() = default;
38 
SetParam(const JSRef<JSVal> & param)39     void SetParam(const JSRef<JSVal>& param)
40     {
41         param_ = param;
42     }
43 
GetParam()44     JSRef<JSVal> GetParam() const
45     {
46         return param_;
47     }
48 
SetOnPop(const JSRef<JSVal> & onPop)49     void SetOnPop(const JSRef<JSVal>& onPop)
50     {
51         onPop_ = onPop;
52     }
53 
GetOnPop()54     JSRef<JSVal> GetOnPop() const
55     {
56         return onPop_;
57     }
58 
59     napi_value GetParamObj() const override;
60 
61 private:
62     JSRef<JSVal> param_;
63     JSRef<JSVal> onPop_;
64 };
65 
66 class JSNavDestinationContext : public Referenced {
67 public:
68 
69     static void JSBind(BindingTarget target);
70     JSNavDestinationContext() = default;
71     ~JSNavDestinationContext() = default;
72 
73     void SetPathStack(const JSCallbackInfo& info);
74 
75     void GetPathStack(const JSCallbackInfo& info);
76 
77     void SetPathInfo(const JSCallbackInfo& info);
78 
79     void GetPathInfo(const JSCallbackInfo& info);
80 
81     void GetRouteInfo(const JSCallbackInfo& info);
82 
83     void SetNavDestinationId(const JSCallbackInfo& info);
84 
85     void GetNavDestinationId(const JSCallbackInfo& info);
86 
SetNavDestinationContext(const RefPtr<NG::NavDestinationContext> context)87     void SetNavDestinationContext(const RefPtr<NG::NavDestinationContext> context)
88     {
89         context_ = context;
90     }
91 
92 private:
93     static void Constructor(const JSCallbackInfo &info);
94     static void Destructor(JSNavDestinationContext* context);
95     RefPtr<NG::NavDestinationContext> context_;
96 };
97 } // namespace OHOS::Ace::Framework
98 
99 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_NAVDESTINATION_CONTEXT_H
100