• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_NAVROUTER_NAVDESTINATION_CONTEXT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVROUTER_NAVDESTINATION_CONTEXT_H
18 
19 #include <string>
20 
21 #include "base/memory/ace_type.h"
22 #include "core/components_ng/pattern/navigation/navigation_stack.h"
23 
24 namespace OHOS::Ace::NG {
25 class NavigationStack;
26 class NavPathInfo : public virtual AceType {
27     DECLARE_ACE_TYPE(NavPathInfo, AceType)
28 public:
29     NavPathInfo() = default;
NavPathInfo(const std::string & name)30     explicit NavPathInfo(const std::string& name) : name_(name) {}
NavPathInfo(const std::string & name,bool isEntry)31     NavPathInfo(const std::string& name, bool isEntry) : name_(name), isEntry_(isEntry) {}
32     virtual ~NavPathInfo() = default;
33 
SetName(const std::string & name)34     void SetName(const std::string& name)
35     {
36         name_ = name;
37     }
38 
GetName()39     std::string GetName() const
40     {
41         return name_;
42     }
43 
GetParamObj()44     virtual napi_value GetParamObj() const
45     {
46         return nullptr;
47     }
48 
GetIsEntry()49     bool GetIsEntry() const
50     {
51         return isEntry_;
52     }
53 
SetIsEntry(bool isEntry)54     void SetIsEntry(bool isEntry)
55     {
56         isEntry_ = isEntry;
57     }
58 
UpdateNavPathInfo(const RefPtr<NG::NavPathInfo> & info)59     virtual void UpdateNavPathInfo(const RefPtr<NG::NavPathInfo>& info)
60     {
61         if (!info) {
62             return;
63         }
64         name_ = info->GetName();
65         isEntry_ = info->GetIsEntry();
66     }
67 
68 protected:
69     std::string name_;
70     bool isEntry_ = false;
71 };
72 
73 class NavDestinationContext : public virtual AceType {
74     DECLARE_ACE_TYPE(NavDestinationContext, AceType)
75 public:
76     NavDestinationContext() = default;
77     virtual ~NavDestinationContext() = default;
78 
SetNavPathInfo(RefPtr<NavPathInfo> info)79     void SetNavPathInfo(RefPtr<NavPathInfo> info)
80     {
81         pathInfo_ = info;
82     }
83 
GetNavPathInfo()84     RefPtr<NavPathInfo> GetNavPathInfo() const
85     {
86         return pathInfo_;
87     }
88 
SetNavigationStack(WeakPtr<NavigationStack> stack)89     void SetNavigationStack(WeakPtr<NavigationStack> stack)
90     {
91         navigationStack_ = stack;
92     }
93 
GetNavigationStack()94     WeakPtr<NavigationStack> GetNavigationStack() const
95     {
96         return navigationStack_;
97     }
98 
GetIndex()99     int32_t GetIndex() const
100     {
101         return index_;
102     }
103 
SetIndex(int32_t index)104     void SetIndex(int32_t index)
105     {
106         index_ = index;
107     }
108 
GetPreIndex()109     int32_t GetPreIndex() const
110     {
111         return preIndex_;
112     }
113 
SetPreIndex(int32_t index)114     void SetPreIndex(int32_t index)
115     {
116         preIndex_ = index;
117     }
118 
GetNavDestinationId()119     uint64_t GetNavDestinationId() const
120     {
121         return navDestinationId_;
122     }
123 
SetNavDestinationId(uint64_t id)124     void SetNavDestinationId(uint64_t id)
125     {
126         navDestinationId_ = id;
127     }
128 
SetIsEmpty(bool isEmpty)129     void SetIsEmpty(bool isEmpty)
130     {
131         isEmpty_ = isEmpty;
132     }
133 
GetIsEmpty()134     bool GetIsEmpty() const
135     {
136         return isEmpty_;
137     }
138 
SetMode(NavDestinationMode mode)139     void SetMode(NavDestinationMode mode)
140     {
141         mode_ = mode;
142     }
143 
GetMode()144     NavDestinationMode GetMode() const
145     {
146         return mode_;
147     }
148 
SetUniqueId(int32_t uniqueId)149     void SetUniqueId(int32_t uniqueId)
150     {
151         uniqueId_ = uniqueId;
152     }
153 
GetUniqueId()154     int32_t GetUniqueId() const
155     {
156         return uniqueId_;
157     }
158 
159 protected:
160     int32_t index_ = -1;
161     int32_t preIndex_ = -1;
162     uint64_t navDestinationId_ = 0;
163     NavDestinationMode mode_;
164     RefPtr<NavPathInfo> pathInfo_;
165     bool isEmpty_ = false;
166     WeakPtr<NavigationStack> navigationStack_;
167     int32_t uniqueId_ = -1;
168 };
169 } // namespace OHOS::Ace::NG
170 
171 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVROUTER_NAVDESTINATION_CONTEXT_H
172