• 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_SHEET_STYLE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_SHEET_STYLE_H
18 
19 #include <optional>
20 
21 #include "base/geometry/dimension.h"
22 #include "core/components/common/properties/color.h"
23 #include "core/components/common/properties/decoration.h"
24 #include "core/components_ng/pattern/overlay/sheet_theme.h"
25 namespace OHOS::Ace::NG {
26 constexpr float SHEET_VELOCITY_THRESHOLD = 1000.0f;
27 constexpr float CURVE_MASS = 1.0f;
28 constexpr float CURVE_STIFFNESS = 328.0f;
29 constexpr float CURVE_DAMPING = 36.0f;
30 constexpr float MEDIUM_SIZE = 0.6f;
31 constexpr float MEDIUM_SIZE_PRE = 0.5f;
32 constexpr float POPUP_LARGE_SIZE = 0.9f;
33 enum SheetMode {
34     MEDIUM,
35     LARGE,
36     AUTO,
37 };
38 
39 enum SheetType {
40     SHEET_BOTTOM,
41     SHEET_CENTER,
42     SHEET_POPUP,
43     SHEET_BOTTOMLANDSPACE,
44     SHEET_BOTTOM_FREE_WINDOW,
45 };
46 
47 struct SheetKey {
SheetKeySheetKey48     SheetKey() {}
SheetKeySheetKey49     explicit SheetKey(int32_t inputTargetId) : targetId(inputTargetId) {}
SheetKeySheetKey50     SheetKey(bool hasValidTarget, int32_t inputContentId, int32_t inputTargetId)
51         : hasValidTargetNode(hasValidTarget), contentId(inputContentId), targetId(inputTargetId)
52     {
53         isStartUpByUIContext = true;
54     }
55 
56     bool operator==(const SheetKey& other) const
57     {
58         return isStartUpByUIContext == other.isStartUpByUIContext &&
59             hasValidTargetNode == other.hasValidTargetNode &&
60             contentId == other.contentId && targetId == other.targetId;
61     }
62 
63     bool isStartUpByUIContext = false;  // Indicates whether the sheet is started by UIContext
64     bool hasValidTargetNode = true;     // If sheet was start-up by UIContext and without targetId, this flag is FALSE
65     int32_t contentId = -1;             // Indicates the uniqueID of componentContent when isStartUpByUIContext is TRUE
66     int32_t targetId = -1;
67 };
68 
69 struct SheetKeyHash {
operatorSheetKeyHash70     size_t operator()(const SheetKey& sheetKey) const
71     {
72         return sheetKey.isStartUpByUIContext ? sheetKey.contentId : sheetKey.targetId;
73     }
74 };
75 
76 enum SheetLevel {
77     OVERLAY,
78     EMBEDDED,
79 };
80 
81 enum ScrollSizeMode {
82     FOLLOW_DETENT,
83     CONTINUOUS,
84 };
85 
86 struct SheetHeight {
87     std::optional<Dimension> height;
88     std::optional<SheetMode> sheetMode;
89 
90     bool operator==(const SheetHeight& sheetHeight) const
91     {
92         return (height == sheetHeight.height && sheetMode == sheetHeight.sheetMode);
93     }
94 
95     bool operator!=(const SheetHeight& sheetHeight) const
96     {
97         return !(*this == sheetHeight);
98     }
99 };
100 
101 enum class SheetKeyboardAvoidMode {
102     NONE,
103     TRANSLATE_AND_RESIZE,
104     RESIZE_ONLY,
105     TRANSLATE_AND_SCROLL,
106 };
107 
108 struct SheetStyle {
109     std::optional<Dimension> height;
110     std::optional<SheetMode> sheetMode;
111     std::optional<bool> showDragBar;
112     std::optional<bool> showCloseIcon;
113     std::optional<bool> isTitleBuilder;
114     std::optional<SheetType> sheetType;
115     std::optional<Color> backgroundColor;
116     std::optional<Color> maskColor;
117     std::optional<BlurStyleOption> backgroundBlurStyle;
118     std::optional<std::string> sheetTitle;
119     std::optional<std::string> sheetSubtitle;
120     std::vector<SheetHeight> detents;
121     std::optional<bool> interactive;
122     std::optional<bool> showInPage;
123     std::optional<ScrollSizeMode> scrollSizeMode;
124     std::optional<SheetKeyboardAvoidMode> sheetKeyboardAvoidMode;
125     std::optional<NG::BorderWidthProperty> borderWidth; // border width
126     std::optional<NG::BorderColorProperty> borderColor; // border color
127     std::optional<NG::BorderStyleProperty> borderStyle;  // border style
128     std::optional<Shadow> shadow;
129     std::optional<Dimension> width;
130     std::optional<int32_t> instanceId; // uiContext instanceId
131 
132     bool operator==(const SheetStyle& sheetStyle) const
133     {
134         return (height == sheetStyle.height && sheetMode == sheetStyle.sheetMode &&
135                 showDragBar == sheetStyle.showDragBar && showCloseIcon == sheetStyle.showCloseIcon &&
136                 isTitleBuilder == sheetStyle.isTitleBuilder && sheetType == sheetStyle.sheetType &&
137                 backgroundColor == sheetStyle.backgroundColor && maskColor == sheetStyle.maskColor &&
138                 detents == sheetStyle.detents && backgroundBlurStyle == sheetStyle.backgroundBlurStyle &&
139                 sheetTitle == sheetStyle.sheetTitle && sheetSubtitle == sheetStyle.sheetSubtitle &&
140                 interactive == sheetStyle.interactive && showInPage == sheetStyle.showInPage &&
141                 borderWidth == sheetStyle.borderWidth && borderColor == sheetStyle.borderColor &&
142                 borderStyle == sheetStyle.borderStyle && shadow == sheetStyle.shadow && width == sheetStyle.width &&
143                 instanceId == sheetStyle.instanceId && scrollSizeMode == sheetStyle.scrollSizeMode &&
144                 sheetKeyboardAvoidMode == sheetStyle.sheetKeyboardAvoidMode);
145     }
146 
PartialUpdateSheetStyle147     void PartialUpdate(const SheetStyle& sheetStyle)
148     {
149         if (sheetStyle.height.has_value() && !sheetStyle.sheetMode.has_value()) {
150             height = sheetStyle.height;
151             sheetMode.reset();
152         } else if (!sheetStyle.height.has_value() && sheetStyle.sheetMode.has_value()) {
153             sheetMode = sheetStyle.sheetMode;
154             height.reset();
155         } else {
156             sheetMode = sheetStyle.sheetMode.has_value() ? sheetStyle.sheetMode : sheetMode;
157         }
158         showDragBar = sheetStyle.showDragBar.has_value() ? sheetStyle.showDragBar : showDragBar;
159         showCloseIcon = sheetStyle.showCloseIcon.has_value() ? sheetStyle.showCloseIcon : showCloseIcon;
160         isTitleBuilder = sheetStyle.isTitleBuilder.has_value() ? sheetStyle.isTitleBuilder : isTitleBuilder;
161         sheetType = sheetStyle.sheetType.has_value() ? sheetStyle.sheetType : sheetType;
162         backgroundColor = sheetStyle.backgroundColor.has_value() ? sheetStyle.backgroundColor : backgroundColor;
163         maskColor = sheetStyle.maskColor.has_value() ? sheetStyle.maskColor : maskColor;
164         backgroundBlurStyle = sheetStyle.backgroundBlurStyle.has_value() ?
165             sheetStyle.backgroundBlurStyle : backgroundBlurStyle;
166         sheetTitle = sheetStyle.sheetTitle.has_value() ? sheetStyle.sheetTitle : sheetTitle;
167         sheetSubtitle = sheetStyle.sheetSubtitle.has_value() ? sheetStyle.sheetSubtitle : sheetSubtitle;
168         detents = !sheetStyle.detents.empty() ? sheetStyle.detents : detents;
169         interactive = sheetStyle.interactive.has_value() ? sheetStyle.interactive : interactive;
170         scrollSizeMode = sheetStyle.scrollSizeMode.has_value() ? sheetStyle.scrollSizeMode : scrollSizeMode;
171         sheetKeyboardAvoidMode =
172             sheetStyle.sheetKeyboardAvoidMode.has_value() ? sheetStyle.sheetKeyboardAvoidMode : sheetKeyboardAvoidMode;
173         borderWidth = sheetStyle.borderWidth.has_value() ? sheetStyle.borderWidth : borderWidth;
174         borderColor = sheetStyle.borderColor.has_value() ? sheetStyle.borderColor : borderColor;
175         borderStyle = sheetStyle.borderStyle.has_value() ? sheetStyle.borderStyle : borderStyle;
176         shadow = sheetStyle.shadow.has_value() ? sheetStyle.shadow : shadow;
177         width = sheetStyle.width.has_value() ? sheetStyle.width : width;
178     }
179 };
180 } // namespace OHOS::Ace::NG
181 
182 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_SHEET_STYLE_H
183