• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 
16 #include "core/components_ng/pattern/toolbaritem/toolbaritem_model_ng.h"
17 
18 #include "core/components_ng/base/frame_node.h"
19 #include "core/components_ng/base/view_stack_processor.h"
20 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
21 #include "core/components_ng/pattern/toolbaritem/toolbaritem_pattern.h"
22 
23 namespace OHOS::Ace::NG {
24 
Create(int32_t value)25 void ToolBarItemModelNG::Create(int32_t value)
26 {
27     auto* stack = ViewStackProcessor::GetInstance();
28 
29     if (isFirstCreate) {
30         auto nodeId = stack->ClaimNodeId();
31         toolbarNode = FrameNode::GetOrCreateFrameNode(
32             V2::TOOLBAR_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<LinearLayoutPattern>(false); });
33         stack->Push(toolbarNode);
34         isFirstCreate = false;
35     }
36 
37     auto toolbaritemNode = FrameNode::GetOrCreateFrameNode(V2::TOOLBARITEM_ETS_TAG,
38         ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<ToolBarItemPattern>(); });
39     toolbarNode->AddChild(toolbaritemNode);
40     stack->Push(toolbaritemNode);
41 
42     auto pattern = toolbaritemNode->GetPattern<ToolBarItemPattern>();
43     CHECK_NULL_VOID(pattern);
44     pattern->SetPlacement(value);
45 }
46 
SetIsFirstCreate(bool value)47 void ToolBarItemModelNG::SetIsFirstCreate(bool value)
48 {
49     isFirstCreate = value;
50 }
51 
52 } // namespace OHOS::Ace::NG