HarmonyOS 全局自定义弹窗demo

HarmonyOS 全局自定义弹窗demo。

HarmonyOS
2024-10-12 09:28:09
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zbw_apple

参考demo如下:

export class Params {  
  text: string = ""  
  callback: (volumeType: string, value: number) => void = () => {  
  };  
  constructor(text: string, callback: (volumeType: string, value: number) => void) {  
    this.text = text;  
    this.callback = callback;  
  }  
}  
@Builder  
export function buildText(params: Params) {  
  Column() {  
    Text(params.text)  
      .fontSize(50)  
      .fontWeight(FontWeight.Bold)  
      .margin({bottom: 36})  
  }.backgroundColor('#FFF0F0F0')  
}  
@Entry  
@Component  
struct CustomDialog_Globally {  
  @State message: string = "hello"  
  
  build() {  
    Row() {  
      Column() {  
        Button("click me")  
          .onClick(() => {  
            let uiContext = this.getUIContext();  
            let promptAction = uiContext.getPromptAction();  
          })  
      }  
      .width('100%')  
      .height('100%')  
    }  
    .height('100%')  
  }  
}
import { ComponentContent } from '@kit.ArkUI';  
import { BusinessError } from '@kit.BasicServicesKit';  
import { buildText, Params } from './CustomDialog_Globally';  
@Entry  
@Component  
struct CustomDialog_Globally_other01 {  
  @State message: string = 'Hello World';  
  build() {  
    Column() {  
      Text(this.message)  
        .id('HelloWorld')  
        .fontSize(50)  
        .fontWeight(FontWeight.Bold)  
        .onClick(() => {  
          let uiContext = this.getUIContext();  
          let promptAction = uiContext.getPromptAction();  
          let callback = (volumeType: string, value: number) => {  
            //处理返回值的逻辑  
            console.log(`OpenCustomDialog args error code is ${volumeType}, message is ${value}`);  
            this.message = volumeType;  
          }  
          let contentNode = new ComponentContent(uiContext, wrapBuilder(buildText), new Params(this.message, callback));  
          try {  
            promptAction.openCustomDialog(contentNode);  
          } catch (error) {  
            let message = (error as BusinessError).message;  
            let code = (error as BusinessError).code;  
            console.error(`OpenCustomDialog args error code is ${code}, message is ${message}`);  
          };  
        })  
    }  
    .height('100%')  
    .width('100%')  
  }  
}
import { BusinessError } from '@ohos.base';  
import { ComponentContent } from "@ohos.arkui.node";  
class Params {  
  text: string = ""  
  constructor(text: string) {  
    this.text = text;  
  }  
}  
@Builder  
function buildText(params: Params) {  
  Column() {  
    Text(params.text)  
      .fontSize(50)  
      .fontWeight(FontWeight.Bold)  
      .margin({bottom: 36})  
    TextInput()  
  }.backgroundColor('#FFF0F0F0')  
  .margin({  
    bottom: -16  
  })  
}  
@Entry  
@Component  
struct CustomDialog_Xuzhip {  
  @State message: string = "hello"  
  build() {  
    Row() {  
      Column() {  
        Button("click me")  
          .onClick(() => {  
            let uiContext = this.getUIContext();  
            let promptAction = uiContext.getPromptAction();  
            let contentNode = new ComponentContent(uiContext, wrapBuilder(buildText), new Params(this.message));  
            try {  
              promptAction.openCustomDialog(contentNode);  
            } catch (error) {  
              let message = (error as BusinessError).message;  
              let code = (error as BusinessError).code;  
              console.error(`OpenCustomDialog args error code is ${code}, message is ${message}`);  
            };  
          })  
      }  
      .width('100%')  
      .height('100%')  
    }  
    .height('100%')  
  }  
}
分享
微博
QQ
微信
回复
2024-10-12 17:10:01
相关问题
如何封装全局性的自定义弹窗
234浏览 • 1回复 待解决
自定义弹窗自定义转场动画
1038浏览 • 1回复 待解决
HarmonyOS 自定义相机demo
173浏览 • 1回复 待解决
HarmonyOS 自定义弹窗选择
274浏览 • 1回复 待解决
HarmonyOS 自定义相机演示demo
127浏览 • 1回复 待解决
如何在全局实现一个自定义dialog弹窗
2720浏览 • 1回复 待解决
HarmonyOS 自定义弹窗的问题
539浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog问题
491浏览 • 1回复 待解决
hvigor自定义扩展demo
927浏览 • 1回复 待解决
HarmonyOS 自定义弹窗 (CustomDialog)问题
245浏览 • 1回复 待解决
HarmonyOS 自定义弹窗遮罩未全屏
490浏览 • 1回复 待解决
使用自定义弹窗实现分享弹窗
456浏览 • 1回复 待解决
如何在自定义弹窗中再次弹窗
2159浏览 • 1回复 待解决
HarmonyOS 如何制作自定义加载弹窗
258浏览 • 1回复 待解决
HarmonyOS 自定义弹窗部分问题答疑
212浏览 • 1回复 待解决
自定义弹窗使用相关问题
845浏览 • 1回复 待解决
自定义弹窗如何嵌套使用
1468浏览 • 1回复 待解决