123b3eb3cSopenharmony_ci/* 223b3eb3cSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License. 523b3eb3cSopenharmony_ci * You may obtain a copy of the License at 623b3eb3cSopenharmony_ci * 723b3eb3cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 823b3eb3cSopenharmony_ci * 923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and 1323b3eb3cSopenharmony_ci * limitations under the License. 1423b3eb3cSopenharmony_ci */ 1523b3eb3cSopenharmony_ciconst ComponentContent = requireNapi("arkui.node").ComponentContent; 1623b3eb3cSopenharmony_ciconst curves = requireNativeModule('ohos.curves'); 1723b3eb3cSopenharmony_ciconst DIALOG_BORDER_RADIUS = { "id": -1, "type": 10002, params: ['sys.float.ohos_id_corner_radius_default_m'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }; 1823b3eb3cSopenharmony_ciconst DIALOG_INNER_PADDING_SIZE = 16; 1923b3eb3cSopenharmony_ciconst DIALOG_MAX_WIDTH = 480; 2023b3eb3cSopenharmony_ciconst DIALOG_OFFSET_X = 0; 2123b3eb3cSopenharmony_ciconst DIALOG_OFFSET_Y_FOR_BAR = -88; 2223b3eb3cSopenharmony_ciconst DIALOG_OFFSET_Y_FOR_NONE = -44; 2323b3eb3cSopenharmony_ciconst STANDARD_MIN_COMPONENT_HEIGHT = 82; 2423b3eb3cSopenharmony_ciconst STANDARD_MAX_COMPONENT_HEIGHT = 94; 2523b3eb3cSopenharmony_ciconst DIALOG_SHADOW_RADIUS = 16; 2623b3eb3cSopenharmony_ciconst DIALOG_SHADOW_OFFSET_Y = 10; 2723b3eb3cSopenharmony_ciconst DIALOG_SHADOW_COLOR = '#19000000'; 2823b3eb3cSopenharmony_ciconst TITLE_LINE_DISTANCE = 2; 2923b3eb3cSopenharmony_ciconst TITLE_MAX_LINE = 2; 3023b3eb3cSopenharmony_ciconst SUBTITLE_MAX_LINE = 1; 3123b3eb3cSopenharmony_ciconst TEXT_LEFT_MARGIN_SIZE = 16; 3223b3eb3cSopenharmony_ciconst SUBTITLE_DEFAULT_COLOR = { "id": -1, "type": 10001, params: ['sys.color.ohos_id_color_text_secondary_contrary'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }; 3323b3eb3cSopenharmony_ciconst TITLE_DEFAULT_COLOR = { "id": -1, "type": 10001, params: ['sys.color.ohos_id_color_text_primary_contrary'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }; 3423b3eb3cSopenharmony_ciconst OPERATE_AREA_AVOID_WIDTH = 28; 3523b3eb3cSopenharmony_ciconst CLOSE_ICON_DARK_RESOURCE = { "id": -1, "type": 10001, params: ['sys.color.ohos_id_color_tertiary'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }; 3623b3eb3cSopenharmony_ciconst CLOSE_ICON_LIGHT_RESOURCE = { "id": -1, "type": 10001, params: ['sys.color.ohos_id_color_primary_contrary'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }; 3723b3eb3cSopenharmony_ciconst CLOSE_BUTTON_BORDER_RADIUS = 8; 3823b3eb3cSopenharmony_ciconst CLOSE_BUTTON_ICON_SIZE = 16; 3923b3eb3cSopenharmony_ciconst CLOSE_BUTTON_HOT_SPOT_SIZE = 32; 4023b3eb3cSopenharmony_ciconst CLOSE_BUTTON_MARGIN = 8; 4123b3eb3cSopenharmony_ciconst CLOSE_BUTTON_ICON_OPACITY = 0.6; 4223b3eb3cSopenharmony_ciconst CLOSE_BUTTON_RESPONSE_REGION_OFFSET_X = -8; 4323b3eb3cSopenharmony_ciconst CLOSE_BUTTON_RESPONSE_REGION_OFFSET_Y = -8; 4423b3eb3cSopenharmony_ciconst CLOSE_BUTTON_OFFSET_X = 0; 4523b3eb3cSopenharmony_ciconst CLOSE_BUTTON_OFFSET_Y = -50; 4623b3eb3cSopenharmony_ciconst FOREGROUND_IMAGE_OFFSET_X = 4; 4723b3eb3cSopenharmony_ciconst FOREGROUND_IMAGE_OFFSET_Y = 0; 4823b3eb3cSopenharmony_ciexport var IconStyle; 4923b3eb3cSopenharmony_ci(function (e2) { 5023b3eb3cSopenharmony_ci e2[e2["DARK"] = 0] = "DARK"; 5123b3eb3cSopenharmony_ci e2[e2["LIGHT"] = 1] = "LIGHT"; 5223b3eb3cSopenharmony_ci})(IconStyle || (IconStyle = {})); 5323b3eb3cSopenharmony_ciexport var TitlePosition; 5423b3eb3cSopenharmony_ci(function (d2) { 5523b3eb3cSopenharmony_ci d2[d2["TOP"] = 0] = "TOP"; 5623b3eb3cSopenharmony_ci d2[d2["BOTTOM"] = 1] = "BOTTOM"; 5723b3eb3cSopenharmony_ci})(TitlePosition || (TitlePosition = {})); 5823b3eb3cSopenharmony_ciexport var BottomOffset; 5923b3eb3cSopenharmony_ci(function (c2) { 6023b3eb3cSopenharmony_ci c2[c2["OFFSET_FOR_BAR"] = 0] = "OFFSET_FOR_BAR"; 6123b3eb3cSopenharmony_ci c2[c2["OFFSET_FOR_NONE"] = 1] = "OFFSET_FOR_NONE"; 6223b3eb3cSopenharmony_ci})(BottomOffset || (BottomOffset = {})); 6323b3eb3cSopenharmony_ciclass DialogParams { 6423b3eb3cSopenharmony_ci constructor(a2, b2) { 6523b3eb3cSopenharmony_ci this.options = a2; 6623b3eb3cSopenharmony_ci this.defaultCloseAction = b2; 6723b3eb3cSopenharmony_ci } 6823b3eb3cSopenharmony_ci} 6923b3eb3cSopenharmony_cifunction dialogBuilder(k, l = null) { 7023b3eb3cSopenharmony_ci const m = k; 7123b3eb3cSopenharmony_ci (l ? l : this).observeComponentCreation2((x1, y1, z1 = m) => { 7223b3eb3cSopenharmony_ci Row.create(); 7323b3eb3cSopenharmony_ci Row.backgroundColor('rgba(0,0,0,0)'); 7423b3eb3cSopenharmony_ci Row.width('100%'); 7523b3eb3cSopenharmony_ci Row.height(STANDARD_MAX_COMPONENT_HEIGHT); 7623b3eb3cSopenharmony_ci Row.padding({ 7723b3eb3cSopenharmony_ci left: DIALOG_INNER_PADDING_SIZE, 7823b3eb3cSopenharmony_ci right: DIALOG_INNER_PADDING_SIZE 7923b3eb3cSopenharmony_ci }); 8023b3eb3cSopenharmony_ci Row.constraintSize({ 8123b3eb3cSopenharmony_ci minHeight: STANDARD_MIN_COMPONENT_HEIGHT, 8223b3eb3cSopenharmony_ci maxHeight: STANDARD_MAX_COMPONENT_HEIGHT, 8323b3eb3cSopenharmony_ci maxWidth: DIALOG_MAX_WIDTH 8423b3eb3cSopenharmony_ci }); 8523b3eb3cSopenharmony_ci }, Row); 8623b3eb3cSopenharmony_ci (l ? l : this).observeComponentCreation2((t1, u1, v1 = m) => { 8723b3eb3cSopenharmony_ci Flex.create(); 8823b3eb3cSopenharmony_ci Flex.backgroundColor(v1.options.backgroundImage === undefined ? '#EBEEF5' : 'rgba(0,0,0,0)'); 8923b3eb3cSopenharmony_ci Flex.shadow({ 9023b3eb3cSopenharmony_ci radius: DIALOG_SHADOW_RADIUS, 9123b3eb3cSopenharmony_ci offsetX: 0, 9223b3eb3cSopenharmony_ci offsetY: DIALOG_SHADOW_OFFSET_Y, 9323b3eb3cSopenharmony_ci color: DIALOG_SHADOW_COLOR 9423b3eb3cSopenharmony_ci }); 9523b3eb3cSopenharmony_ci Flex.height(STANDARD_MIN_COMPONENT_HEIGHT); 9623b3eb3cSopenharmony_ci Flex.width('100%'); 9723b3eb3cSopenharmony_ci Flex.alignSelf(ItemAlign.End); 9823b3eb3cSopenharmony_ci Flex.direction(Direction.Rtl); 9923b3eb3cSopenharmony_ci Flex.zIndex(1); 10023b3eb3cSopenharmony_ci Flex.borderRadius({ 10123b3eb3cSopenharmony_ci topLeft: DIALOG_BORDER_RADIUS, 10223b3eb3cSopenharmony_ci topRight: DIALOG_BORDER_RADIUS, 10323b3eb3cSopenharmony_ci bottomLeft: DIALOG_BORDER_RADIUS, 10423b3eb3cSopenharmony_ci bottomRight: DIALOG_BORDER_RADIUS 10523b3eb3cSopenharmony_ci }); 10623b3eb3cSopenharmony_ci Flex.onClick(() => { 10723b3eb3cSopenharmony_ci if (v1.options.onDialogClick !== undefined) { 10823b3eb3cSopenharmony_ci v1.options.onDialogClick(); 10923b3eb3cSopenharmony_ci } 11023b3eb3cSopenharmony_ci v1.defaultCloseAction(); 11123b3eb3cSopenharmony_ci }); 11223b3eb3cSopenharmony_ci }, Flex); 11323b3eb3cSopenharmony_ci (l ? l : this).observeComponentCreation2((q1, r1, s1 = m) => { 11423b3eb3cSopenharmony_ci Row.create(); 11523b3eb3cSopenharmony_ci Row.padding({ left: OPERATE_AREA_AVOID_WIDTH }); 11623b3eb3cSopenharmony_ci Row.direction(Direction.Rtl); 11723b3eb3cSopenharmony_ci Row.defaultFocus(true); 11823b3eb3cSopenharmony_ci Row.align(Alignment.End); 11923b3eb3cSopenharmony_ci Row.alignSelf(ItemAlign.End); 12023b3eb3cSopenharmony_ci Row.constraintSize({ 12123b3eb3cSopenharmony_ci maxWidth: '50%', 12223b3eb3cSopenharmony_ci minWidth: '40%' 12323b3eb3cSopenharmony_ci }); 12423b3eb3cSopenharmony_ci }, Row); 12523b3eb3cSopenharmony_ci (l ? l : this).observeComponentCreation2((m1, n1, o1 = m) => { 12623b3eb3cSopenharmony_ci SymbolGlyph.create({ "id": -1, "type": 40000, params: ['sys.symbol.xmark_circle_fill'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }); 12723b3eb3cSopenharmony_ci SymbolGlyph.fontColor([o1.options.iconStyle === IconStyle.DARK ? 12823b3eb3cSopenharmony_ci CLOSE_ICON_DARK_RESOURCE : CLOSE_ICON_LIGHT_RESOURCE]); 12923b3eb3cSopenharmony_ci SymbolGlyph.borderRadius(CLOSE_BUTTON_BORDER_RADIUS); 13023b3eb3cSopenharmony_ci SymbolGlyph.width(CLOSE_BUTTON_ICON_SIZE); 13123b3eb3cSopenharmony_ci SymbolGlyph.height(CLOSE_BUTTON_ICON_SIZE); 13223b3eb3cSopenharmony_ci SymbolGlyph.opacity(CLOSE_BUTTON_ICON_OPACITY); 13323b3eb3cSopenharmony_ci SymbolGlyph.draggable(false); 13423b3eb3cSopenharmony_ci SymbolGlyph.focusable(true); 13523b3eb3cSopenharmony_ci SymbolGlyph.responseRegion({ 13623b3eb3cSopenharmony_ci x: CLOSE_BUTTON_RESPONSE_REGION_OFFSET_X, 13723b3eb3cSopenharmony_ci y: CLOSE_BUTTON_RESPONSE_REGION_OFFSET_Y, 13823b3eb3cSopenharmony_ci width: CLOSE_BUTTON_HOT_SPOT_SIZE, 13923b3eb3cSopenharmony_ci height: CLOSE_BUTTON_HOT_SPOT_SIZE 14023b3eb3cSopenharmony_ci }); 14123b3eb3cSopenharmony_ci SymbolGlyph.margin(CLOSE_BUTTON_MARGIN); 14223b3eb3cSopenharmony_ci SymbolGlyph.alignSelf(ItemAlign.End); 14323b3eb3cSopenharmony_ci SymbolGlyph.offset({ 14423b3eb3cSopenharmony_ci x: CLOSE_BUTTON_OFFSET_X, 14523b3eb3cSopenharmony_ci y: CLOSE_BUTTON_OFFSET_Y 14623b3eb3cSopenharmony_ci }); 14723b3eb3cSopenharmony_ci SymbolGlyph.onClick(() => { 14823b3eb3cSopenharmony_ci if (o1.options.onDialogClose !== undefined) { 14923b3eb3cSopenharmony_ci o1.options.onDialogClose(); 15023b3eb3cSopenharmony_ci } 15123b3eb3cSopenharmony_ci o1.defaultCloseAction(); 15223b3eb3cSopenharmony_ci }); 15323b3eb3cSopenharmony_ci }, SymbolGlyph); 15423b3eb3cSopenharmony_ci (l ? l : this).observeComponentCreation2((j1, k1, l1 = m) => { 15523b3eb3cSopenharmony_ci Image.create(l1.options.foregroundImage); 15623b3eb3cSopenharmony_ci Image.height(STANDARD_MAX_COMPONENT_HEIGHT); 15723b3eb3cSopenharmony_ci Image.objectFit(ImageFit.Contain); 15823b3eb3cSopenharmony_ci Image.fitOriginalSize(true); 15923b3eb3cSopenharmony_ci Image.offset({ 16023b3eb3cSopenharmony_ci x: FOREGROUND_IMAGE_OFFSET_X, 16123b3eb3cSopenharmony_ci y: FOREGROUND_IMAGE_OFFSET_Y 16223b3eb3cSopenharmony_ci }); 16323b3eb3cSopenharmony_ci Image.alignSelf(ItemAlign.End); 16423b3eb3cSopenharmony_ci }, Image); 16523b3eb3cSopenharmony_ci Row.pop(); 16623b3eb3cSopenharmony_ci (l ? l : this).observeComponentCreation2((g1, h1, i1 = m) => { 16723b3eb3cSopenharmony_ci Flex.create({ 16823b3eb3cSopenharmony_ci direction: i1.options.titlePosition === TitlePosition.BOTTOM ? 16923b3eb3cSopenharmony_ci FlexDirection.ColumnReverse : FlexDirection.Column, 17023b3eb3cSopenharmony_ci justifyContent: FlexAlign.Center 17123b3eb3cSopenharmony_ci }); 17223b3eb3cSopenharmony_ci Flex.constraintSize({ 17323b3eb3cSopenharmony_ci maxWidth: '60%', 17423b3eb3cSopenharmony_ci minWidth: '50%' 17523b3eb3cSopenharmony_ci }); 17623b3eb3cSopenharmony_ci Flex.flexGrow(1); 17723b3eb3cSopenharmony_ci Flex.margin({ left: TEXT_LEFT_MARGIN_SIZE }); 17823b3eb3cSopenharmony_ci }, Flex); 17923b3eb3cSopenharmony_ci (l ? l : this).observeComponentCreation2((d1, e1, f1 = m) => { 18023b3eb3cSopenharmony_ci Text.create(f1.options.title); 18123b3eb3cSopenharmony_ci Text.alignSelf(ItemAlign.Start); 18223b3eb3cSopenharmony_ci Text.maxFontSize({ "id": -1, "type": 10002, params: ['sys.float.ohos_id_text_size_sub_title1'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }); 18323b3eb3cSopenharmony_ci Text.minFontSize(16); 18423b3eb3cSopenharmony_ci Text.fontColor(f1.options.titleColor !== undefined ? f1.options.titleColor : TITLE_DEFAULT_COLOR); 18523b3eb3cSopenharmony_ci Text.fontWeight(FontWeight.Bold); 18623b3eb3cSopenharmony_ci Text.margin(f1.options.titlePosition ? { top: TITLE_LINE_DISTANCE } : { bottom: TITLE_LINE_DISTANCE }); 18723b3eb3cSopenharmony_ci Text.maxLines(TITLE_MAX_LINE); 18823b3eb3cSopenharmony_ci Text.wordBreak(WordBreak.BREAK_WORD); 18923b3eb3cSopenharmony_ci Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 19023b3eb3cSopenharmony_ci }, Text); 19123b3eb3cSopenharmony_ci Text.pop(); 19223b3eb3cSopenharmony_ci (l ? l : this).observeComponentCreation2((a1, b1, c1 = m) => { 19323b3eb3cSopenharmony_ci Text.create(c1.options.subtitle); 19423b3eb3cSopenharmony_ci Text.alignSelf(ItemAlign.Start); 19523b3eb3cSopenharmony_ci Text.maxFontSize({ "id": -1, "type": 10002, params: ['sys.float.ohos_id_text_size_caption'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }); 19623b3eb3cSopenharmony_ci Text.minFontSize(9); 19723b3eb3cSopenharmony_ci Text.fontColor(c1.options.subtitleColor !== undefined ? c1.options.subtitleColor : SUBTITLE_DEFAULT_COLOR); 19823b3eb3cSopenharmony_ci Text.maxLines(SUBTITLE_MAX_LINE); 19923b3eb3cSopenharmony_ci Text.wordBreak(WordBreak.BREAK_WORD); 20023b3eb3cSopenharmony_ci Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 20123b3eb3cSopenharmony_ci }, Text); 20223b3eb3cSopenharmony_ci Text.pop(); 20323b3eb3cSopenharmony_ci Flex.pop(); 20423b3eb3cSopenharmony_ci Flex.pop(); 20523b3eb3cSopenharmony_ci (l ? l : this).observeComponentCreation2((w, x, y = m) => { 20623b3eb3cSopenharmony_ci Image.create(y.options.backgroundImage); 20723b3eb3cSopenharmony_ci Image.width('100%'); 20823b3eb3cSopenharmony_ci Image.height(STANDARD_MIN_COMPONENT_HEIGHT); 20923b3eb3cSopenharmony_ci Image.offset({ x: '-100%', y: 0 }); 21023b3eb3cSopenharmony_ci Image.borderRadius(DIALOG_BORDER_RADIUS); 21123b3eb3cSopenharmony_ci Image.zIndex(0); 21223b3eb3cSopenharmony_ci Image.alignSelf(ItemAlign.End); 21323b3eb3cSopenharmony_ci Image.onClick(() => { 21423b3eb3cSopenharmony_ci if (y.options.onDialogClose !== undefined) { 21523b3eb3cSopenharmony_ci y.options.onDialogClose(); 21623b3eb3cSopenharmony_ci } 21723b3eb3cSopenharmony_ci y.defaultCloseAction(); 21823b3eb3cSopenharmony_ci }); 21923b3eb3cSopenharmony_ci }, Image); 22023b3eb3cSopenharmony_ci Row.pop(); 22123b3eb3cSopenharmony_ci} 22223b3eb3cSopenharmony_ciexport class InterstitialDialogAction { 22323b3eb3cSopenharmony_ci constructor(i) { 22423b3eb3cSopenharmony_ci this.uiContext = i.uiContext; 22523b3eb3cSopenharmony_ci this.bottomOffsetType = i.bottomOffsetType; 22623b3eb3cSopenharmony_ci this.dialogParam = new DialogParams(i, () => { 22723b3eb3cSopenharmony_ci this.closeDialog(); 22823b3eb3cSopenharmony_ci }); 22923b3eb3cSopenharmony_ci this.contentNode = new ComponentContent(this.uiContext, wrapBuilder(dialogBuilder), this.dialogParam); 23023b3eb3cSopenharmony_ci } 23123b3eb3cSopenharmony_ci openDialog() { 23223b3eb3cSopenharmony_ci if (this.contentNode !== null) { 23323b3eb3cSopenharmony_ci this.uiContext.getPromptAction().openCustomDialog(this.contentNode, { 23423b3eb3cSopenharmony_ci isModal: false, 23523b3eb3cSopenharmony_ci autoCancel: false, 23623b3eb3cSopenharmony_ci offset: { 23723b3eb3cSopenharmony_ci dx: DIALOG_OFFSET_X, 23823b3eb3cSopenharmony_ci dy: this.bottomOffsetType === BottomOffset.OFFSET_FOR_BAR ? 23923b3eb3cSopenharmony_ci DIALOG_OFFSET_Y_FOR_BAR : DIALOG_OFFSET_Y_FOR_NONE 24023b3eb3cSopenharmony_ci }, 24123b3eb3cSopenharmony_ci alignment: DialogAlignment.Bottom, 24223b3eb3cSopenharmony_ci transition: TransitionEffect.asymmetric(TransitionEffect.OPACITY.animation({ duration: 150, curve: Curve.Sharp }) 24323b3eb3cSopenharmony_ci .combine(TransitionEffect.scale({ x: 0.85, y: 0.85, centerX: '50%', centerY: '85%' }) 24423b3eb3cSopenharmony_ci .animation({ curve: curves.interpolatingSpring(0, 1, 228, 24) })), TransitionEffect.OPACITY.animation({ duration: 250, curve: Curve.Sharp }) 24523b3eb3cSopenharmony_ci .combine(TransitionEffect.scale({ x: 0.85, y: 0.85, centerX: '50%', centerY: '85%' }) 24623b3eb3cSopenharmony_ci .animation({ duration: 250, curve: Curve.Friction }))) 24723b3eb3cSopenharmony_ci }) 24823b3eb3cSopenharmony_ci .catch((f) => { 24923b3eb3cSopenharmony_ci let g = f.message; 25023b3eb3cSopenharmony_ci let h = f.code; 25123b3eb3cSopenharmony_ci console.error(`${h}: ${g}`); 25223b3eb3cSopenharmony_ci }); 25323b3eb3cSopenharmony_ci } 25423b3eb3cSopenharmony_ci } 25523b3eb3cSopenharmony_ci closeDialog() { 25623b3eb3cSopenharmony_ci if (this.contentNode !== null) { 25723b3eb3cSopenharmony_ci this.uiContext.getPromptAction().closeCustomDialog(this.contentNode) 25823b3eb3cSopenharmony_ci .catch((b) => { 25923b3eb3cSopenharmony_ci let c = b.message; 26023b3eb3cSopenharmony_ci let d = b.code; 26123b3eb3cSopenharmony_ci console.error(`${d}: ${c}`); 26223b3eb3cSopenharmony_ci }); 26323b3eb3cSopenharmony_ci } 26423b3eb3cSopenharmony_ci } 26523b3eb3cSopenharmony_ci} 26623b3eb3cSopenharmony_ci 26723b3eb3cSopenharmony_ciexport default { InterstitialDialogAction, IconStyle, TitlePosition, BottomOffset };