diff --git a/CustomDialogPractice/entry/src/main/ets/entryability/EntryAbility.ets b/CustomDialogPractice/entry/src/main/ets/entryability/EntryAbility.ets index 217744d8eb6d893e1138cd660209ce4d0441ac4f..485b777f7ff57f0441f2208441ad7333da3ac127 100644 --- a/CustomDialogPractice/entry/src/main/ets/entryability/EntryAbility.ets +++ b/CustomDialogPractice/entry/src/main/ets/entryability/EntryAbility.ets @@ -36,6 +36,8 @@ export default class EntryAbility extends UIAbility { return; } hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + let uiContext: UIContext | undefined = windowStage.getMainWindowSync().getUIContext() + AppStorage.setOrCreate('uiContext', uiContext); }); } diff --git a/CustomDialogPractice/entry/src/main/ets/pages/CustomDialogDisplayAndExitAnimations.ets b/CustomDialogPractice/entry/src/main/ets/pages/CustomDialogDisplayAndExitAnimations.ets index 8cd016df21300a395060b3e6ea270d8b33d673db..2bb49584a2a47d3152b71c5985bc6b6800348d2a 100644 --- a/CustomDialogPractice/entry/src/main/ets/pages/CustomDialogDisplayAndExitAnimations.ets +++ b/CustomDialogPractice/entry/src/main/ets/pages/CustomDialogDisplayAndExitAnimations.ets @@ -43,7 +43,7 @@ export struct CustomDialogDisplayAndExitAnimations { .fontColor('#0A59F7') .backgroundColor(Color.White) .onClick(() => { - this.promptAction.closeCustomDialog(this.customDialogComponentId); + this.getUIContext().getPromptAction().closeCustomDialog(this.customDialogComponentId); }) .width('100%') .margin({ @@ -73,7 +73,7 @@ export struct CustomDialogDisplayAndExitAnimations { .margin({ bottom: 16 }) .backgroundColor('#0A59F7') .onClick(() => { - this.promptAction.openCustomDialog({ + this.getUIContext().getPromptAction().openCustomDialog({ builder: () => { this.customDialogComponent(); }, diff --git a/CustomDialogPractice/entry/src/main/ets/pages/InterceptReturn01.ets b/CustomDialogPractice/entry/src/main/ets/pages/InterceptReturn01.ets index 20e4351c2de25221dd99313d9718d948347a424b..581491e85345ef6088836ae4c1a043b6a0d635f9 100644 --- a/CustomDialogPractice/entry/src/main/ets/pages/InterceptReturn01.ets +++ b/CustomDialogPractice/entry/src/main/ets/pages/InterceptReturn01.ets @@ -44,7 +44,7 @@ export struct InterceptReturn01 { .fontColor('#0A59F7') .backgroundColor(Color.White) .onClick(() => { - this.context.getPromptAction().closeCustomDialog(this.customDialogComponentId); + this.getUIContext().getPromptAction().closeCustomDialog(this.customDialogComponentId); }) .width('100%') .margin({ @@ -77,7 +77,7 @@ export struct InterceptReturn01 { .margin({ bottom: 16 }) .backgroundColor('#0A59F7') .onClick(() => { - this.promptAction.openCustomDialog({ + this.getUIContext().getPromptAction().openCustomDialog({ builder: () => { this.customDialogComponent() }, diff --git a/CustomDialogPractice/entry/src/main/ets/uitls/PromptActionClass.ets b/CustomDialogPractice/entry/src/main/ets/uitls/PromptActionClass.ets index 9bcc58ab8ec7e8b5398be23767e77091bd25d092..f6cc8651e74d257863c20a80425471aa9e7f7053 100644 --- a/CustomDialogPractice/entry/src/main/ets/uitls/PromptActionClass.ets +++ b/CustomDialogPractice/entry/src/main/ets/uitls/PromptActionClass.ets @@ -18,7 +18,7 @@ import { BusinessError } from '@kit.BasicServicesKit'; import { ComponentContent, promptAction } from '@kit.ArkUI'; import { UIContext } from '@ohos.arkui.UIContext'; import { hilog } from '@kit.PerformanceAnalysisKit'; - +const uiContext: UIContext | undefined = AppStorage.get('uiContext'); export class PromptActionClass { static ctx: UIContext; static contentNode: ComponentContent; @@ -38,7 +38,7 @@ export class PromptActionClass { static openDialog() { if (PromptActionClass.contentNode !== null) { - PromptActionClass.ctx.getPromptAction() + uiContext!.getPromptAction() .openCustomDialog(PromptActionClass.contentNode, PromptActionClass.options) .then(() => { hilog.info(0x0000, 'testTag', 'OpenCustomDialog complete.'); @@ -53,7 +53,7 @@ export class PromptActionClass { static closeDialog() { if (PromptActionClass.contentNode !== null) { - PromptActionClass.ctx.getPromptAction() + uiContext!.getPromptAction() .closeCustomDialog(PromptActionClass.contentNode) .then(() => { hilog.info(0x0000, 'testTag', 'CloseCustomDialog complete.');