• 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 
16 #include "core/components_ng/pattern/overlay/sheet_view.h"
17 
18 #include "base/geometry/axis.h"
19 #include "base/geometry/ng/offset_t.h"
20 #include "base/utils/utils.h"
21 #include "core/pipeline/base/element_register.h"
22 #include "core/components/common/layout/constants.h"
23 #include "core/components/drag_bar/drag_bar_theme.h"
24 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
25 #include "core/components_ng/pattern/linear_layout/linear_layout_property.h"
26 #include "core/components_ng/pattern/overlay/sheet_drag_bar_pattern.h"
27 #include "core/components_ng/pattern/overlay/sheet_drag_bar_paint_property.h"
28 #include "core/components_ng/pattern/overlay/sheet_presentation_pattern.h"
29 #include "core/components_ng/pattern/overlay/sheet_presentation_property.h"
30 #include "core/components_ng/pattern/overlay/sheet_style.h"
31 #include "core/components_ng/property/measure_property.h"
32 #include "core/components_ng/property/measure_utils.h"
33 #include "core/components_v2/inspector/inspector_constants.h"
34 #include "core/pipeline_ng/pipeline_context.h"
35 
36 namespace OHOS::Ace::NG {
CreateSheetPage(int32_t targetId,RefPtr<FrameNode> builder,std::function<void (const std::string &)> && callback,NG::SheetStyle & sheetStyle)37 RefPtr<FrameNode> SheetView::CreateSheetPage(int32_t targetId, RefPtr<FrameNode> builder,
38     std::function<void(const std::string&)>&& callback, NG::SheetStyle& sheetStyle)
39 {
40     // create sheet node
41     auto sheetNode = FrameNode::CreateFrameNode(V2::SHEET_PAGE_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
42         AceType::MakeRefPtr<SheetPresentationPattern>(targetId, std::move(callback)));
43     auto sheetLayoutProperty = sheetNode->GetLayoutProperty<SheetPresentationProperty>();
44     CHECK_NULL_RETURN(sheetLayoutProperty, nullptr);
45     sheetLayoutProperty->UpdateMainAxisAlign(FlexAlign::FLEX_START);
46     sheetLayoutProperty->UpdateCrossAxisAlign(FlexAlign::CENTER);
47     sheetLayoutProperty->UpdateSheetStyle(sheetStyle);
48     if (sheetStyle.sheetMode.has_value() && sheetStyle.sheetMode == SheetMode::AUTO) {
49         sheetLayoutProperty->UpdateMeasureType(MeasureType::MATCH_PARENT_CROSS_AXIS);
50     }
51 
52     // create drag bar
53     bool isShow = sheetStyle.showDragBar.value_or(true);
54     auto dragBarNode = FrameNode::GetOrCreateFrameNode("SheetDragBar", ElementRegister::GetInstance()->MakeUniqueId(),
55         []() { return AceType::MakeRefPtr<SheetDragBarPattern>(); });
56     auto dragBarLayoutProperty = dragBarNode->GetLayoutProperty();
57     CHECK_NULL_RETURN(dragBarLayoutProperty, nullptr);
58     dragBarLayoutProperty->UpdateUserDefinedIdealSize(
59         CalcSize(CalcLength(SHEET_DRAG_BAR_WIDTH), CalcLength(SHEET_DRAG_BAR_HEIGHT)));
60     dragBarLayoutProperty->UpdateAlignment(Alignment::CENTER);
61     dragBarLayoutProperty->UpdateVisibility(isShow ? VisibleType::VISIBLE : VisibleType::GONE);
62     dragBarNode->MountToParent(sheetNode, 0);
63     dragBarNode->MarkModifyDone();
64     sheetNode->AddChild(builder);
65     sheetNode->MarkModifyDone();
66     return sheetNode;
67 }
68 } // namespace::OHOS::Ace::NG
69