• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #include "frameworks/bridge/declarative_frontend/jsview/dialog/js_alert_dialog.h"
16 
17 #include <sstream>
18 #include <string>
19 #include <vector>
20 
21 #include "base/log/ace_scoring_log.h"
22 #include "bridge/declarative_frontend/jsview/models/alert_dialog_model_impl.h"
23 #include "core/common/container.h"
24 #include "core/components_ng/base/view_stack_processor.h"
25 #include "core/components_ng/pattern/dialog/alert_dialog_model_ng.h"
26 #include "frameworks/bridge/common/utils/engine_helper.h"
27 #include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h"
28 
29 namespace OHOS::Ace {
30 std::unique_ptr<AlertDialogModel> AlertDialogModel::instance_ = nullptr;
31 std::mutex AlertDialogModel::mutex_;
GetInstance()32 AlertDialogModel* AlertDialogModel::GetInstance()
33 {
34     if (!instance_) {
35         std::lock_guard<std::mutex> lock(mutex_);
36         if (!instance_) {
37 #ifdef NG_BUILD
38             instance_.reset(new NG::AlertDialogModelNG());
39 #else
40             if (Container::IsCurrentUseNewPipeline()) {
41                 instance_.reset(new NG::AlertDialogModelNG());
42             } else {
43                 instance_.reset(new Framework::AlertDialogModelImpl());
44             }
45 #endif
46         }
47     }
48     return instance_.get();
49 }
50 
51 } // namespace OHOS::Ace
52 namespace OHOS::Ace::Framework {
53 namespace {
54 const std::vector<DialogAlignment> DIALOG_ALIGNMENT = { DialogAlignment::TOP, DialogAlignment::CENTER,
55     DialogAlignment::BOTTOM, DialogAlignment::DEFAULT, DialogAlignment::TOP_START, DialogAlignment::TOP_END,
56     DialogAlignment::CENTER_START, DialogAlignment::CENTER_END, DialogAlignment::BOTTOM_START,
57     DialogAlignment::BOTTOM_END };
58 const std::vector<DialogButtonDirection> DIALOG_BUTTONS_DIRECTION = { DialogButtonDirection::AUTO,
59     DialogButtonDirection::HORIZONTAL, DialogButtonDirection::VERTICAL };
60 constexpr int32_t ALERT_DIALOG_VALID_PRIMARY_BUTTON_NUM = 1;
61 const std::vector<LevelMode> DIALOG_LEVEL_MODE = { LevelMode::OVERLAY, LevelMode::EMBEDDED };
62 const std::vector<ImmersiveMode> DIALOG_IMMERSIVE_MODE = { ImmersiveMode::DEFAULT, ImmersiveMode::EXTEND};
63 } // namespace
64 
SetParseStyle(ButtonInfo & buttonInfo,const int32_t styleValue)65 void SetParseStyle(ButtonInfo& buttonInfo, const int32_t styleValue)
66 {
67     if (styleValue >= static_cast<int32_t>(DialogButtonStyle::DEFAULT) &&
68         styleValue <= static_cast<int32_t>(DialogButtonStyle::HIGHTLIGHT)) {
69         buttonInfo.dlgButtonStyle = static_cast<DialogButtonStyle>(styleValue);
70     }
71 }
72 
ParseButtonObj(const JsiExecutionContext & execContext,DialogProperties & properties,JSRef<JSVal> jsVal,const std::string & property,bool isPrimaryButtonValid)73 void ParseButtonObj(const JsiExecutionContext& execContext, DialogProperties& properties, JSRef<JSVal> jsVal,
74     const std::string& property, bool isPrimaryButtonValid)
75 {
76     if (!jsVal->IsObject()) {
77         return;
78     }
79     auto objInner = JSRef<JSObject>::Cast(jsVal);
80     std::string buttonValue;
81     ButtonInfo buttonInfo;
82     if (JSAlertDialog::ParseJsString(objInner->GetProperty("value"), buttonValue)) {
83         buttonInfo.text = buttonValue;
84     }
85 
86     // Parse enabled
87     auto enabledValue = objInner->GetProperty("enabled");
88     if (enabledValue->IsBoolean()) {
89         buttonInfo.enabled = enabledValue->ToBoolean();
90     }
91 
92     // Parse defaultFocus
93     auto defaultFocusValue = objInner->GetProperty("defaultFocus");
94     if (defaultFocusValue->IsBoolean()) {
95         buttonInfo.defaultFocus = defaultFocusValue->ToBoolean();
96     }
97 
98     // Parse style
99     auto style = objInner->GetProperty("style");
100     if (style->IsNumber()) {
101         SetParseStyle(buttonInfo, style->ToNumber<int32_t>());
102     }
103 
104     Color textColor;
105     if (JSAlertDialog::ParseJsColor(objInner->GetProperty("fontColor"), textColor)) {
106         buttonInfo.textColor = textColor.ColorToString();
107     }
108 
109     Color backgroundColor;
110     if (JSAlertDialog::ParseJsColor(objInner->GetProperty("backgroundColor"), backgroundColor)) {
111         buttonInfo.isBgColorSetted = true;
112         buttonInfo.bgColor = backgroundColor;
113     }
114 
115     auto actionValue = objInner->GetProperty("action");
116     if (actionValue->IsFunction()) {
117         auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
118         auto actionFunc = AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(actionValue));
119         auto eventFunc = [execCtx = execContext, func = std::move(actionFunc), property, node = frameNode]() {
120             JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
121             ACE_SCORING_EVENT("AlertDialog.[" + property + "].onAction");
122             auto pipelineContext = PipelineContext::GetCurrentContextSafely();
123             CHECK_NULL_VOID(pipelineContext);
124             pipelineContext->UpdateCurrentActiveNode(node);
125             func->Execute();
126         };
127         AlertDialogModel::GetInstance()->SetParseButtonObj(eventFunc, buttonInfo, properties, property);
128     }
129 
130     if (!buttonInfo.defaultFocus && isPrimaryButtonValid) {
131         if (strcmp(property.c_str(), "confirm") == 0 ||
132         strcmp(property.c_str(), "primaryButton") == 0) {
133             buttonInfo.isPrimary = true;
134         } else {
135             auto primaryButton = objInner->GetProperty("primary");
136             if (primaryButton->IsBoolean()) {
137                 buttonInfo.isPrimary = primaryButton->ToBoolean();
138             }
139         }
140     }
141 
142     if (buttonInfo.IsValid()) {
143         properties.buttons.emplace_back(buttonInfo);
144     }
145 }
146 
ParseButtonArray(const JsiExecutionContext & execContext,DialogProperties & properties,JSRef<JSObject> obj,const std::string & property)147 void ParseButtonArray(const JsiExecutionContext& execContext, DialogProperties& properties, JSRef<JSObject> obj,
148     const std::string& property)
149 {
150     auto jsVal = obj->GetProperty(property.c_str());
151     if (!jsVal->IsArray()) {
152         return;
153     }
154     JSRef<JSArray> array = JSRef<JSArray>::Cast(jsVal);
155     size_t length = array->Length();
156     if (length <= 0) {
157         return;
158     }
159     int32_t primaryButtonNum = 0;
160     bool isPrimaryButtonValid = true;
161     for (size_t i = 0; i < length; i++) {
162         JSRef<JSVal> buttonItem = array->GetValueAt(i);
163         if (!buttonItem->IsObject()) {
164             break;
165         }
166         auto objInner = JSRef<JSObject>::Cast(buttonItem);
167         auto primaryButton = objInner->GetProperty("primary");
168         if (primaryButton->IsBoolean()) {
169             primaryButtonNum += (primaryButton->ToBoolean() ? ALERT_DIALOG_VALID_PRIMARY_BUTTON_NUM : 0);
170         }
171         if (primaryButtonNum > ALERT_DIALOG_VALID_PRIMARY_BUTTON_NUM) {
172             isPrimaryButtonValid = false;
173             break;
174         }
175     }
176     for (size_t i = 0; i < length; i++) {
177         JSRef<JSVal> buttonItem = array->GetValueAt(i);
178         if (!buttonItem->IsObject()) {
179             break;
180         }
181         ParseButtonObj(execContext, properties, buttonItem, property + std::to_string(i), isPrimaryButtonValid);
182     }
183 }
184 
ParseButtons(const JsiExecutionContext & execContext,DialogProperties & properties,JSRef<JSObject> obj)185 void ParseButtons(const JsiExecutionContext& execContext, DialogProperties& properties, JSRef<JSObject> obj)
186 {
187     properties.buttons.clear();
188     if (obj->GetProperty("confirm")->IsObject()) {
189         // Parse confirm.
190         auto objInner = obj->GetProperty("confirm");
191         ParseButtonObj(execContext, properties, objInner, "confirm", true);
192     } else if (obj->GetProperty("buttons")->IsArray()) {
193         // Parse buttons array.
194         ParseButtonArray(execContext, properties, obj, "buttons");
195     } else {
196         // Parse primaryButton and secondaryButton.
197         auto objInner = obj->GetProperty("primaryButton");
198         ParseButtonObj(execContext, properties, objInner, "primaryButton", true);
199         objInner = obj->GetProperty("secondaryButton");
200         ParseButtonObj(execContext, properties, objInner, "secondaryButton", true);
201     }
202 
203     // Parse buttons direction.
204     auto directionValue = obj->GetProperty("buttonDirection");
205     if (directionValue->IsNumber()) {
206         auto buttonDirection = directionValue->ToNumber<int32_t>();
207         if (buttonDirection >= 0 && buttonDirection <= static_cast<int32_t>(DIALOG_BUTTONS_DIRECTION.size())) {
208             properties.buttonDirection = DIALOG_BUTTONS_DIRECTION[buttonDirection];
209         }
210     }
211 }
212 
ParseDialogTitleAndMessage(DialogProperties & properties,JSRef<JSObject> obj)213 void ParseDialogTitleAndMessage(DialogProperties& properties, JSRef<JSObject> obj)
214 {
215     // Parse title.
216     auto titleValue = obj->GetProperty("title");
217     std::string title;
218     if (JSAlertDialog::ParseJsString(titleValue, title)) {
219         properties.title = title;
220     }
221 
222     // Parse subtitle.
223     auto subtitleValue = obj->GetProperty("subtitle");
224     std::string subtitle;
225     if (JSAlertDialog::ParseJsString(subtitleValue, subtitle)) {
226         properties.subtitle = subtitle;
227     }
228 
229     // Parses message.
230     auto messageValue = obj->GetProperty("message");
231     std::string message;
232     if (JSAlertDialog::ParseJsString(messageValue, message)) {
233         properties.content = message;
234     }
235 }
236 
ParseTextStyle(DialogProperties & properties,JSRef<JSObject> obj)237 void ParseTextStyle(DialogProperties& properties, JSRef<JSObject> obj)
238 {
239     auto textStyleObj = obj->GetProperty("textStyle");
240     if (textStyleObj->IsNull() || !textStyleObj->IsObject()) {
241         return;
242     }
243     auto textStyle = JSRef<JSObject>::Cast(textStyleObj);
244     auto args = textStyle->GetProperty("wordBreak");
245     int32_t index = 1;
246     if (args->IsNumber()) {
247         index = args->ToNumber<int32_t>();
248     }
249     if (index < 0 || index >= static_cast<int32_t>(WORD_BREAK_TYPES.size())) {
250         index = 1;
251     }
252     properties.wordBreak = WORD_BREAK_TYPES[index];
253 }
254 
ParseAlertShadow(DialogProperties & properties,JSRef<JSObject> obj)255 void ParseAlertShadow(DialogProperties& properties, JSRef<JSObject> obj)
256 {
257     // Parse shadow.
258     auto shadowValue = obj->GetProperty("shadow");
259     Shadow shadow;
260     if ((shadowValue->IsObject() || shadowValue->IsNumber()) && JSAlertDialog::ParseShadowProps(shadowValue, shadow)) {
261         properties.shadow = shadow;
262     }
263 }
264 
ParseAlertBorderWidthAndColor(DialogProperties & properties,JSRef<JSObject> obj)265 void ParseAlertBorderWidthAndColor(DialogProperties& properties, JSRef<JSObject> obj)
266 {
267     auto borderWidthValue = obj->GetProperty("borderWidth");
268     NG::BorderWidthProperty borderWidth;
269     if (JSAlertDialog::ParseBorderWidthProps(borderWidthValue, borderWidth)) {
270         properties.borderWidth = borderWidth;
271         auto colorValue = obj->GetProperty("borderColor");
272         NG::BorderColorProperty borderColor;
273         if (JSAlertDialog::ParseBorderColorProps(colorValue, borderColor)) {
274             properties.borderColor = borderColor;
275         } else {
276             borderColor.SetColor(Color::BLACK);
277             properties.borderColor = borderColor;
278         }
279     }
280 }
281 
UpdateAlertAlignment(DialogAlignment & alignment)282 void UpdateAlertAlignment(DialogAlignment& alignment)
283 {
284     bool isRtl = AceApplicationInfo::GetInstance().IsRightToLeft();
285     if (alignment == DialogAlignment::TOP_START) {
286         if (isRtl) {
287             alignment = DialogAlignment::TOP_END;
288         }
289     } else if (alignment == DialogAlignment::TOP_END) {
290         if (isRtl) {
291             alignment = DialogAlignment::TOP_START;
292         }
293     } else if (alignment == DialogAlignment::CENTER_START) {
294         if (isRtl) {
295             alignment = DialogAlignment::CENTER_END;
296         }
297     } else if (alignment == DialogAlignment::CENTER_END) {
298         if (isRtl) {
299             alignment = DialogAlignment::CENTER_START;
300         }
301     } else if (alignment == DialogAlignment::BOTTOM_START) {
302         if (isRtl) {
303             alignment = DialogAlignment::BOTTOM_END;
304         }
305     } else if (alignment == DialogAlignment::BOTTOM_END) {
306         if (isRtl) {
307             alignment = DialogAlignment::BOTTOM_START;
308         }
309     }
310 }
311 
ParseAlertRadius(DialogProperties & properties,JSRef<JSObject> obj)312 void ParseAlertRadius(DialogProperties& properties, JSRef<JSObject> obj)
313 {
314     auto cornerRadiusValue = obj->GetProperty("cornerRadius");
315     NG::BorderRadiusProperty radius;
316     if (JSAlertDialog::ParseBorderRadius(cornerRadiusValue, radius)) {
317         properties.borderRadius = radius;
318     }
319 }
320 
ParseAlertAlignment(DialogProperties & properties,JSRef<JSObject> obj)321 void ParseAlertAlignment(DialogProperties& properties, JSRef<JSObject> obj)
322 {
323     // Parse alignment
324     auto alignmentValue = obj->GetProperty("alignment");
325     if (alignmentValue->IsNumber()) {
326         auto alignment = alignmentValue->ToNumber<int32_t>();
327         if (alignment >= 0 && alignment <= static_cast<int32_t>(DIALOG_ALIGNMENT.size())) {
328             properties.alignment = DIALOG_ALIGNMENT[alignment];
329             UpdateAlertAlignment(properties.alignment);
330         }
331     }
332 }
333 
ParseAlertOffset(DialogProperties & properties,JSRef<JSObject> obj)334 void ParseAlertOffset(DialogProperties& properties, JSRef<JSObject> obj)
335 {
336     // Parse offset
337     auto offsetValue = obj->GetProperty("offset");
338     if (offsetValue->IsObject()) {
339         auto offsetObj = JSRef<JSObject>::Cast(offsetValue);
340         CalcDimension dx;
341         auto dxValue = offsetObj->GetProperty("dx");
342         JSAlertDialog::ParseJsDimensionVp(dxValue, dx);
343         CalcDimension dy;
344         auto dyValue = offsetObj->GetProperty("dy");
345         JSAlertDialog::ParseJsDimensionVp(dyValue, dy);
346         properties.offset = DimensionOffset(dx, dy);
347         bool isRtl = AceApplicationInfo::GetInstance().IsRightToLeft();
348         Dimension offsetX = isRtl ? properties.offset.GetX() * (-1) : properties.offset.GetX();
349         properties.offset.SetX(offsetX);
350     }
351 }
352 
ParseAlertMaskRect(DialogProperties & properties,JSRef<JSObject> obj)353 void ParseAlertMaskRect(DialogProperties& properties, JSRef<JSObject> obj)
354 {
355     // Parse maskRect.
356     auto maskRectValue = obj->GetProperty("maskRect");
357     DimensionRect maskRect;
358     if (JSViewAbstract::ParseJsDimensionRect(maskRectValue, maskRect)) {
359         properties.maskRect = maskRect;
360         bool isRtl = AceApplicationInfo::GetInstance().IsRightToLeft();
361         auto offset = maskRect.GetOffset();
362         Dimension offsetX = isRtl ? offset.GetX() * (-1) : offset.GetX();
363         offset.SetX(offsetX);
364         properties.maskRect->SetOffset(offset);
365     }
366 }
367 
ParseAlertDialogLevelMode(DialogProperties & properties,JSRef<JSObject> obj)368 void ParseAlertDialogLevelMode(DialogProperties& properties, JSRef<JSObject> obj)
369 {
370     auto levelMode = obj->GetProperty("levelMode");
371     auto levelUniqueId = obj->GetProperty("levelUniqueId");
372     auto immersiveMode = obj->GetProperty("immersiveMode");
373     bool showInMainWindow = true;
374     if (obj->GetProperty("showInSubWindow")->IsBoolean() && obj->GetProperty("showInSubWindow")->ToBoolean()) {
375         showInMainWindow = false;
376     }
377     if (levelMode->IsNumber() && showInMainWindow) {
378         auto mode = levelMode->ToNumber<int32_t>();
379         if (mode >= 0 && mode < static_cast<int32_t>(DIALOG_LEVEL_MODE.size())) {
380             properties.dialogLevelMode = DIALOG_LEVEL_MODE[mode];
381         }
382     }
383     if (levelUniqueId->IsNumber()) {
384         properties.dialogLevelUniqueId = levelUniqueId->ToNumber<int32_t>();
385     }
386     if (immersiveMode->IsNumber()) {
387         auto immersiveVal = immersiveMode->ToNumber<int32_t>();
388         if (immersiveVal >= 0 && immersiveVal < static_cast<int32_t>(DIALOG_IMMERSIVE_MODE.size())) {
389             properties.dialogImmersiveMode = DIALOG_IMMERSIVE_MODE[immersiveVal];
390         }
391     }
392 }
393 
Show(const JSCallbackInfo & args)394 void JSAlertDialog::Show(const JSCallbackInfo& args)
395 {
396     auto scopedDelegate = EngineHelper::GetCurrentDelegateSafely();
397     if (!scopedDelegate) {
398         // this case usually means there is no foreground container, need to figure out the reason.
399         LOGE("scopedDelegate is null, please check");
400         return;
401     }
402 
403     DialogProperties properties { .type = DialogType::ALERT_DIALOG };
404     if (args[0]->IsObject()) {
405         auto obj = JSRef<JSObject>::Cast(args[0]);
406         auto dialogNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
407         auto execContext = args.GetExecutionContext();
408 
409         ParseDialogTitleAndMessage(properties, obj);
410         ParseButtons(execContext, properties, obj);
411         ParseTextStyle(properties, obj);
412         ParseAlertShadow(properties, obj);
413         ParseAlertBorderWidthAndColor(properties, obj);
414         ParseAlertRadius(properties, obj);
415         ParseAlertAlignment(properties, obj);
416         ParseAlertOffset(properties, obj);
417         ParseAlertMaskRect(properties, obj);
418         ParseAlertDialogLevelMode(properties, obj);
419 
420         auto onLanguageChange = [execContext, obj, parseContent = ParseDialogTitleAndMessage,
421                                     parseButton = ParseButtons, parseShadow = ParseAlertShadow,
422                                     parseBorderProps = ParseAlertBorderWidthAndColor,
423                                     parseRadius = ParseAlertRadius, parseAlignment = ParseAlertAlignment,
424                                     parseOffset = ParseAlertOffset, parseMaskRect = ParseAlertMaskRect,
425                                     parseDialogLevelMode = ParseAlertDialogLevelMode,
426                                     node = dialogNode](DialogProperties& dialogProps) {
427             JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execContext);
428             ACE_SCORING_EVENT("AlertDialog.property.onLanguageChange");
429             auto pipelineContext = PipelineContext::GetCurrentContextSafely();
430             CHECK_NULL_VOID(pipelineContext);
431             pipelineContext->UpdateCurrentActiveNode(node);
432             parseContent(dialogProps, obj);
433             parseButton(execContext, dialogProps, obj);
434             parseShadow(dialogProps, obj);
435             parseBorderProps(dialogProps, obj);
436             parseRadius(dialogProps, obj);
437             parseAlignment(dialogProps, obj);
438             parseOffset(dialogProps, obj);
439             parseMaskRect(dialogProps, obj);
440             parseDialogLevelMode(dialogProps, obj);
441         };
442         properties.onLanguageChange = std::move(onLanguageChange);
443 
444         // Parses gridCount.
445         auto gridCountValue = obj->GetProperty("gridCount");
446         if (gridCountValue->IsNumber()) {
447             properties.gridCount = gridCountValue->ToNumber<int32_t>();
448         }
449 
450         // Parse auto autoCancel.
451         auto autoCancelValue = obj->GetProperty("autoCancel");
452         if (autoCancelValue->IsBoolean()) {
453             properties.autoCancel = autoCancelValue->ToBoolean();
454         }
455 
456         // Parse cancel.
457         auto cancelValue = obj->GetProperty("cancel");
458         if (cancelValue->IsFunction()) {
459             auto cancelFunc = AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(cancelValue));
460             auto eventFunc = [execContext, func = std::move(cancelFunc), node = dialogNode]() {
461                 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execContext);
462                 ACE_SCORING_EVENT("AlertDialog.property.cancel");
463                 auto pipelineContext = PipelineContext::GetCurrentContextSafely();
464                 CHECK_NULL_VOID(pipelineContext);
465                 pipelineContext->UpdateCurrentActiveNode(node);
466                 func->Execute();
467             };
468             AlertDialogModel::GetInstance()->SetOnCancel(eventFunc, properties);
469         }
470 
471         std::function<void(const int32_t& info)> onWillDismissFunc = nullptr;
472         ParseDialogCallback(obj, onWillDismissFunc);
473         AlertDialogModel::GetInstance()->SetOnWillDismiss(std::move(onWillDismissFunc), properties);
474 
475         // Parse showInSubWindowValue.
476         auto showInSubWindowValue = obj->GetProperty("showInSubWindow");
477         if (showInSubWindowValue->IsBoolean()) {
478 #if defined(PREVIEW)
479             LOGW("[Engine Log] Unable to use the SubWindow in the Previewer. Perform this operation on the "
480                  "emulator or a real device instead.");
481 #else
482             properties.isShowInSubWindow = showInSubWindowValue->ToBoolean();
483 #endif
484         }
485 
486         // Parse isModal.
487         auto isModalValue = obj->GetProperty("isModal");
488         if (isModalValue->IsBoolean()) {
489             LOGI("Parse isModalValue");
490             properties.isModal = isModalValue->ToBoolean();
491         }
492 
493         auto backgroundColorValue = obj->GetProperty("backgroundColor");
494         Color backgroundColor;
495         if (JSViewAbstract::ParseJsColor(backgroundColorValue, backgroundColor)) {
496             properties.backgroundColor = backgroundColor;
497         }
498 
499         auto backgroundBlurStyle = obj->GetProperty("backgroundBlurStyle");
500         if (backgroundBlurStyle->IsNumber()) {
501             auto blurStyle = backgroundBlurStyle->ToNumber<int32_t>();
502             if (blurStyle >= static_cast<int>(BlurStyle::NO_MATERIAL) &&
503                 blurStyle <= static_cast<int>(BlurStyle::COMPONENT_ULTRA_THICK)) {
504                 properties.backgroundBlurStyle = blurStyle;
505             }
506         }
507         // Parse transition.
508         properties.transitionEffect = ParseJsTransitionEffect(args);
509         JSViewAbstract::SetDialogProperties(obj, properties);
510         JSViewAbstract::SetDialogHoverModeProperties(obj, properties);
511         AlertDialogModel::GetInstance()->SetShowDialog(properties);
512     }
513 }
514 
JSBind(BindingTarget globalObj)515 void JSAlertDialog::JSBind(BindingTarget globalObj)
516 {
517     JSClass<JSAlertDialog>::Declare("AlertDialog");
518     JSClass<JSAlertDialog>::StaticMethod("show", &JSAlertDialog::Show);
519 
520     JSClass<JSAlertDialog>::InheritAndBind<JSViewAbstract>(globalObj);
521 }
522 } // namespace OHOS::Ace::Framework
523