1/* 2 * Copyright (c) 2023-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 */ 15const curves = requireNativeModule('ohos.curves'); 16 17const START_TIME = 250; 18const END_TIME = 200; 19const BORDER_RADIUS = 12; 20const ZINDEX_NUM = 9; 21 22export var MarginType; 23!function(e){ 24 e[e.DEFAULT_MARGIN=0] = "DEFAULT_MARGIN"; 25 e[e.FIT_MARGIN=1] = "FIT_MARGIN" 26}(MarginType || (MarginType = {})); 27 28export class ExceptionPrompt extends ViewPU { 29 constructor(e, o, t, i = -1, a = void 0) { 30 super(e, t, i); 31 "function" == typeof a && (this.paramsGenerator_ = a); 32 this.__options = new SynchedPropertyObjectOneWayPU(o.options, this, "options"); 33 this.touchBackgroundColor = { 34 id: -1, 35 type: 10001, 36 params: ["sys.color.ohos_id_color_sub_background_transparent"], 37 bundleName: "", 38 moduleName: "" 39 }; 40 this.onTipClick = () => { 41 }; 42 this.onActionTextClick = () => { 43 }; 44 this.setInitiallyProvidedValue(o) 45 } 46 47 setInitiallyProvidedValue(e) { 48 void 0 !== e.touchBackgroundColor && (this.touchBackgroundColor = e.touchBackgroundColor); 49 void 0 !== e.onTipClick && (this.onTipClick = e.onTipClick); 50 void 0 !== e.onActionTextClick && (this.onActionTextClick = e.onActionTextClick) 51 } 52 53 updateStateVars(e) { 54 this.__options.reset(e.options) 55 } 56 57 purgeVariableDependenciesOnElmtId(e) { 58 this.__options.purgeDependencyOnElmtId(e) 59 } 60 61 aboutToBeDeleted() { 62 this.__options.aboutToBeDeleted(); 63 SubscriberManager.Get().delete(this.id__()); 64 this.aboutToBeDeletedInternal() 65 } 66 67 get options() { 68 return this.__options.get() 69 } 70 71 set options(e) { 72 this.__options.set(e) 73 } 74 75 TextBuilder(e = null) { 76 this.observeComponentCreation2(((e, o) => { 77 Flex.create({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }); 78 Flex.padding({ 79 left: { 80 id: -1, 81 type: 10002, 82 params: ["sys.float.ohos_id_notification_margin_start"], 83 bundleName: "", 84 moduleName: "" 85 }, 86 right: { 87 id: -1, 88 type: 10002, 89 params: ["sys.float.ohos_id_text_paragraph_margin_s"], 90 bundleName: "", 91 moduleName: "" 92 }, 93 top: { 94 id: -1, 95 type: 10002, 96 params: ["sys.float.ohos_id_default_padding_start"], 97 bundleName: "", 98 moduleName: "" 99 }, 100 bottom: { 101 id: -1, 102 type: 10002, 103 params: ["sys.float.ohos_id_default_padding_end"], 104 bundleName: "", 105 moduleName: "" 106 } 107 }) 108 }), Flex); 109 this.observeComponentCreation2(((e, o) => { 110 Row.create(); 111 Row.padding({ 112 right: { 113 id: -1, 114 type: 10002, 115 params: ["sys.float.ohos_id_default_padding_end"], 116 bundleName: "", 117 moduleName: "" 118 } 119 }); 120 Row.width("100%"); 121 Row.onClick((() => { 122 this.onTipClick() 123 })) 124 }), Row); 125 this.observeComponentCreation2(((e, o) => { 126 var t; 127 Image.create(null !== (t = this.options.icon) && void 0 !== t ? t : { 128 id: -1, 129 type: 2e4, 130 params: ["sys.media.ohos_ic_public_fail"], 131 bundleName: "", 132 moduleName: "" 133 }); 134 Image.width("24vp"); 135 Image.height("24vp"); 136 Image.fillColor({ 137 id: -1, 138 type: 10001, 139 params: ["sys.color.ohos_id_color_warning"], 140 bundleName: "", 141 moduleName: "" 142 }) 143 }), Image); 144 this.observeComponentCreation2(((e, o) => { 145 Text.create(this.options.tip); 146 Text.fontSize({ 147 id: -1, 148 type: 10002, 149 params: ["sys.float.ohos_id_text_size_body1"], 150 bundleName: "", 151 moduleName: "" 152 }); 153 Text.fontColor({ 154 id: -1, 155 type: 10001, 156 params: ["sys.color.ohos_id_color_warning"], 157 bundleName: "", 158 moduleName: "" 159 }); 160 Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 161 Text.maxLines(2); 162 Text.lineHeight(24); 163 Text.margin({ 164 left: { 165 id: -1, 166 type: 10002, 167 params: ["sys.float.ohos_id_dialog_margin_end"], 168 bundleName: "", 169 moduleName: "" 170 }, 171 right: { 172 id: -1, 173 type: 10002, 174 params: ["sys.float.ohos_id_dialog_margin_end"], 175 bundleName: "", 176 moduleName: "" 177 } 178 }) 179 }), Text); 180 Text.pop(); 181 Row.pop(); 182 this.observeComponentCreation2(((e, o) => { 183 If.create(); 184 this.options.actionText ? this.ifElseBranchUpdateFunction(0, (() => { 185 this.observeComponentCreation2(((e, o) => { 186 Button.createWithChild({ stateEffect: !0, type: ButtonType.Normal }); 187 Button.backgroundColor(this.touchBackgroundColor); 188 Button.width(this.options.actionText ? 144 : 0); 189 Button.height(24); 190 Button.borderRadius({ 191 id: -1, 192 type: 10002, 193 params: ["sys.float.ohos_id_corner_radius_subtab"], 194 bundleName: "", 195 moduleName: "" 196 }); 197 Button.padding({ 198 right: { 199 id: -1, 200 type: 10002, 201 params: ["sys.float.ohos_id_elements_margin_vertical_l"], 202 bundleName: "", 203 moduleName: "" 204 }, 205 left: { 206 id: -1, 207 type: 10002, 208 params: ["sys.float.ohos_id_elements_margin_vertical_l"], 209 bundleName: "", 210 moduleName: "" 211 } 212 }); 213 Button.onTouch((e => { 214 if (e.type === TouchType.Down) { 215 this.touchBackgroundColor = { 216 id: -1, 217 type: 10001, 218 params: ["sys.color.ohos_id_color_click_effect"], 219 bundleName: "", 220 moduleName: "" 221 }; 222 this.onActionTextClick() 223 } else e.type === TouchType.Up && (this.touchBackgroundColor = { 224 id: -1, 225 type: 10001, 226 params: ["sys.color.ohos_id_color_sub_background_transparent"], 227 bundleName: "", 228 moduleName: "" 229 }) 230 })) 231 }), Button); 232 this.observeComponentCreation2(((e, o) => { 233 Row.create() 234 }), Row); 235 this.observeComponentCreation2(((e, o) => { 236 Text.create(this.options.actionText); 237 Text.fontSize({ 238 id: -1, 239 type: 10002, 240 params: ["sys.float.ohos_id_text_size_body2"], 241 bundleName: "", 242 moduleName: "" 243 }); 244 Text.fontColor({ 245 id: -1, 246 type: 10001, 247 params: ["sys.color.ohos_id_color_text_secondary"], 248 bundleName: "", 249 moduleName: "" 250 }); 251 Text.maxLines(1); 252 Text.padding(0); 253 Text.margin({ 254 right: { 255 id: -1, 256 type: 10002, 257 params: ["sys.float.ohos_id_text_paragraph_margin_s"], 258 bundleName: "", 259 moduleName: "" 260 } 261 }); 262 Text.textAlign(TextAlign.End) 263 }), Text); 264 Text.pop(); 265 this.observeComponentCreation2(((e, o) => { 266 Image.create({ 267 id: -1, 268 type: 2e4, 269 params: ["sys.media.ohos_ic_public_arrow_right"], 270 bundleName: "", 271 moduleName: "" 272 }); 273 Image.width("12vp"); 274 Image.height("24vp"); 275 Image.fillColor({ 276 id: -1, 277 type: 10001, 278 params: ["sys.color.ohos_id_color_tertiary"], 279 bundleName: "", 280 moduleName: "" 281 }) 282 }), Image); 283 Row.pop(); 284 Button.pop() 285 })) : this.ifElseBranchUpdateFunction(1, (() => { 286 })) 287 }), If); 288 If.pop(); 289 Flex.pop() 290 } 291 292 initialRender() { 293 this.observeComponentCreation2(((e, o) => { 294 Row.create(); 295 Row.width("100%"); 296 Row.position({ y: this.options.marginTop }); 297 Row.zIndex(9) 298 }), Row); 299 this.observeComponentCreation2(((e, o) => { 300 Column.create(); 301 Column.padding(this.options.marginType === MarginType.DEFAULT_MARGIN ? { 302 left: { 303 id: -1, 304 type: 10002, 305 params: ["sys.float.ohos_id_card_margin_start"], 306 bundleName: "", 307 moduleName: "" 308 }, 309 right: { 310 id: -1, 311 type: 10002, 312 params: ["sys.float.ohos_id_card_margin_end"], 313 bundleName: "", 314 moduleName: "" 315 } 316 } : { 317 left: { 318 id: -1, 319 type: 10002, 320 params: ["sys.float.ohos_id_max_padding_start"], 321 bundleName: "", 322 moduleName: "" 323 }, 324 right: { 325 id: -1, 326 type: 10002, 327 params: ["sys.float.ohos_id_max_padding_end"], 328 bundleName: "", 329 moduleName: "" 330 } 331 }); 332 Column.transition(TransitionEffect.OPACITY.animation({ 333 curve: curves.cubicBezierCurve(.33, 0, .67, 1), 334 duration: this.options.isShown ? 250 : 200 335 })); 336 Column.visibility(this.options.isShown ? Visibility.Visible : Visibility.None) 337 }), Column); 338 this.observeComponentCreation2(((e, o) => { 339 Column.create(); 340 Column.width("100%"); 341 Column.borderRadius(12); 342 Column.backgroundColor("#fdd9d9"); 343 Column.zIndex(9) 344 }), Column); 345 this.TextBuilder.bind(this)(); 346 Column.pop(); 347 Column.pop(); 348 Row.pop() 349 } 350 351 rerender() { 352 this.updateDirtyElements() 353 } 354} 355 356export default { 357 MarginType, 358 ExceptionPrompt 359}