• 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 #include "core/interfaces/native/node/nav_router_modifier.h"
16 
17 #include "core/components_ng/pattern/navrouter/navrouter_model_ng.h"
18 
19 namespace OHOS::Ace::NG {
SetNavRouteMode(ArkUINodeHandle node,int32_t mode)20 void SetNavRouteMode(ArkUINodeHandle node, int32_t mode)
21 {
22     auto* frameNode = reinterpret_cast<FrameNode*>(node);
23     CHECK_NULL_VOID(frameNode);
24     NavRouterModelNG::SetNavRouteMode(frameNode, mode);
25 }
26 
ResetNavRouteMode(ArkUINodeHandle node)27 void ResetNavRouteMode(ArkUINodeHandle node)
28 {
29     auto* frameNode = reinterpret_cast<FrameNode*>(node);
30     CHECK_NULL_VOID(frameNode);
31     NavRouterModelNG::SetNavRouteMode(frameNode, 0);
32 }
33 
SetOnStateChange(ArkUINodeHandle node,void * callback)34 void SetOnStateChange(ArkUINodeHandle node, void* callback)
35 {
36     auto* frameNode = reinterpret_cast<FrameNode*>(node);
37     CHECK_NULL_VOID(frameNode);
38     if (callback) {
39         auto onStateChange = reinterpret_cast<std::function<void(bool)>*>(callback);
40         NavRouterModelNG::SetOnStateChange(frameNode, std::move(*onStateChange));
41     } else {
42         NavRouterModelNG::SetOnStateChange(frameNode, nullptr);
43     }
44 }
45 
ResetOnStateChange(ArkUINodeHandle node)46 void ResetOnStateChange(ArkUINodeHandle node)
47 {
48     auto* frameNode = reinterpret_cast<FrameNode*>(node);
49     CHECK_NULL_VOID(frameNode);
50     NavRouterModelNG::SetOnStateChange(frameNode, nullptr);
51 }
52 
53 namespace NodeModifier {
GetNavRouterModifier()54 const ArkUINavRouterModifier* GetNavRouterModifier()
55 {
56     CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
57     static const ArkUINavRouterModifier modifier = {
58         .setNavRouteMode = SetNavRouteMode,
59         .resetNavRouteMode = ResetNavRouteMode,
60         .setOnStateChange = SetOnStateChange,
61         .resetOnStateChange = ResetOnStateChange,
62     };
63     CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
64 
65     return &modifier;
66 }
67 
GetCJUINavRouterModifier()68 const CJUINavRouterModifier* GetCJUINavRouterModifier()
69 {
70     CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
71     static const CJUINavRouterModifier modifier = {
72         .setNavRouteMode = SetNavRouteMode,
73         .resetNavRouteMode = ResetNavRouteMode,
74     };
75     CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
76 
77     return &modifier;
78 }
79 }
80 }
81