• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_NAVIGATION_STACK_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_NAVIGATION_STACK_H
18 
19 #include <stdint.h>
20 
21 #include "bridge/declarative_frontend/engine/js_types.h"
22 #include "bridge/declarative_frontend/jsview/js_utils.h"
23 #include "core/components_ng/pattern/navigation/navigation_stack.h"
24 
25 namespace OHOS::Ace::Framework {
26 
27 class JSRouteInfo : public NG::RouteInfo {
28     DECLARE_ACE_TYPE(JSRouteInfo, NG::RouteInfo)
29 public:
30     JSRouteInfo() = default;
31     ~JSRouteInfo() override = default;
32 
33     std::string GetName() override;
34     void SetName(const std::string& name);
35     void SetParam(const JSRef<JSVal>& param);
36     JSRef<JSVal> GetParam() const;
37 
38 protected:
39     std::string name_;
40     JSRef<JSVal> param_;
41 };
42 
43 class JSNavigationStack : public NG::NavigationStack {
44     DECLARE_ACE_TYPE(JSNavigationStack, NG::NavigationStack)
45 public:
46     JSNavigationStack() = default;
47     ~JSNavigationStack() override = default;
48 
UpdateStackInfo(const RefPtr<NavigationStack> & newStack)49     void UpdateStackInfo(const RefPtr<NavigationStack>& newStack) override
50     {
51         auto newJsStack = AceType::DynamicCast<JSNavigationStack>(newStack);
52         if (newJsStack) {
53             SetDataSourceObj(newJsStack->GetDataSourceObj());
54         }
55     }
56     void SetDataSourceObj(const JSRef<JSObject>& dataSourceObj);
57     const JSRef<JSObject>& GetDataSourceObj();
58     void SetNavDestBuilderFunc(const JSRef<JSFunc>& navDestBuilderFunc);
59     bool IsEmpty() override;
60     void Pop() override;
61     void Push(const std::string& name, const RefPtr<NG::RouteInfo>& routeInfo = nullptr) override;
62     void Push(const std::string& name, int32_t index) override;
63     void PushName(const std::string& name, const JSRef<JSVal>& param);
64     void RemoveName(const std::string& name) override;
65     void RemoveIndex(int32_t index) override;
66     void Clear() override;
67     std::vector<std::string> GetAllPathName() override;
68     RefPtr<NG::UINode> CreateNodeByIndex(int32_t index) override;
69     RefPtr<NG::UINode> CreateNodeByRouteInfo(const RefPtr<NG::RouteInfo>& routeInfo) override;
70     void SetJSExecutionContext(const JSExecutionContext& context);
71 
72 protected:
73     JSRef<JSObject> dataSourceObj_;
74     JSRef<JSFunc> navDestBuilderFunc_;
75     JSExecutionContext executionContext_;
76 
77 private:
78     std::string GetNameByIndex(int32_t index);
79     JSRef<JSVal> GetParamByIndex(int32_t index) const;
80     bool CheckNavDestinationNodeInUINode(RefPtr<NG::UINode> node);
81 };
82 } // namespace OHOS::Ace::Framework
83 
84 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_NAVIGATION_STACK_H
85