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