• 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 "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_nav_router_bridge.h"
16 
17 #include "core/interfaces/native/node/api.h"
18 
19 namespace OHOS::Ace::NG {
20 constexpr int32_t CALL_ARG_0 = 0;
21 constexpr int32_t CALL_ARG_1 = 1;
22 constexpr int32_t NAV_ROUTE_MODE_RANGE = 2;
23 constexpr int32_t NAV_ROUTE_MODE_DEFAULT = 0;
SetMode(ArkUIRuntimeCallInfo * runtimeCallInfo)24 ArkUINativeModuleValue NavRouterBridge::SetMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
25 {
26     EcmaVM* vm = runtimeCallInfo->GetVM();
27     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
28     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_0);
29     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_1);
30     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
31 
32     if (valueArg->IsNumber()) {
33         int32_t value = valueArg->Int32Value(vm);
34         if (value >= NAV_ROUTE_MODE_DEFAULT && value <= NAV_ROUTE_MODE_RANGE) {
35             GetArkUIInternalNodeAPI()->GetNavRouterModifier().SetNavRouteMode(nativeNode, value);
36         } else {
37             GetArkUIInternalNodeAPI()->GetNavRouterModifier().ResetNavRouteMode(nativeNode);
38         }
39     } else {
40         GetArkUIInternalNodeAPI()->GetNavRouterModifier().ResetNavRouteMode(nativeNode);
41     }
42 
43     return panda::JSValueRef::Undefined(vm);
44 }
45 
ResetMode(ArkUIRuntimeCallInfo * runtimeCallInfo)46 ArkUINativeModuleValue NavRouterBridge::ResetMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
47 {
48     EcmaVM* vm = runtimeCallInfo->GetVM();
49     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
50     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_0);
51     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
52     GetArkUIInternalNodeAPI()->GetNavRouterModifier().ResetNavRouteMode(nativeNode);
53     return panda::JSValueRef::Undefined(vm);
54 }
55 } // namespace OHOS::Ace::NG
56