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 #include "core/interfaces/native/node/tab_content_modifier.h"
16
17 #include "bridge/common/utils/engine_helper.h"
18 #include "core/components_ng/base/frame_node.h"
19 #include "core/components_ng/pattern/tabs/tab_content_model_ng.h"
20 #include "core/interfaces/native/node/view_model.h"
21
22 namespace OHOS::Ace::NG {
23
SetTabContentBuilder(ArkUINodeHandle node,ArkUI_Int32 methodId)24 void SetTabContentBuilder(ArkUINodeHandle node, ArkUI_Int32 methodId)
25 {
26 auto* frameNode = reinterpret_cast<FrameNode*>(node);
27 CHECK_NULL_VOID(frameNode);
28 auto builder = [methodId]() {
29 auto engine = EngineHelper::GetCurrentEngine();
30 CHECK_NULL_VOID(engine);
31 NativeEngine* nativeEngine = engine->GetNativeEngine();
32 ArkUIEventCallbackArg args[] = {};
33 auto dispatch = ViewModel::GetCallbackMethod();
34 CHECK_NULL_VOID(dispatch);
35 auto vmContext = reinterpret_cast<ArkUIVMContext>(nativeEngine);
36 CHECK_NULL_VOID(vmContext);
37 dispatch->CallInt(vmContext, methodId, 0, args);
38 };
39 TabContentModelNG::SetTabBarBuilder(frameNode, std::move(builder));
40 }
41
SetTabContentLabel(ArkUINodeHandle node,ArkUI_CharPtr label)42 void SetTabContentLabel(ArkUINodeHandle node, ArkUI_CharPtr label)
43 {
44 auto* frameNode = reinterpret_cast<FrameNode*>(node);
45 CHECK_NULL_VOID(frameNode);
46 TabContentModelNG::SetTabBarLabel(frameNode, label);
47 }
48
49 namespace NodeModifier {
GetTabContentModifier()50 const ArkUITabContentModifier* GetTabContentModifier()
51 {
52 static const ArkUITabContentModifier modifier = {
53 SetTabContentBuilder,
54 SetTabContentLabel
55 };
56 return &modifier;
57 }
58
GetCJUITabContentModifier()59 const CJUITabContentModifier* GetCJUITabContentModifier()
60 {
61 static const CJUITabContentModifier modifier = {
62 SetTabContentBuilder,
63 SetTabContentLabel
64 };
65 return &modifier;
66 }
67 }
68 }
69