1c8a96e64Sopenharmony_ci/* 2c8a96e64Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3c8a96e64Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4c8a96e64Sopenharmony_ci * you may not use this file except in compliance with the License. 5c8a96e64Sopenharmony_ci * You may obtain a copy of the License at 6c8a96e64Sopenharmony_ci * 7c8a96e64Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8c8a96e64Sopenharmony_ci * 9c8a96e64Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10c8a96e64Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11c8a96e64Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12c8a96e64Sopenharmony_ci * See the License for the specific language governing permissions and 13c8a96e64Sopenharmony_ci * limitations under the License. 14c8a96e64Sopenharmony_ci */ 15c8a96e64Sopenharmony_ciconst ComponentContent = requireNapi("arkui.node").ComponentContent; 16c8a96e64Sopenharmony_ciconst curves = requireNativeModule('ohos.curves'); 17c8a96e64Sopenharmony_ciconst DIALOG_BORDER_RADIUS = { "id": -1, "type": 10002, params: ['sys.float.ohos_id_corner_radius_default_m'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }; 18c8a96e64Sopenharmony_ciconst DIALOG_INNER_PADDING_SIZE = 16; 19c8a96e64Sopenharmony_ciconst DIALOG_MAX_WIDTH = 480; 20c8a96e64Sopenharmony_ciconst DIALOG_OFFSET_X = 0; 21c8a96e64Sopenharmony_ciconst DIALOG_OFFSET_Y_FOR_BAR = -88; 22c8a96e64Sopenharmony_ciconst DIALOG_OFFSET_Y_FOR_NONE = -44; 23c8a96e64Sopenharmony_ciconst STANDARD_MIN_COMPONENT_HEIGHT = 82; 24c8a96e64Sopenharmony_ciconst STANDARD_MAX_COMPONENT_HEIGHT = 94; 25c8a96e64Sopenharmony_ciconst DIALOG_SHADOW_RADIUS = 16; 26c8a96e64Sopenharmony_ciconst DIALOG_SHADOW_OFFSET_Y = 10; 27c8a96e64Sopenharmony_ciconst DIALOG_SHADOW_COLOR = '#19000000'; 28c8a96e64Sopenharmony_ciconst TITLE_LINE_DISTANCE = 2; 29c8a96e64Sopenharmony_ciconst TITLE_MAX_LINE = 2; 30c8a96e64Sopenharmony_ciconst SUBTITLE_MAX_LINE = 1; 31c8a96e64Sopenharmony_ciconst TEXT_LEFT_MARGIN_SIZE = 16; 32c8a96e64Sopenharmony_ciconst SUBTITLE_DEFAULT_COLOR = { "id": -1, "type": 10001, params: ['sys.color.ohos_id_color_text_secondary_contrary'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }; 33c8a96e64Sopenharmony_ciconst TITLE_DEFAULT_COLOR = { "id": -1, "type": 10001, params: ['sys.color.ohos_id_color_text_primary_contrary'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }; 34c8a96e64Sopenharmony_ciconst OPERATE_AREA_AVOID_WIDTH = 28; 35c8a96e64Sopenharmony_ciconst CLOSE_ICON_DARK_RESOURCE = { "id": -1, "type": 10001, params: ['sys.color.ohos_id_color_tertiary'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }; 36c8a96e64Sopenharmony_ciconst CLOSE_ICON_LIGHT_RESOURCE = { "id": -1, "type": 10001, params: ['sys.color.ohos_id_color_primary_contrary'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }; 37c8a96e64Sopenharmony_ciconst CLOSE_BUTTON_BORDER_RADIUS = 8; 38c8a96e64Sopenharmony_ciconst CLOSE_BUTTON_ICON_SIZE = 16; 39c8a96e64Sopenharmony_ciconst CLOSE_BUTTON_HOT_SPOT_SIZE = 32; 40c8a96e64Sopenharmony_ciconst CLOSE_BUTTON_MARGIN = 8; 41c8a96e64Sopenharmony_ciconst CLOSE_BUTTON_ICON_OPACITY = 0.6; 42c8a96e64Sopenharmony_ciconst CLOSE_BUTTON_RESPONSE_REGION_OFFSET_X = -8; 43c8a96e64Sopenharmony_ciconst CLOSE_BUTTON_RESPONSE_REGION_OFFSET_Y = -8; 44c8a96e64Sopenharmony_ciconst CLOSE_BUTTON_OFFSET_X = 0; 45c8a96e64Sopenharmony_ciconst CLOSE_BUTTON_OFFSET_Y = -50; 46c8a96e64Sopenharmony_ciconst FOREGROUND_IMAGE_OFFSET_X = 4; 47c8a96e64Sopenharmony_ciconst FOREGROUND_IMAGE_OFFSET_Y = 0; 48c8a96e64Sopenharmony_ciexport var IconStyle; 49c8a96e64Sopenharmony_ci(function (e2) { 50c8a96e64Sopenharmony_ci e2[e2["DARK"] = 0] = "DARK"; 51c8a96e64Sopenharmony_ci e2[e2["LIGHT"] = 1] = "LIGHT"; 52c8a96e64Sopenharmony_ci})(IconStyle || (IconStyle = {})); 53c8a96e64Sopenharmony_ciexport var TitlePosition; 54c8a96e64Sopenharmony_ci(function (d2) { 55c8a96e64Sopenharmony_ci d2[d2["TOP"] = 0] = "TOP"; 56c8a96e64Sopenharmony_ci d2[d2["BOTTOM"] = 1] = "BOTTOM"; 57c8a96e64Sopenharmony_ci})(TitlePosition || (TitlePosition = {})); 58c8a96e64Sopenharmony_ciexport var BottomOffset; 59c8a96e64Sopenharmony_ci(function (c2) { 60c8a96e64Sopenharmony_ci c2[c2["OFFSET_FOR_BAR"] = 0] = "OFFSET_FOR_BAR"; 61c8a96e64Sopenharmony_ci c2[c2["OFFSET_FOR_NONE"] = 1] = "OFFSET_FOR_NONE"; 62c8a96e64Sopenharmony_ci})(BottomOffset || (BottomOffset = {})); 63c8a96e64Sopenharmony_ciclass DialogParams { 64c8a96e64Sopenharmony_ci constructor(a2, b2) { 65c8a96e64Sopenharmony_ci this.options = a2; 66c8a96e64Sopenharmony_ci this.defaultCloseAction = b2; 67c8a96e64Sopenharmony_ci } 68c8a96e64Sopenharmony_ci} 69c8a96e64Sopenharmony_cifunction dialogBuilder(k, l = null) { 70c8a96e64Sopenharmony_ci const m = k; 71c8a96e64Sopenharmony_ci (l ? l : this).observeComponentCreation2((x1, y1, z1 = m) => { 72c8a96e64Sopenharmony_ci Row.create(); 73c8a96e64Sopenharmony_ci Row.backgroundColor('rgba(0,0,0,0)'); 74c8a96e64Sopenharmony_ci Row.width('100%'); 75c8a96e64Sopenharmony_ci Row.height(STANDARD_MAX_COMPONENT_HEIGHT); 76c8a96e64Sopenharmony_ci Row.padding({ 77c8a96e64Sopenharmony_ci left: DIALOG_INNER_PADDING_SIZE, 78c8a96e64Sopenharmony_ci right: DIALOG_INNER_PADDING_SIZE 79c8a96e64Sopenharmony_ci }); 80c8a96e64Sopenharmony_ci Row.constraintSize({ 81c8a96e64Sopenharmony_ci minHeight: STANDARD_MIN_COMPONENT_HEIGHT, 82c8a96e64Sopenharmony_ci maxHeight: STANDARD_MAX_COMPONENT_HEIGHT, 83c8a96e64Sopenharmony_ci maxWidth: DIALOG_MAX_WIDTH 84c8a96e64Sopenharmony_ci }); 85c8a96e64Sopenharmony_ci }, Row); 86c8a96e64Sopenharmony_ci (l ? l : this).observeComponentCreation2((t1, u1, v1 = m) => { 87c8a96e64Sopenharmony_ci Flex.create(); 88c8a96e64Sopenharmony_ci Flex.backgroundColor(v1.options.backgroundImage === undefined ? '#EBEEF5' : 'rgba(0,0,0,0)'); 89c8a96e64Sopenharmony_ci Flex.shadow({ 90c8a96e64Sopenharmony_ci radius: DIALOG_SHADOW_RADIUS, 91c8a96e64Sopenharmony_ci offsetX: 0, 92c8a96e64Sopenharmony_ci offsetY: DIALOG_SHADOW_OFFSET_Y, 93c8a96e64Sopenharmony_ci color: DIALOG_SHADOW_COLOR 94c8a96e64Sopenharmony_ci }); 95c8a96e64Sopenharmony_ci Flex.height(STANDARD_MIN_COMPONENT_HEIGHT); 96c8a96e64Sopenharmony_ci Flex.width('100%'); 97c8a96e64Sopenharmony_ci Flex.alignSelf(ItemAlign.End); 98c8a96e64Sopenharmony_ci Flex.direction(Direction.Rtl); 99c8a96e64Sopenharmony_ci Flex.zIndex(1); 100c8a96e64Sopenharmony_ci Flex.borderRadius({ 101c8a96e64Sopenharmony_ci topLeft: DIALOG_BORDER_RADIUS, 102c8a96e64Sopenharmony_ci topRight: DIALOG_BORDER_RADIUS, 103c8a96e64Sopenharmony_ci bottomLeft: DIALOG_BORDER_RADIUS, 104c8a96e64Sopenharmony_ci bottomRight: DIALOG_BORDER_RADIUS 105c8a96e64Sopenharmony_ci }); 106c8a96e64Sopenharmony_ci Flex.onClick(() => { 107c8a96e64Sopenharmony_ci if (v1.options.onDialogClick !== undefined) { 108c8a96e64Sopenharmony_ci v1.options.onDialogClick(); 109c8a96e64Sopenharmony_ci } 110c8a96e64Sopenharmony_ci v1.defaultCloseAction(); 111c8a96e64Sopenharmony_ci }); 112c8a96e64Sopenharmony_ci }, Flex); 113c8a96e64Sopenharmony_ci (l ? l : this).observeComponentCreation2((q1, r1, s1 = m) => { 114c8a96e64Sopenharmony_ci Row.create(); 115c8a96e64Sopenharmony_ci Row.padding({ left: OPERATE_AREA_AVOID_WIDTH }); 116c8a96e64Sopenharmony_ci Row.direction(Direction.Rtl); 117c8a96e64Sopenharmony_ci Row.defaultFocus(true); 118c8a96e64Sopenharmony_ci Row.align(Alignment.End); 119c8a96e64Sopenharmony_ci Row.alignSelf(ItemAlign.End); 120c8a96e64Sopenharmony_ci Row.constraintSize({ 121c8a96e64Sopenharmony_ci maxWidth: '50%', 122c8a96e64Sopenharmony_ci minWidth: '40%' 123c8a96e64Sopenharmony_ci }); 124c8a96e64Sopenharmony_ci }, Row); 125c8a96e64Sopenharmony_ci (l ? l : this).observeComponentCreation2((m1, n1, o1 = m) => { 126c8a96e64Sopenharmony_ci SymbolGlyph.create({ "id": -1, "type": 40000, params: ['sys.symbol.xmark_circle_fill'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }); 127c8a96e64Sopenharmony_ci SymbolGlyph.fontColor([o1.options.iconStyle === IconStyle.DARK ? 128c8a96e64Sopenharmony_ci CLOSE_ICON_DARK_RESOURCE : CLOSE_ICON_LIGHT_RESOURCE]); 129c8a96e64Sopenharmony_ci SymbolGlyph.borderRadius(CLOSE_BUTTON_BORDER_RADIUS); 130c8a96e64Sopenharmony_ci SymbolGlyph.width(CLOSE_BUTTON_ICON_SIZE); 131c8a96e64Sopenharmony_ci SymbolGlyph.height(CLOSE_BUTTON_ICON_SIZE); 132c8a96e64Sopenharmony_ci SymbolGlyph.opacity(CLOSE_BUTTON_ICON_OPACITY); 133c8a96e64Sopenharmony_ci SymbolGlyph.draggable(false); 134c8a96e64Sopenharmony_ci SymbolGlyph.focusable(true); 135c8a96e64Sopenharmony_ci SymbolGlyph.responseRegion({ 136c8a96e64Sopenharmony_ci x: CLOSE_BUTTON_RESPONSE_REGION_OFFSET_X, 137c8a96e64Sopenharmony_ci y: CLOSE_BUTTON_RESPONSE_REGION_OFFSET_Y, 138c8a96e64Sopenharmony_ci width: CLOSE_BUTTON_HOT_SPOT_SIZE, 139c8a96e64Sopenharmony_ci height: CLOSE_BUTTON_HOT_SPOT_SIZE 140c8a96e64Sopenharmony_ci }); 141c8a96e64Sopenharmony_ci SymbolGlyph.margin(CLOSE_BUTTON_MARGIN); 142c8a96e64Sopenharmony_ci SymbolGlyph.alignSelf(ItemAlign.End); 143c8a96e64Sopenharmony_ci SymbolGlyph.offset({ 144c8a96e64Sopenharmony_ci x: CLOSE_BUTTON_OFFSET_X, 145c8a96e64Sopenharmony_ci y: CLOSE_BUTTON_OFFSET_Y 146c8a96e64Sopenharmony_ci }); 147c8a96e64Sopenharmony_ci SymbolGlyph.onClick(() => { 148c8a96e64Sopenharmony_ci if (o1.options.onDialogClose !== undefined) { 149c8a96e64Sopenharmony_ci o1.options.onDialogClose(); 150c8a96e64Sopenharmony_ci } 151c8a96e64Sopenharmony_ci o1.defaultCloseAction(); 152c8a96e64Sopenharmony_ci }); 153c8a96e64Sopenharmony_ci }, SymbolGlyph); 154c8a96e64Sopenharmony_ci (l ? l : this).observeComponentCreation2((j1, k1, l1 = m) => { 155c8a96e64Sopenharmony_ci Image.create(l1.options.foregroundImage); 156c8a96e64Sopenharmony_ci Image.height(STANDARD_MAX_COMPONENT_HEIGHT); 157c8a96e64Sopenharmony_ci Image.objectFit(ImageFit.Contain); 158c8a96e64Sopenharmony_ci Image.fitOriginalSize(true); 159c8a96e64Sopenharmony_ci Image.offset({ 160c8a96e64Sopenharmony_ci x: FOREGROUND_IMAGE_OFFSET_X, 161c8a96e64Sopenharmony_ci y: FOREGROUND_IMAGE_OFFSET_Y 162c8a96e64Sopenharmony_ci }); 163c8a96e64Sopenharmony_ci Image.alignSelf(ItemAlign.End); 164c8a96e64Sopenharmony_ci }, Image); 165c8a96e64Sopenharmony_ci Row.pop(); 166c8a96e64Sopenharmony_ci (l ? l : this).observeComponentCreation2((g1, h1, i1 = m) => { 167c8a96e64Sopenharmony_ci Flex.create({ 168c8a96e64Sopenharmony_ci direction: i1.options.titlePosition === TitlePosition.BOTTOM ? 169c8a96e64Sopenharmony_ci FlexDirection.ColumnReverse : FlexDirection.Column, 170c8a96e64Sopenharmony_ci justifyContent: FlexAlign.Center 171c8a96e64Sopenharmony_ci }); 172c8a96e64Sopenharmony_ci Flex.constraintSize({ 173c8a96e64Sopenharmony_ci maxWidth: '60%', 174c8a96e64Sopenharmony_ci minWidth: '50%' 175c8a96e64Sopenharmony_ci }); 176c8a96e64Sopenharmony_ci Flex.flexGrow(1); 177c8a96e64Sopenharmony_ci Flex.margin({ left: TEXT_LEFT_MARGIN_SIZE }); 178c8a96e64Sopenharmony_ci }, Flex); 179c8a96e64Sopenharmony_ci (l ? l : this).observeComponentCreation2((d1, e1, f1 = m) => { 180c8a96e64Sopenharmony_ci Text.create(f1.options.title); 181c8a96e64Sopenharmony_ci Text.alignSelf(ItemAlign.Start); 182c8a96e64Sopenharmony_ci Text.maxFontSize({ "id": -1, "type": 10002, params: ['sys.float.ohos_id_text_size_sub_title1'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }); 183c8a96e64Sopenharmony_ci Text.minFontSize(16); 184c8a96e64Sopenharmony_ci Text.fontColor(f1.options.titleColor !== undefined ? f1.options.titleColor : TITLE_DEFAULT_COLOR); 185c8a96e64Sopenharmony_ci Text.fontWeight(FontWeight.Bold); 186c8a96e64Sopenharmony_ci Text.margin(f1.options.titlePosition ? { top: TITLE_LINE_DISTANCE } : { bottom: TITLE_LINE_DISTANCE }); 187c8a96e64Sopenharmony_ci Text.maxLines(TITLE_MAX_LINE); 188c8a96e64Sopenharmony_ci Text.wordBreak(WordBreak.BREAK_WORD); 189c8a96e64Sopenharmony_ci Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 190c8a96e64Sopenharmony_ci }, Text); 191c8a96e64Sopenharmony_ci Text.pop(); 192c8a96e64Sopenharmony_ci (l ? l : this).observeComponentCreation2((a1, b1, c1 = m) => { 193c8a96e64Sopenharmony_ci Text.create(c1.options.subtitle); 194c8a96e64Sopenharmony_ci Text.alignSelf(ItemAlign.Start); 195c8a96e64Sopenharmony_ci Text.maxFontSize({ "id": -1, "type": 10002, params: ['sys.float.ohos_id_text_size_caption'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }); 196c8a96e64Sopenharmony_ci Text.minFontSize(9); 197c8a96e64Sopenharmony_ci Text.fontColor(c1.options.subtitleColor !== undefined ? c1.options.subtitleColor : SUBTITLE_DEFAULT_COLOR); 198c8a96e64Sopenharmony_ci Text.maxLines(SUBTITLE_MAX_LINE); 199c8a96e64Sopenharmony_ci Text.wordBreak(WordBreak.BREAK_WORD); 200c8a96e64Sopenharmony_ci Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 201c8a96e64Sopenharmony_ci }, Text); 202c8a96e64Sopenharmony_ci Text.pop(); 203c8a96e64Sopenharmony_ci Flex.pop(); 204c8a96e64Sopenharmony_ci Flex.pop(); 205c8a96e64Sopenharmony_ci (l ? l : this).observeComponentCreation2((w, x, y = m) => { 206c8a96e64Sopenharmony_ci Image.create(y.options.backgroundImage); 207c8a96e64Sopenharmony_ci Image.width('100%'); 208c8a96e64Sopenharmony_ci Image.height(STANDARD_MIN_COMPONENT_HEIGHT); 209c8a96e64Sopenharmony_ci Image.offset({ x: '-100%', y: 0 }); 210c8a96e64Sopenharmony_ci Image.borderRadius(DIALOG_BORDER_RADIUS); 211c8a96e64Sopenharmony_ci Image.zIndex(0); 212c8a96e64Sopenharmony_ci Image.alignSelf(ItemAlign.End); 213c8a96e64Sopenharmony_ci Image.onClick(() => { 214c8a96e64Sopenharmony_ci if (y.options.onDialogClose !== undefined) { 215c8a96e64Sopenharmony_ci y.options.onDialogClose(); 216c8a96e64Sopenharmony_ci } 217c8a96e64Sopenharmony_ci y.defaultCloseAction(); 218c8a96e64Sopenharmony_ci }); 219c8a96e64Sopenharmony_ci }, Image); 220c8a96e64Sopenharmony_ci Row.pop(); 221c8a96e64Sopenharmony_ci} 222c8a96e64Sopenharmony_ciexport class InterstitialDialogAction { 223c8a96e64Sopenharmony_ci constructor(i) { 224c8a96e64Sopenharmony_ci this.uiContext = i.uiContext; 225c8a96e64Sopenharmony_ci this.bottomOffsetType = i.bottomOffsetType; 226c8a96e64Sopenharmony_ci this.dialogParam = new DialogParams(i, () => { 227c8a96e64Sopenharmony_ci this.closeDialog(); 228c8a96e64Sopenharmony_ci }); 229c8a96e64Sopenharmony_ci this.contentNode = new ComponentContent(this.uiContext, wrapBuilder(dialogBuilder), this.dialogParam); 230c8a96e64Sopenharmony_ci } 231c8a96e64Sopenharmony_ci openDialog() { 232c8a96e64Sopenharmony_ci if (this.contentNode !== null) { 233c8a96e64Sopenharmony_ci this.uiContext.getPromptAction().openCustomDialog(this.contentNode, { 234c8a96e64Sopenharmony_ci isModal: false, 235c8a96e64Sopenharmony_ci autoCancel: false, 236c8a96e64Sopenharmony_ci offset: { 237c8a96e64Sopenharmony_ci dx: DIALOG_OFFSET_X, 238c8a96e64Sopenharmony_ci dy: this.bottomOffsetType === BottomOffset.OFFSET_FOR_BAR ? 239c8a96e64Sopenharmony_ci DIALOG_OFFSET_Y_FOR_BAR : DIALOG_OFFSET_Y_FOR_NONE 240c8a96e64Sopenharmony_ci }, 241c8a96e64Sopenharmony_ci alignment: DialogAlignment.Bottom, 242c8a96e64Sopenharmony_ci transition: TransitionEffect.asymmetric(TransitionEffect.OPACITY.animation({ duration: 150, curve: Curve.Sharp }) 243c8a96e64Sopenharmony_ci .combine(TransitionEffect.scale({ x: 0.85, y: 0.85, centerX: '50%', centerY: '85%' }) 244c8a96e64Sopenharmony_ci .animation({ curve: curves.interpolatingSpring(0, 1, 228, 24) })), TransitionEffect.OPACITY.animation({ duration: 250, curve: Curve.Sharp }) 245c8a96e64Sopenharmony_ci .combine(TransitionEffect.scale({ x: 0.85, y: 0.85, centerX: '50%', centerY: '85%' }) 246c8a96e64Sopenharmony_ci .animation({ duration: 250, curve: Curve.Friction }))) 247c8a96e64Sopenharmony_ci }) 248c8a96e64Sopenharmony_ci .catch((f) => { 249c8a96e64Sopenharmony_ci let g = f.message; 250c8a96e64Sopenharmony_ci let h = f.code; 251c8a96e64Sopenharmony_ci console.error(`${h}: ${g}`); 252c8a96e64Sopenharmony_ci }); 253c8a96e64Sopenharmony_ci } 254c8a96e64Sopenharmony_ci } 255c8a96e64Sopenharmony_ci closeDialog() { 256c8a96e64Sopenharmony_ci if (this.contentNode !== null) { 257c8a96e64Sopenharmony_ci this.uiContext.getPromptAction().closeCustomDialog(this.contentNode) 258c8a96e64Sopenharmony_ci .catch((b) => { 259c8a96e64Sopenharmony_ci let c = b.message; 260c8a96e64Sopenharmony_ci let d = b.code; 261c8a96e64Sopenharmony_ci console.error(`${d}: ${c}`); 262c8a96e64Sopenharmony_ci }); 263c8a96e64Sopenharmony_ci } 264c8a96e64Sopenharmony_ci } 265c8a96e64Sopenharmony_ci} 266c8a96e64Sopenharmony_ci 267c8a96e64Sopenharmony_ciexport default { InterstitialDialogAction, IconStyle, TitlePosition, BottomOffset };