• 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_TRANSITION_PROXY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_TRANSITION_PROXY_H
18 
19 #include "base/memory/ace_type.h"
20 #include "frameworks/core/components_ng/pattern/navigation/navigation_declaration.h"
21 #include "frameworks/core/components_ng/pattern/navrouter/navdestination_group_node.h"
22 #include "frameworks/core/components_ng/pattern/navrouter/navdestination_pattern.h"
23 namespace OHOS::Ace::NG {
24 
25 using namespace Framework;
26 class NavigationTransitionProxy : public AceType {
27     DECLARE_ACE_TYPE(NavigationTransitionProxy, AceType);
28 
29 public:
GetPreDestination()30     NavContentInfo GetPreDestination() const
31     {
32         return preNavInfo_;
33     }
34 
GetTopDestination()35     NavContentInfo GetTopDestination() const
36     {
37         return topNavInfo_;
38     }
39 
SetPreDestination(const RefPtr<NavDestinationGroupNode> & preDestination)40     void SetPreDestination(const RefPtr<NavDestinationGroupNode>& preDestination)
41     {
42         if (!preDestination) {
43             preNavInfo_.index = -1;
44             return;
45         }
46         preNavInfo_.index = preDestination->GetIndex();
47         preNavInfo_.mode = preDestination->GetNavDestinationMode();
48         auto pattern = AceType::DynamicCast<NavDestinationPattern>(preDestination->GetPattern());
49         CHECK_NULL_VOID(pattern);
50         preNavInfo_.name = pattern->GetName();
51     }
52 
SetTopDestination(const RefPtr<NavDestinationGroupNode> & topDestination)53     void SetTopDestination(const RefPtr<NavDestinationGroupNode>& topDestination)
54     {
55         if (!topDestination) {
56             topNavInfo_.index = -1;
57             return;
58         }
59         topNavInfo_.index = topDestination->GetIndex();
60         topNavInfo_.mode = topDestination->GetNavDestinationMode();
61         auto pattern = AceType::DynamicCast<NavDestinationPattern>(topDestination->GetPattern());
62         CHECK_NULL_VOID(pattern);
63         topNavInfo_.name = pattern->GetName();
64     }
65 
SetFinishTransitionEvent(std::function<void (bool)> && event)66     void SetFinishTransitionEvent(std::function<void(bool)>&& event)
67     {
68         finishCallback_ = std::move(event);
69     }
70 
FireFinishCallback()71     void FireFinishCallback()
72     {
73         if (hasFinished_ || !finishCallback_) {
74             return;
75         }
76         finishCallback_(isSuccess_);
77     }
78 
SetIsSuccess(bool isSuccess)79     void SetIsSuccess(bool isSuccess)
80     {
81         isSuccess_ = isSuccess;
82     }
83 
SetIsFinished(bool isFinished)84     void SetIsFinished(bool isFinished)
85     {
86         hasFinished_ = isFinished;
87     }
88 
GetIsFinished()89     bool GetIsFinished() const
90     {
91         return hasFinished_;
92     }
93 
SetNavigationOperation(NavigationOperation operation)94     void SetNavigationOperation(NavigationOperation operation)
95     {
96         operation_ = operation;
97     }
98 
99 private:
100     NavContentInfo preNavInfo_;
101     NavContentInfo topNavInfo_;
102     std::function<void(bool)> finishCallback_;
103     NavigationOperation operation_;
104     bool hasFinished_ = false;
105     bool isSuccess_ = false;
106 };
107 
108 struct NavigationTransition {
109     int32_t timeout = 1000;
110     std::function<void(const RefPtr<NavigationTransitionProxy>&)> transition;
111     std::function<void(bool)> endCallback;
112     bool isValid = true;
113 };
114 } // namespace OHOS::Ace::NG
115 #endif