• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/pattern/tabs/tab_content_model_ng.h"
19 #include "core/interfaces/native/node/view_model.h"
20 
21 namespace OHOS::Ace::NG {
22 
SetTabContentBuilder(ArkUINodeHandle node,ArkUI_Int32 methodId)23 void SetTabContentBuilder(ArkUINodeHandle node, ArkUI_Int32 methodId)
24 {
25     auto* frameNode = reinterpret_cast<FrameNode*>(node);
26     CHECK_NULL_VOID(frameNode);
27     auto builder = [methodId]() {
28         auto engine = EngineHelper::GetCurrentEngine();
29         CHECK_NULL_VOID(engine);
30         NativeEngine* nativeEngine = engine->GetNativeEngine();
31         ArkUIEventCallbackArg args[] = {};
32         auto dispatch = ViewModel::GetCallbackMethod();
33         CHECK_NULL_VOID(dispatch);
34         auto vmContext = reinterpret_cast<ArkUIVMContext>(nativeEngine);
35         CHECK_NULL_VOID(vmContext);
36         dispatch->CallInt(vmContext, methodId, 0, args);
37     };
38     TabContentModelNG::SetTabBarBuilder(frameNode, std::move(builder));
39 }
40 
SetTabContentLabel(ArkUINodeHandle node,ArkUI_CharPtr label)41 void SetTabContentLabel(ArkUINodeHandle node, ArkUI_CharPtr label)
42 {
43     auto* frameNode = reinterpret_cast<FrameNode*>(node);
44     CHECK_NULL_VOID(frameNode);
45     TabContentModelNG::SetTabBarLabel(frameNode, label);
46 
47     CHECK_NULL_VOID(SystemProperties::ConfigChangePerform());
48     TabContentModelNG::CreateTextContentWithResourceObj(frameNode, nullptr);
49 }
50 
SetTabContentOnWillShow(ArkUINodeHandle node,void * callback)51 void SetTabContentOnWillShow(ArkUINodeHandle node, void* callback)
52 {
53     auto* frameNode = reinterpret_cast<FrameNode*>(node);
54     CHECK_NULL_VOID(frameNode);
55     if (callback) {
56         auto onWillShow = reinterpret_cast<std::function<void()>*>(callback);
57         TabContentModelNG::SetOnWillShow(frameNode, std::move(*onWillShow));
58     } else {
59         TabContentModelNG::SetOnWillShow(frameNode, nullptr);
60     }
61 }
62 
ResetTabContentOnWillShow(ArkUINodeHandle node)63 void ResetTabContentOnWillShow(ArkUINodeHandle node)
64 {
65     auto* frameNode = reinterpret_cast<FrameNode*>(node);
66     CHECK_NULL_VOID(frameNode);
67     TabContentModelNG::SetOnWillShow(frameNode, nullptr);
68 }
69 
SetTabContentOnWillHide(ArkUINodeHandle node,void * callback)70 void SetTabContentOnWillHide(ArkUINodeHandle node, void* callback)
71 {
72     auto* frameNode = reinterpret_cast<FrameNode*>(node);
73     CHECK_NULL_VOID(frameNode);
74     if (callback) {
75         auto onWillHide = reinterpret_cast<std::function<void()>*>(callback);
76         TabContentModelNG::SetOnWillHide(frameNode, std::move(*onWillHide));
77     } else {
78         TabContentModelNG::SetOnWillHide(frameNode, nullptr);
79     }
80 }
81 
ResetTabContentOnWillHide(ArkUINodeHandle node)82 void ResetTabContentOnWillHide(ArkUINodeHandle node)
83 {
84     auto* frameNode = reinterpret_cast<FrameNode*>(node);
85     CHECK_NULL_VOID(frameNode);
86     TabContentModelNG::SetOnWillHide(frameNode, nullptr);
87 }
88 
89 namespace NodeModifier {
GetTabContentModifier()90 const ArkUITabContentModifier* GetTabContentModifier()
91 {
92     CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
93     static const ArkUITabContentModifier modifier = {
94         .setTabContentBuilder = SetTabContentBuilder,
95         .setTabContentLabel = SetTabContentLabel,
96         .setTabContentOnWillShow = SetTabContentOnWillShow,
97         .resetTabContentOnWillShow = ResetTabContentOnWillShow,
98         .setTabContentOnWillHide = SetTabContentOnWillHide,
99         .resetTabContentOnWillHide = ResetTabContentOnWillHide,
100     };
101     CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
102 
103     return &modifier;
104 }
105 
GetCJUITabContentModifier()106 const CJUITabContentModifier* GetCJUITabContentModifier()
107 {
108     CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
109     static const CJUITabContentModifier modifier = {
110         .setTabContentBuilder = SetTabContentBuilder,
111         .setTabContentLabel = SetTabContentLabel,
112     };
113     CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
114 
115     return &modifier;
116 }
117 }
118 }
119