• 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_tabcontent_bridge.h"
16 #include "frameworks/bridge/declarative_frontend/jsview/js_tab_content.h"
17 
18 namespace OHOS::Ace::NG {
SetTabBar(ArkUIRuntimeCallInfo * runtimeCallInfo)19 ArkUINativeModuleValue TabContentBridge::SetTabBar(ArkUIRuntimeCallInfo* runtimeCallInfo)
20 {
21     Framework::JSTabContent::SetTabBar(Framework::JsiCallbackInfo(runtimeCallInfo));
22     return panda::JSValueRef::Undefined(runtimeCallInfo->GetVM());
23 }
24 
ResetTabBar(ArkUIRuntimeCallInfo * runtimeCallInfo)25 ArkUINativeModuleValue TabContentBridge::ResetTabBar(ArkUIRuntimeCallInfo* runtimeCallInfo)
26 {
27     EcmaVM* vm = runtimeCallInfo->GetVM();
28     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
29     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
30     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
31     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
32     GetArkUINodeModifiers()->getTabContentModifier()->setTabContentLabel(nativeNode, "");
33     return panda::JSValueRef::Undefined(vm);
34 }
35 
SetTabContentWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)36 ArkUINativeModuleValue TabContentBridge::SetTabContentWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
37 {
38     LOGW("TabContent does not support width and height settings");
39     EcmaVM* vm = runtimeCallInfo->GetVM();
40     return panda::JSValueRef::Undefined(vm);
41 }
42 
SetTabContentHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)43 ArkUINativeModuleValue TabContentBridge::SetTabContentHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
44 {
45     LOGW("TabContent does not support width and height settings");
46     EcmaVM* vm = runtimeCallInfo->GetVM();
47     return panda::JSValueRef::Undefined(vm);
48 }
49 
SetTabContentSize(ArkUIRuntimeCallInfo * runtimeCallInfo)50 ArkUINativeModuleValue TabContentBridge::SetTabContentSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
51 {
52     LOGW("TabContent does not support width and height settings");
53     EcmaVM* vm = runtimeCallInfo->GetVM();
54     return panda::JSValueRef::Undefined(vm);
55 }
ResetTabContentWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)56 ArkUINativeModuleValue TabContentBridge::ResetTabContentWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
57 {
58     LOGW("TabContent does not support width and height settings");
59     EcmaVM* vm = runtimeCallInfo->GetVM();
60     return panda::JSValueRef::Undefined(vm);
61 }
62 
ResetTabContentHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)63 ArkUINativeModuleValue TabContentBridge::ResetTabContentHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
64 {
65     LOGW("TabContent does not support width and height settings");
66     EcmaVM* vm = runtimeCallInfo->GetVM();
67     return panda::JSValueRef::Undefined(vm);
68 }
69 
ResetTabContentSize(ArkUIRuntimeCallInfo * runtimeCallInfo)70 ArkUINativeModuleValue TabContentBridge::ResetTabContentSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
71 {
72     LOGW("TabContent does not support width and height settings");
73     EcmaVM* vm = runtimeCallInfo->GetVM();
74     return panda::JSValueRef::Undefined(vm);
75 }
76 
SetTabContentOnWillShow(ArkUIRuntimeCallInfo * runtimeCallInfo)77 ArkUINativeModuleValue TabContentBridge::SetTabContentOnWillShow(ArkUIRuntimeCallInfo* runtimeCallInfo)
78 {
79     EcmaVM* vm = runtimeCallInfo->GetVM();
80     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
81     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
82     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(1);
83     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
84     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
85     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
86     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
87         GetArkUINodeModifiers()->getTabContentModifier()->resetTabContentOnWillShow(nativeNode);
88         return panda::JSValueRef::Undefined(vm);
89     }
90     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
91     std::function<void()> callback = [vm, frameNode, func = panda::CopyableGlobal(vm, func)]() {
92         panda::LocalScope pandaScope(vm);
93         panda::TryCatch trycatch(vm);
94         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
95         func->Call(vm, func.ToLocal(), nullptr, 0);
96     };
97     GetArkUINodeModifiers()->getTabContentModifier()->setTabContentOnWillShow(
98         nativeNode, reinterpret_cast<void*>(&callback));
99     return panda::JSValueRef::Undefined(vm);
100 }
101 
ResetTabContentOnWillShow(ArkUIRuntimeCallInfo * runtimeCallInfo)102 ArkUINativeModuleValue TabContentBridge::ResetTabContentOnWillShow(ArkUIRuntimeCallInfo* runtimeCallInfo)
103 {
104     EcmaVM* vm = runtimeCallInfo->GetVM();
105     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
106     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
107     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
108     GetArkUINodeModifiers()->getTabContentModifier()->resetTabContentOnWillShow(nativeNode);
109     return panda::JSValueRef::Undefined(vm);
110 }
111 
SetTabContentOnWillHide(ArkUIRuntimeCallInfo * runtimeCallInfo)112 ArkUINativeModuleValue TabContentBridge::SetTabContentOnWillHide(ArkUIRuntimeCallInfo* runtimeCallInfo)
113 {
114     EcmaVM* vm = runtimeCallInfo->GetVM();
115     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
116     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
117     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(1);
118     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
119     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
120     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
121     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
122         GetArkUINodeModifiers()->getTabContentModifier()->resetTabContentOnWillHide(nativeNode);
123         return panda::JSValueRef::Undefined(vm);
124     }
125     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
126     std::function<void()> callback = [vm, frameNode, func = panda::CopyableGlobal(vm, func)]() {
127         panda::LocalScope pandaScope(vm);
128         panda::TryCatch trycatch(vm);
129         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
130         func->Call(vm, func.ToLocal(), nullptr, 0);
131     };
132     GetArkUINodeModifiers()->getTabContentModifier()->setTabContentOnWillHide(
133         nativeNode, reinterpret_cast<void*>(&callback));
134     return panda::JSValueRef::Undefined(vm);
135 }
136 
ResetTabContentOnWillHide(ArkUIRuntimeCallInfo * runtimeCallInfo)137 ArkUINativeModuleValue TabContentBridge::ResetTabContentOnWillHide(ArkUIRuntimeCallInfo* runtimeCallInfo)
138 {
139     EcmaVM* vm = runtimeCallInfo->GetVM();
140     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
141     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
142     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
143     GetArkUINodeModifiers()->getTabContentModifier()->resetTabContentOnWillHide(nativeNode);
144     return panda::JSValueRef::Undefined(vm);
145 }
146 } // namespace OHOS::Ace::NG
147